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 print "STARTING SAMBA...\n";
121 # we want out from samba to go to the log file, but also
122 # to the users terminal when running 'make test' on the command
123 # line. This puts it on stderr on the terminal
124 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
125 open STDERR, '>&STDOUT';
127 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
129 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
130 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
131 if (defined($ENV{MITKRB5})) {
132 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
134 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
135 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
137 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
138 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
139 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
140 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
141 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
142 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
144 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
145 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
147 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
149 $ENV{RESOLV_CONF} = $env_vars->{RESOLV_CONF};
151 $ENV{UID_WRAPPER} = "1";
152 $ENV{UID_WRAPPER_ROOT} = "1";
154 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
157 if (defined($ENV{SAMBA_OPTIONS})) {
158 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
160 if(defined($ENV{SAMBA_VALGRIND})) {
161 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
164 if (defined($process_model)) {
165 push @optargs, ("-M", $process_model);
167 close($env_vars->{STDIN_PIPE});
168 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
170 exec(@preargs, Samba::bindir_path($self, "samba"), "-i", "--no-process-group", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
172 $env_vars->{SAMBA_PID} = $pid;
173 print "DONE ($pid)\n";
175 close($STDIN_READER);
177 if ($self->wait_for_start($env_vars) != 0) {
178 warn("Samba $pid failed to start up");
185 sub wait_for_start($$)
187 my ($self, $testenv_vars) = @_;
191 if (not $self->check_env($testenv_vars)) {
192 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
196 # This will return quickly when things are up, but be slow if we
197 # need to wait for (eg) SSL init
198 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
201 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
207 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
208 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
209 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
210 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
211 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
212 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
213 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
214 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
215 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
218 } while ($ret != 0 && $count < 20);
220 teardown_env($self, $testenv_vars);
221 warn("nbt not reachable after 20 retries\n");
225 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
226 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
227 print "waiting for working LDAP and a RID Set to be allocated\n";
228 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
230 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
232 my $search_dn = $base_dn;
233 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
234 # TODO currently no check for actual rIDAllocationPool
235 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
239 # Add hosts file for name lookups
240 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
241 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
242 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
244 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
246 $cmd .= "RESOLV_CONF='$testenv_vars->{RESOLV_CONF}' ";
248 $cmd .= "$ldbsearch ";
249 $cmd .= "$testenv_vars->{CONFIGURATION} ";
250 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
251 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
253 $cmd .= "-b '$search_dn' ";
254 while (system("$cmd >/dev/null") != 0) {
256 if ($count > $max_wait) {
257 teardown_env($self, $testenv_vars);
258 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}");
261 print "Waiting for working LDAP...\n";
266 my $wbinfo = Samba::bindir_path($self, "wbinfo");
270 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
271 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
272 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
273 $cmd .= "$wbinfo -P";
280 } while ($ret != 0 && $count < 20);
282 teardown_env($self, $testenv_vars);
283 warn("winbind not reachable after 20 retries\n");
287 # Ensure we registered all our names
288 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
290 print "Waiting for dns_update_cache to be created.\n";
292 while (not -e "$testenv_vars->{PRIVATEDIR}/dns_update_cache") {
294 if ($count > $max_wait) {
295 teardown_env($self, $testenv_vars);
296 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
299 print "Waiting for dns_update_cache to be created...\n";
302 print "Waiting for dns_update_cache to be filled.\n";
304 while ((-s "$testenv_vars->{PRIVATEDIR}/dns_update_cache") == 0) {
306 if ($count > $max_wait) {
307 teardown_env($self, $testenv_vars);
308 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
311 print "Waiting for dns_update_cache to be filled...\n";
316 print $self->getlog_env($testenv_vars);
318 print "READY ($testenv_vars->{SAMBA_PID})\n";
323 sub write_ldb_file($$$)
325 my ($self, $file, $ldif) = @_;
327 my $ldbadd = Samba::bindir_path($self, "ldbadd");
328 open(LDIF, "|$ldbadd -H $file >/dev/null");
333 sub add_wins_config($$)
335 my ($self, $privatedir) = @_;
337 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
338 dn: name=TORTURE_11,CN=PARTNERS
339 objectClass: wreplPartner
350 my ($self, $ctx) = @_;
352 #Make the subdirectory be as fedora DS would expect
353 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
355 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
357 return ($fedora_ds_dir, $pidfile);
362 my ($self, $ctx) = @_;
364 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
365 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
367 return ($slapd_conf_d, $pidfile);
370 sub setup_dns_hub_internal($$$)
372 my ($self, $hostname, $prefix) = @_;
375 unless(-d $prefix or make_path($prefix, 0777)) {
376 warn("Unable to create $prefix");
379 my $prefix_abs = abs_path($prefix);
381 die ("prefix=''") if $prefix_abs eq "";
382 die ("prefix='/'") if $prefix_abs eq "/";
384 unless (system("rm -rf $prefix_abs/*") == 0) {
385 warn("Unable to clean up");
388 my $swiface = Samba::get_interface($hostname);
391 $env->{prefix} = $prefix;
392 $env->{prefix_abs} = $prefix_abs;
394 $env->{hostname} = $hostname;
395 $env->{swiface} = $swiface;
397 $env->{ipv4} = "127.0.0.$swiface";
398 $env->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
400 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
402 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
404 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
405 print RESOLV_CONF "nameserver $env->{ipv4}\n";
406 print RESOLV_CONF "nameserver $env->{ipv6}\n";
409 # use a pipe for stdin in the child processes. This allows
410 # those processes to monitor the pipe for EOF to ensure they
411 # exit when the test script exits
412 pipe($STDIN_READER, $env->{STDIN_PIPE});
414 print "STARTING rootdnsforwarder...\n";
417 # we want out from samba to go to the log file, but also
418 # to the users terminal when running 'make test' on the command
419 # line. This puts it on stderr on the terminal
420 open STDOUT, "| tee $env->{DNS_HUB_LOG} 1>&2";
421 open STDERR, '>&STDOUT';
423 SocketWrapper::set_default_iface($swiface);
424 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap";
425 SocketWrapper::setup_pcap($pcap_file);
430 if (!defined($ENV{PYTHON})) {
431 push (@preargs, "env");
432 push (@preargs, "python");
434 push (@preargs, $ENV{PYTHON});
436 $ENV{MAKE_TEST_BINARY} = "$self->{srcdir}/selftest/target/dns_hub.py";
437 push (@args, "$self->{server_maxtime}");
438 push (@args, "$env->{ipv4}");
439 close($env->{STDIN_PIPE});
440 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
442 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
443 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
445 $env->{SAMBA_PID} = $pid;
446 $env->{KRB5_CONFIG} = "${prefix_abs}/no_krb5.conf";
447 close($STDIN_READER);
455 my ($self, $prefix) = @_;
457 my $hostname = "rootdnsforwarder";
459 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
461 $self->{dns_hub_env} = $env;
466 sub get_dns_hub_env($)
468 my ($self, $prefix) = @_;
470 if (defined($self->{dns_hub_env})) {
471 return $self->{dns_hub_env};
474 die("get_dns_hub_env() not setup 'dns_hub_env'");
478 # Returns the environmental variables that we pass to samba-tool commands
481 my ($self, $localenv) = @_;
483 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
484 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
485 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
486 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
488 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
490 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
491 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
492 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
497 sub setup_namespaces($$:$$)
499 my ($self, $localenv, $upn_array, $spn_array) = @_;
501 @{$upn_array} = [] unless defined($upn_array);
503 foreach my $upn (@{$upn_array}) {
504 $upn_args .= " --add-upn-suffix=$upn";
507 @{$spn_array} = [] unless defined($spn_array);
509 foreach my $spn (@{$spn_array}) {
510 $spn_args .= " --add-spn-suffix=$spn";
513 my $samba_tool = Samba::bindir_path($self, "samba-tool");
515 my $cmd_env = $self->get_cmd_env_vars($localenv);
517 my $cmd_config = " $localenv->{CONFIGURATION}";
519 my $namespaces = $cmd_env;
520 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
521 $namespaces .= $cmd_config;
522 unless (system($namespaces) == 0) {
523 warn("Failed to add namespaces \n$namespaces");
530 sub setup_trust($$$$$)
532 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
534 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
536 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
537 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
538 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
539 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
540 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
542 my $samba_tool = Samba::bindir_path($self, "samba-tool");
545 my $cmd_env = $self->get_cmd_env_vars($localenv);
547 my $cmd_config = " $localenv->{CONFIGURATION}";
548 my $cmd_creds = $cmd_config;
549 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
551 my $create = $cmd_env;
552 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
553 $create .= " $extra_args";
554 $create .= $cmd_creds;
555 unless (system($create) == 0) {
556 warn("Failed to create trust \n$create");
560 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
561 my $groupadd = $cmd_env;
562 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
563 unless (system($groupadd) == 0) {
564 warn("Failed to create group \n$groupadd");
567 my $groupmem = $cmd_env;
568 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
569 unless (system($groupmem) == 0) {
570 warn("Failed to add group member \n$groupmem");
577 sub provision_raw_prepare($$$$$$$$$$$$)
579 my ($self, $prefix, $server_role, $hostname,
580 $domain, $realm, $samsid, $functional_level,
581 $password, $kdc_ipv4, $kdc_ipv6) = @_;
584 if (defined $ENV{PYTHON}) {
585 $python_cmd = $ENV{PYTHON} . " ";
587 $ctx->{python} = $python_cmd;
588 my $netbiosname = uc($hostname);
590 unless(-d $prefix or mkdir($prefix, 0777)) {
591 warn("Unable to create $prefix");
594 my $prefix_abs = abs_path($prefix);
596 die ("prefix=''") if $prefix_abs eq "";
597 die ("prefix='/'") if $prefix_abs eq "/";
599 unless (system("rm -rf $prefix_abs/*") == 0) {
600 warn("Unable to clean up");
604 my $swiface = Samba::get_interface($hostname);
606 $ctx->{prefix} = $prefix;
607 $ctx->{prefix_abs} = $prefix_abs;
609 $ctx->{server_role} = $server_role;
610 $ctx->{hostname} = $hostname;
611 $ctx->{netbiosname} = $netbiosname;
612 $ctx->{swiface} = $swiface;
613 $ctx->{password} = $password;
614 $ctx->{kdc_ipv4} = $kdc_ipv4;
615 $ctx->{kdc_ipv6} = $kdc_ipv6;
616 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
617 if ($functional_level eq "2000") {
618 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
622 # Set smbd log level here.
624 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
625 $ctx->{username} = "Administrator";
626 $ctx->{domain} = $domain;
627 $ctx->{realm} = uc($realm);
628 $ctx->{dnsname} = lc($realm);
629 $ctx->{samsid} = $samsid;
631 $ctx->{functional_level} = $functional_level;
633 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
635 $ctx->{unix_name} = $unix_name;
636 $ctx->{unix_uid} = $>;
637 my @mygid = split(" ", $();
638 $ctx->{unix_gid} = $mygid[0];
639 $ctx->{unix_gids_str} = $);
640 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
642 $ctx->{etcdir} = "$prefix_abs/etc";
643 $ctx->{piddir} = "$prefix_abs/pid";
644 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
645 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
646 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
647 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
648 $ctx->{privatedir} = "$prefix_abs/private";
649 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
650 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
651 $ctx->{lockdir} = "$prefix_abs/lockdir";
652 $ctx->{logdir} = "$prefix_abs/logs";
653 $ctx->{statedir} = "$prefix_abs/statedir";
654 $ctx->{cachedir} = "$prefix_abs/cachedir";
655 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
656 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
657 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
658 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
659 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
660 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
661 if ($ENV{SAMBA_DNS_FAKING}) {
662 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
663 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
664 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
666 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
667 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
668 $ctx->{use_resolv_wrapper} = 1;
671 my $dns_hub = $self->get_dns_hub_env();
672 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
674 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
676 $ctx->{ipv4} = "127.0.0.$swiface";
677 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
678 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
680 push(@{$ctx->{directories}}, $ctx->{privatedir});
681 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
682 push(@{$ctx->{directories}}, $ctx->{etcdir});
683 push(@{$ctx->{directories}}, $ctx->{piddir});
684 push(@{$ctx->{directories}}, $ctx->{lockdir});
685 push(@{$ctx->{directories}}, $ctx->{logdir});
686 push(@{$ctx->{directories}}, $ctx->{statedir});
687 push(@{$ctx->{directories}}, $ctx->{cachedir});
689 $ctx->{smb_conf_extra_options} = "";
691 my @provision_options = ();
692 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
693 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
694 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
695 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
696 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
697 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
698 if (defined($ctx->{use_resolv_wrapper})) {
699 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
700 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
702 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
704 if (defined($ENV{GDB_PROVISION})) {
705 push (@provision_options, "gdb --args");
706 if (!defined($ENV{PYTHON})) {
707 push (@provision_options, "env");
708 push (@provision_options, "python");
711 if (defined($ENV{VALGRIND_PROVISION})) {
712 push (@provision_options, "valgrind");
713 if (!defined($ENV{PYTHON})) {
714 push (@provision_options, "env");
715 push (@provision_options, "python");
719 my $samba_tool = Samba::bindir_path($self, "samba-tool");
721 push (@provision_options, $samba_tool);
722 push (@provision_options, "domain");
723 push (@provision_options, "provision");
724 push (@provision_options, "--configfile=$ctx->{smb_conf}");
725 push (@provision_options, "--host-name=$ctx->{hostname}");
726 push (@provision_options, "--host-ip=$ctx->{ipv4}");
727 push (@provision_options, "--quiet");
728 push (@provision_options, "--domain=$ctx->{domain}");
729 push (@provision_options, "--realm=$ctx->{realm}");
730 if (defined($ctx->{samsid})) {
731 push (@provision_options, "--domain-sid=$ctx->{samsid}");
733 push (@provision_options, "--adminpass=$ctx->{password}");
734 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
735 push (@provision_options, "--machinepass=machine$ctx->{password}");
736 push (@provision_options, "--root=$ctx->{unix_name}");
737 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
738 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
740 @{$ctx->{provision_options}} = @provision_options;
747 my ($self, $keyword, @options_list) = @_;
749 # convert the options-list to a hash-map for easy keyword lookup
750 my %options_dict = map { $_ => 1 } @options_list;
752 return exists $options_dict{$keyword};
756 # Step1 creates the basic configuration
758 sub provision_raw_step1($$)
760 my ($self, $ctx) = @_;
762 mkdir($_, 0777) foreach (@{$ctx->{directories}});
765 ## lockdir and piddir must be 0755
767 chmod 0755, $ctx->{lockdir};
768 chmod 0755, $ctx->{piddir};
770 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
771 warn("can't open $ctx->{smb_conf}$?");
775 Samba::prepare_keyblobs($ctx);
776 my $crlfile = "$ctx->{tlsdir}/crl.pem";
777 $crlfile = "" unless -e ${crlfile};
779 # work out which file server to use. Default to source3 smbd (s3fs),
780 # unless the source4 NTVFS (smb) file server has been specified
781 my $services = "-smb +s3fs";
782 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
783 $services = "+smb -s3fs";
788 netbios name = $ctx->{netbiosname}
789 posix:eadb = $ctx->{statedir}/eadb.tdb
790 workgroup = $ctx->{domain}
791 realm = $ctx->{realm}
792 private dir = $ctx->{privatedir}
793 binddns dir = $ctx->{binddnsdir}
794 pid directory = $ctx->{piddir}
795 ncalrpc dir = $ctx->{ncalrpcdir}
796 lock dir = $ctx->{lockdir}
797 state directory = $ctx->{statedir}
798 cache directory = $ctx->{cachedir}
799 winbindd socket directory = $ctx->{winbindd_socket_dir}
800 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
801 winbind separator = /
802 interfaces = $ctx->{interfaces}
803 tls dh params file = $ctx->{tlsdir}/dhparms.pem
804 tls crlfile = ${crlfile}
805 tls verify peer = no_check
806 panic action = $RealBin/gdb_backtrace \%d
808 server role = $ctx->{server_role}
809 server services = +echo $services
810 dcerpc endpoint servers = +winreg +srvsvc
811 notify:inotify = false
813 ldap server require strong auth = yes
814 #We don't want to pass our self-tests if the PAC code is wrong
815 gensec:require_pac = true
816 log file = $ctx->{logdir}/log.\%m
817 log level = $ctx->{server_loglevel}
821 dns update command = $ctx->{samba_dnsupdate}
822 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
823 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
824 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
825 dreplsrv:periodic_startup_interval = 0
826 dsdb:schema update allowed = yes
828 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
830 idmap_ldb:use rfc2307=yes
831 winbind enum users = yes
832 winbind enum groups = yes
834 rpc server port:netlogon = 1026
840 # Begin extra options
841 $ctx->{smb_conf_extra_options}
846 #Default the KDC IP to the server's IP
847 if (not defined($ctx->{kdc_ipv4})) {
848 $ctx->{kdc_ipv4} = $ctx->{ipv4};
850 if (not defined($ctx->{kdc_ipv6})) {
851 $ctx->{kdc_ipv6} = $ctx->{ipv6};
854 Samba::mk_krb5_conf($ctx);
855 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
857 open(PWD, ">$ctx->{nsswrap_passwd}");
858 if ($ctx->{unix_uid} != 0) {
859 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
861 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
862 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
863 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
864 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
865 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
866 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
869 my $uid_rfc2307test = 65533;
871 open(GRP, ">$ctx->{nsswrap_group}");
872 if ($ctx->{unix_gid} != 0) {
873 print GRP "root:x:0:\n";
875 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
876 print GRP "wheel:x:10:
879 nogroup:x:65534:nobody
882 my $gid_rfc2307test = 65532;
884 my $hostname = lc($ctx->{hostname});
885 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
886 if ($hostname eq "localdc") {
887 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
888 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
890 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
891 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
895 my $configuration = "--configfile=$ctx->{smb_conf}";
897 #Ensure the config file is valid before we start
898 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
899 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
900 system("$testparm -v --suppress-prompt $configuration >&2");
901 warn("Failed to create a valid smb.conf configuration $testparm!");
904 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) {
905 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
909 # Return the environment variables for the new testenv DC.
910 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
911 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
913 KRB5_CONFIG => $ctx->{krb5_conf},
914 KRB5_CCACHE => $ctx->{krb5_ccache},
915 MITKDC_CONFIG => $ctx->{mitkdc_conf},
916 PIDDIR => $ctx->{piddir},
917 SERVER => $ctx->{hostname},
918 DC_SERVER => $ctx->{hostname},
919 SERVER_IP => $ctx->{ipv4},
920 DC_SERVER_IP => $ctx->{ipv4},
921 SERVER_IPV6 => $ctx->{ipv6},
922 DC_SERVER_IPV6 => $ctx->{ipv6},
923 NETBIOSNAME => $ctx->{netbiosname},
924 DC_NETBIOSNAME => $ctx->{netbiosname},
925 DOMAIN => $ctx->{domain},
926 USERNAME => $ctx->{username},
927 DC_USERNAME => $ctx->{username},
928 REALM => $ctx->{realm},
929 DNSNAME => $ctx->{dnsname},
930 SAMSID => $ctx->{samsid},
931 PASSWORD => $ctx->{password},
932 DC_PASSWORD => $ctx->{password},
933 LDAPDIR => $ctx->{ldapdir},
934 LDAP_INSTANCE => $ctx->{ldap_instance},
935 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
936 NCALRPCDIR => $ctx->{ncalrpcdir},
937 LOCKDIR => $ctx->{lockdir},
938 STATEDIR => $ctx->{statedir},
939 CACHEDIR => $ctx->{cachedir},
940 PRIVATEDIR => $ctx->{privatedir},
941 BINDDNSDIR => $ctx->{binddnsdir},
942 SERVERCONFFILE => $ctx->{smb_conf},
943 CONFIGURATION => $configuration,
944 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
945 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
946 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
947 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
948 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
949 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
950 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
951 SAMBA_TEST_LOG_POS => 0,
952 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
953 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
954 LOCAL_PATH => $ctx->{share},
955 UID_RFC2307TEST => $uid_rfc2307test,
956 GID_RFC2307TEST => $gid_rfc2307test,
957 SERVER_ROLE => $ctx->{server_role},
958 RESOLV_CONF => $ctx->{resolv_conf}
961 if (defined($ctx->{use_resolv_wrapper})) {
962 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
964 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
967 if ($ctx->{server_role} eq "domain controller") {
968 $ret->{DOMSID} = $ret->{SAMSID};
975 # Step2 runs the provision script
977 sub provision_raw_step2($$$)
979 my ($self, $ctx, $ret) = @_;
981 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
982 unless (system($provision_cmd) == 0) {
983 warn("Unable to provision: \n$provision_cmd\n");
987 my $testallowed_account = "testallowed";
988 my $samba_tool_cmd = "";
989 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
990 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
991 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
992 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
993 unless (system($samba_tool_cmd) == 0) {
994 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
999 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1000 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1001 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1002 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1004 if ($ctx->{server_role} ne "domain controller") {
1005 $base_dn = "DC=$ctx->{netbiosname}";
1008 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
1009 $testallowed_account = "testallowed account";
1010 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1011 print LDIF "dn: $user_dn
1013 replace: samAccountName
1014 samAccountName: $testallowed_account
1019 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1020 print LDIF "dn: $user_dn
1022 replace: userPrincipalName
1023 userPrincipalName: testallowed upn\@$ctx->{realm}
1024 replace: servicePrincipalName
1025 servicePrincipalName: host/testallowed
1030 $samba_tool_cmd = "";
1031 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1032 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1033 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1034 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1035 unless (system($samba_tool_cmd) == 0) {
1036 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1040 my $user_dn = "cn=testdenied,cn=users,$base_dn";
1041 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1042 print LDIF "dn: $user_dn
1044 replace: userPrincipalName
1045 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1050 $samba_tool_cmd = "";
1051 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1052 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1053 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1054 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1055 unless (system($samba_tool_cmd) == 0) {
1056 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1060 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
1061 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1062 print LDIF "dn: $user_dn
1064 replace: userPrincipalName
1065 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1066 replace: servicePrincipalName
1067 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1072 $samba_tool_cmd = "";
1073 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1074 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1075 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1076 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1077 unless (system($samba_tool_cmd) == 0) {
1078 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1082 # Create to users alice and bob!
1083 my $user_account_array = ["alice", "bob", "jane"];
1085 foreach my $user_account (@{$user_account_array}) {
1086 my $samba_tool_cmd = "";
1088 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1089 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1090 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1091 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1092 unless (system($samba_tool_cmd) == 0) {
1093 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1099 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1100 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1101 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1103 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1104 my $user_dn = "cn=jane,cn=users,$base_dn";
1106 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1107 print LDIF "dn: $user_dn
1109 replace: userPrincipalName
1110 userPrincipalName: jane.doe\@$ctx->{realm}
1118 sub provision($$$$$$$$$$)
1120 my ($self, $prefix, $server_role, $hostname,
1121 $domain, $realm, $functional_level,
1122 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1123 $extra_provision_options) = @_;
1125 my $samsid = Samba::random_domain_sid();
1127 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1132 $password, $kdc_ipv4, $kdc_ipv6);
1134 if (defined($extra_provision_options)) {
1135 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1138 $ctx->{share} = "$ctx->{prefix_abs}/share";
1139 push(@{$ctx->{directories}}, "$ctx->{share}");
1140 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1141 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1143 # precreate directories for printer drivers
1144 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1145 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1146 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1149 $msdfs = "yes" if ($server_role eq "domain controller");
1150 $ctx->{smb_conf_extra_options} = "
1153 server max protocol = SMB2
1157 # fruit:copyfile is a global option
1158 fruit:copyfile = yes
1160 $extra_smbconf_options
1163 path = $ctx->{share}
1165 posix:sharedelay = 100000
1166 posix:oplocktimeout = 3
1167 posix:writetimeupdatedelay = 500000
1170 path = $ctx->{share}
1172 posix:sharedelay = 100000
1173 posix:oplocktimeout = 3
1174 posix:writetimeupdatedelay = 500000
1176 force create mode = 777
1179 path = $ctx->{share}
1182 force create mode = 0
1183 directory mask = 0777
1184 force directory mode = 0
1187 path = $ctx->{share}/test1
1189 posix:sharedelay = 100000
1190 posix:oplocktimeout = 3
1191 posix:writetimeupdatedelay = 500000
1194 path = $ctx->{share}/test2
1196 posix:sharedelay = 100000
1197 posix:oplocktimeout = 3
1198 posix:writetimeupdatedelay = 500000
1201 path = $ctx->{share}/_ignore_cifs_
1203 ntvfs handler = cifs
1204 cifs:server = $ctx->{netbiosname}
1206 cifs:use-s4u2proxy = yes
1207 # There is no username specified here, instead the client is expected
1208 # to log in with kerberos, and the serverwill use delegated credentials.
1209 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1212 path = $ctx->{share}
1214 ntvfs handler = simple
1217 path = $ctx->{statedir}/sysvol
1221 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1226 ntvfs handler = cifsposix
1229 path = $ctx->{share}
1230 vfs objects = catia fruit streams_xattr acl_xattr
1232 fruit:resource = file
1233 fruit:metadata = netatalk
1234 fruit:locking = netatalk
1235 fruit:encoding = native
1237 $extra_smbconf_shares
1240 if (defined($self->{ldap})) {
1241 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1242 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1244 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1245 $ldap_uri =~ s|/|%2F|g;
1246 $ldap_uri = "ldapi://$ldap_uri";
1247 $ctx->{ldap_uri} = $ldap_uri;
1249 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1252 my $ret = $self->provision_raw_step1($ctx);
1253 unless (defined $ret) {
1257 if (defined($self->{ldap})) {
1258 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1259 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1260 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1261 if ($self->{ldap} eq "openldap") {
1262 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1263 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1265 } elsif ($self->{ldap} eq "fedora-ds") {
1266 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1267 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1268 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1273 return $self->provision_raw_step2($ctx, $ret);
1276 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1277 # original DC) in the testenv. $SERVER is always the joined DC that we are
1278 # actually running the test against
1279 sub set_pdc_env_vars
1281 my ($self, $env, $dcvars) = @_;
1283 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1284 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1285 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1286 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1287 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1288 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1289 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1292 sub provision_s4member($$$$$)
1294 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1295 print "PROVISIONING MEMBER...\n";
1296 my $extra_smb_conf = "
1297 passdb backend = samba_dsdb
1298 winbindd:use external pipes = true
1300 # the source4 smb server doesn't allow signing by default
1301 server signing = enabled
1302 raw NTLMv2 auth = yes
1304 rpc_server:default = external
1305 rpc_server:svcctl = embedded
1306 rpc_server:srvsvc = embedded
1307 rpc_server:eventlog = embedded
1308 rpc_server:ntsvcs = embedded
1309 rpc_server:winreg = embedded
1310 rpc_server:spoolss = embedded
1311 rpc_daemon:spoolssd = embedded
1312 rpc_server:tcpip = no
1315 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1317 my $extra_provision_options = ["--use-ntvfs"];
1318 my $ret = $self->provision($prefix,
1325 $dcvars->{SERVER_IP},
1326 $dcvars->{SERVER_IPV6},
1327 $extra_smb_conf, "",
1328 $extra_provision_options);
1333 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1334 my $cmd = $self->get_cmd_env_vars($ret);
1335 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1336 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1337 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1339 unless (system($cmd) == 0) {
1340 warn("Join failed\n$cmd");
1344 $ret->{DOMSID} = $dcvars->{DOMSID};
1345 $self->set_pdc_env_vars($ret, $dcvars);
1350 sub provision_rpc_proxy($$$)
1352 my ($self, $prefix, $dcvars) = @_;
1353 print "PROVISIONING RPC PROXY...\n";
1355 my $extra_smbconf_options = "
1356 passdb backend = samba_dsdb
1359 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1360 dcerpc endpoint servers = epmapper, remote
1361 dcerpc_remote:interfaces = rpcecho
1362 dcerpc_remote:allow_anonymous_fallback = yes
1365 path = /tmp/_ignore_cifs_to_dc_/_none_
1367 ntvfs handler = cifs
1368 cifs:server = $dcvars->{SERVER}
1370 cifs:use-s4u2proxy = yes
1371 # There is no username specified here, instead the client is expected
1372 # to log in with kerberos, and the serverwill use delegated credentials.
1373 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1377 my $extra_provision_options = ["--use-ntvfs"];
1378 my $ret = $self->provision($prefix,
1385 $dcvars->{SERVER_IP},
1386 $dcvars->{SERVER_IPV6},
1387 $extra_smbconf_options, "",
1388 $extra_provision_options);
1393 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1395 # The joind runs in the context of the rpc_proxy/member for now
1396 my $cmd = $self->get_cmd_env_vars($ret);
1397 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1398 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1399 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1401 unless (system($cmd) == 0) {
1402 warn("Join failed\n$cmd");
1406 # Setting up delegation runs in the context of the DC for now
1408 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1409 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1410 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1411 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1412 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1413 $cmd .= " $dcvars->{CONFIGURATION}";
1416 unless (system($cmd) == 0) {
1417 warn("Delegation failed\n$cmd");
1421 # Setting up delegation runs in the context of the DC for now
1423 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1424 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1425 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1426 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1427 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1428 $cmd .= " $dcvars->{CONFIGURATION}";
1430 unless (system($cmd) == 0) {
1431 warn("Delegation failed\n$cmd");
1435 $ret->{DOMSID} = $dcvars->{DOMSID};
1436 $self->set_pdc_env_vars($ret, $dcvars);
1441 sub provision_promoted_dc($$$)
1443 my ($self, $prefix, $dcvars) = @_;
1444 print "PROVISIONING PROMOTED DC...\n";
1446 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1447 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1453 $dcvars->{PASSWORD},
1454 $dcvars->{SERVER_IP},
1455 $dcvars->{SERVER_IPV6});
1457 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1459 $ctx->{smb_conf_extra_options} = "
1461 server max protocol = SMB2
1463 ntlm auth = ntlmv2-only
1466 path = $ctx->{statedir}/sysvol
1470 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1475 my $ret = $self->provision_raw_step1($ctx);
1480 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1481 my $cmd = $self->get_cmd_env_vars($ret);
1482 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1483 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1484 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1486 unless (system($cmd) == 0) {
1487 warn("Join failed\n$cmd");
1491 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1492 my $cmd = $self->get_cmd_env_vars($ret);
1493 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1494 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1495 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1497 unless (system($cmd) == 0) {
1498 warn("Join failed\n$cmd");
1502 $self->set_pdc_env_vars($ret, $dcvars);
1507 sub provision_vampire_dc($$$)
1509 my ($self, $prefix, $dcvars, $fl) = @_;
1510 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1511 my $name = "localvampiredc";
1512 my $extra_conf = "";
1514 if ($fl == "2000") {
1515 $name = "vampire2000dc";
1517 $extra_conf = "drs: immediate link sync = yes
1518 drs: max link sync = 250";
1521 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1522 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1528 $dcvars->{PASSWORD},
1529 $dcvars->{SERVER_IP},
1530 $dcvars->{SERVER_IPV6});
1532 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1534 $ctx->{smb_conf_extra_options} = "
1536 server max protocol = SMB2
1538 ntlm auth = mschapv2-and-ntlmv2-only
1542 path = $ctx->{statedir}/sysvol
1546 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1551 my $ret = $self->provision_raw_step1($ctx);
1556 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1557 my $cmd = $self->get_cmd_env_vars($ret);
1558 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1559 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1560 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1561 $cmd .= " --backend-store=mdb";
1563 unless (system($cmd) == 0) {
1564 warn("Join failed\n$cmd");
1568 $self->set_pdc_env_vars($ret, $dcvars);
1569 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1574 sub provision_subdom_dc($$$)
1576 my ($self, $prefix, $dcvars) = @_;
1577 print "PROVISIONING SUBDOMAIN DC...\n";
1579 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1580 my $samsid = undef; # TODO pass the domain sid all the way down
1581 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1584 "sub.samba.example.com",
1587 $dcvars->{PASSWORD},
1590 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1592 $ctx->{smb_conf_extra_options} = "
1594 server max protocol = SMB2
1597 path = $ctx->{statedir}/sysvol
1601 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1606 my $ret = $self->provision_raw_step1($ctx);
1611 Samba::mk_krb5_conf($ctx);
1612 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1614 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1615 my $cmd = $self->get_cmd_env_vars($ret);
1616 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1617 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1618 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1619 $cmd .= " --adminpass=$ret->{PASSWORD}";
1621 unless (system($cmd) == 0) {
1622 warn("Join failed\n$cmd");
1626 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1628 $self->set_pdc_env_vars($ret, $dcvars);
1633 sub provision_ad_dc_ntvfs($$)
1635 my ($self, $prefix) = @_;
1637 # We keep the old 'winbind' name here in server services to
1638 # ensure upgrades which used that name still work with the now
1641 print "PROVISIONING AD DC (NTVFS)...\n";
1642 my $extra_conf_options = "netbios aliases = localDC1-a
1643 server services = +winbind -winbindd
1644 ldap server require strong auth = allow_sasl_over_tls
1645 allow nt4 crypto = yes
1646 raw NTLMv2 auth = yes
1647 lsa over netlogon = yes
1648 rpc server port = 1027
1649 auth event notification = true
1650 dsdb event notification = true
1651 dsdb password event notification = true
1652 dsdb group change notification = true
1653 server schannel = auto
1655 my $extra_provision_options = ["--use-ntvfs"];
1656 my $ret = $self->provision($prefix,
1657 "domain controller",
1660 "samba.example.com",
1665 $extra_conf_options,
1667 $extra_provision_options);
1672 unless($self->add_wins_config("$prefix/private")) {
1673 warn("Unable to add wins configuration");
1676 $ret->{NETBIOSALIAS} = "localdc1-a";
1677 $ret->{DC_REALM} = $ret->{REALM};
1682 sub provision_fl2000dc($$)
1684 my ($self, $prefix) = @_;
1686 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1687 my $extra_conf_options = "
1688 spnego:simulate_w2k=yes
1689 ntlmssp_server:force_old_spnego=yes
1690 server max protocol = NT1
1692 my $extra_provision_options = ["--use-ntvfs"];
1693 # This environment uses plain text secrets
1694 # i.e. secret attributes are not encrypted on disk.
1695 # This allows testing of the --plaintext-secrets option for
1697 push (@{$extra_provision_options}, "--plaintext-secrets");
1698 my $ret = $self->provision($prefix,
1699 "domain controller",
1702 "samba2000.example.com",
1707 $extra_conf_options,
1709 $extra_provision_options);
1714 unless($self->add_wins_config("$prefix/private")) {
1715 warn("Unable to add wins configuration");
1718 $ret->{DC_REALM} = $ret->{REALM};
1723 sub provision_fl2003dc($$$)
1725 my ($self, $prefix, $dcvars) = @_;
1726 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1727 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1729 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1730 my $extra_conf_options = "allow dns updates = nonsecure and secure
1731 dcesrv:header signing = no
1732 dcesrv:max auth states = 0
1733 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2
1734 server max protocol = SMB2_02
1736 my $extra_provision_options = ["--use-ntvfs"];
1737 my $ret = $self->provision($prefix,
1738 "domain controller",
1741 "samba2003.example.com",
1746 $extra_conf_options,
1748 $extra_provision_options);
1749 unless (defined $ret) {
1753 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1754 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1756 my @samba_tool_options;
1757 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1758 push (@samba_tool_options, "domain");
1759 push (@samba_tool_options, "passwordsettings");
1760 push (@samba_tool_options, "set");
1761 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1762 push (@samba_tool_options, "--min-pwd-age=0");
1763 push (@samba_tool_options, "--history-length=1");
1765 my $samba_tool_cmd = join(" ", @samba_tool_options);
1767 unless (system($samba_tool_cmd) == 0) {
1768 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1772 unless($self->add_wins_config("$prefix/private")) {
1773 warn("Unable to add wins configuration");
1780 sub provision_fl2008r2dc($$$)
1782 my ($self, $prefix, $dcvars) = @_;
1784 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1785 my $extra_conf_options = "
1786 ldap server require strong auth = no
1787 server max protocol = SMB2_10
1789 my $extra_provision_options = ["--use-ntvfs"];
1790 my $ret = $self->provision($prefix,
1791 "domain controller",
1794 "samba2008R2.example.com",
1799 $extra_conf_options,
1801 $extra_provision_options);
1802 unless (defined $ret) {
1806 unless ($self->add_wins_config("$prefix/private")) {
1807 warn("Unable to add wins configuration");
1810 $ret->{DC_REALM} = $ret->{REALM};
1816 sub provision_rodc($$$)
1818 my ($self, $prefix, $dcvars) = @_;
1819 print "PROVISIONING RODC...\n";
1821 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1822 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1828 $dcvars->{PASSWORD},
1829 $dcvars->{SERVER_IP},
1830 $dcvars->{SERVER_IPV6});
1835 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1837 $ctx->{share} = "$ctx->{prefix_abs}/share";
1838 push(@{$ctx->{directories}}, "$ctx->{share}");
1840 $ctx->{smb_conf_extra_options} = "
1842 server max protocol = SMB2
1843 password server = $dcvars->{DC_SERVER}
1846 path = $ctx->{statedir}/sysvol
1850 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1854 path = $ctx->{share}
1856 posix:sharedelay = 10000
1857 posix:oplocktimeout = 3
1858 posix:writetimeupdatedelay = 50000
1862 my $ret = $self->provision_raw_step1($ctx);
1867 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1868 my $cmd = $self->get_cmd_env_vars($ret);
1869 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1870 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1871 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1873 unless (system($cmd) == 0) {
1874 warn("RODC join failed\n$cmd");
1878 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1879 # user password verified on the RODC
1880 my $testallowed_account = "testallowed account";
1881 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1882 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1883 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1884 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1885 $cmd .= " --server=$dcvars->{DC_SERVER}";
1887 unless (system($cmd) == 0) {
1888 warn("RODC join failed\n$cmd");
1892 # we overwrite the kdc after the RODC join
1893 # so that use the RODC as kdc and test
1895 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1896 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1897 Samba::mk_krb5_conf($ctx);
1898 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1900 $self->set_pdc_env_vars($ret, $dcvars);
1905 sub read_config_h($)
1909 open(LF, "<$name") or die("unable to read $name: $!");
1912 next if not (/^#define /);
1913 if (/^#define (.*?)[ \t]+(.*?)$/) {
1917 if (/^#define (.*?)[ \t]+$/) {
1926 sub provision_ad_dc($$$$$$)
1928 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1929 $extra_provision_options) = @_;
1931 my $prefix_abs = abs_path($prefix);
1933 my $bindir_abs = abs_path($self->{bindir});
1934 my $lockdir="$prefix_abs/lockdir";
1935 my $conffile="$prefix_abs/etc/smb.conf";
1937 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1938 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1942 if (defined($ENV{CONFIG_H})) {
1943 $config_h = read_config_h($ENV{CONFIG_H});
1946 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1947 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1949 my $extra_smbconf_options = "
1950 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1952 dbwrap_tdb_mutexes:* = yes
1955 ${password_hash_gpg_key_ids}
1958 kernel change notify = no
1963 printcap name = /dev/null
1968 smbd:sharedelay = 100000
1969 smbd:writetimeupdatedelay = 500000
1972 check parent directory delete on close = yes
1974 dcerpc endpoint servers = -winreg -srvsvc
1976 printcap name = /dev/null
1978 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1979 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1982 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1983 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1984 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1985 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1986 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1987 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1988 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1990 print notify backchannel = yes
1992 server schannel = auto
1993 auth event notification = true
1994 dsdb event notification = true
1995 dsdb password event notification = true
1996 dsdb group change notification = true
2000 my $extra_smbconf_shares = "
2004 smb encrypt = required
2008 case sensitive = yes
2016 hide unreadable = yes
2020 kernel share modes = no
2039 push (@{$extra_provision_options}, "--backend-store=mdb");
2040 print "PROVISIONING AD DC...\n";
2041 my $ret = $self->provision($prefix,
2042 "domain controller",
2050 $extra_smbconf_options,
2051 $extra_smbconf_shares,
2052 $extra_provision_options);
2053 unless (defined $ret) {
2057 unless($self->add_wins_config("$prefix/private")) {
2058 warn("Unable to add wins configuration");
2065 sub provision_chgdcpass($$)
2067 my ($self, $prefix) = @_;
2069 print "PROVISIONING CHGDCPASS...\n";
2070 # This environment disallows the use of this password
2071 # (and also removes the default AD complexity checks)
2072 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2073 my $extra_smb_conf = "
2074 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
2075 allow dcerpc auth level connect:lsarpc = yes
2076 dcesrv:max auth states = 8
2078 my $extra_provision_options = ["--use-ntvfs"];
2079 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2080 my $ret = $self->provision($prefix,
2081 "domain controller",
2084 "chgdcpassword.samba.example.com",
2091 $extra_provision_options);
2092 unless (defined $ret) {
2096 unless($self->add_wins_config("$prefix/private")) {
2097 warn("Unable to add wins configuration");
2101 # Remove secrets.tdb from this environment to test that we
2102 # still start up on systems without the new matching
2103 # secrets.tdb records.
2104 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2105 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2109 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2114 sub teardown_env_terminate($$)
2116 my ($self, $envvars) = @_;
2119 # This should cause samba to terminate gracefully
2120 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2122 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2123 my $ret = system($cmd);
2125 warn "'$cmd' failed with '$ret'\n";
2128 # This should cause samba to terminate gracefully
2129 close($envvars->{STDIN_PIPE});
2131 $pid = $envvars->{SAMBA_PID};
2135 # This should give it time to write out the gcov data
2136 until ($count > 15) {
2137 if (Samba::cleanup_child($pid, "samba") != 0) {
2144 # After 15 Seconds, work out why this thing is still alive
2145 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2146 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2148 until ($count > 30) {
2149 if (Samba::cleanup_child($pid, "samba") != 0) {
2156 if (kill(0, $pid)) {
2157 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2161 until ($count > 40) {
2162 if (Samba::cleanup_child($pid, "samba") != 0) {
2168 # If it is still around, kill it
2169 if (kill(0, $pid)) {
2170 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2176 sub teardown_env($$)
2178 my ($self, $envvars) = @_;
2179 teardown_env_terminate($self, $envvars);
2181 $self->slapd_stop($envvars) if ($self->{ldap});
2183 print $self->getlog_env($envvars);
2190 my ($self, $envvars) = @_;
2191 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2194 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2196 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2200 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2203 return "" if $out eq $title;
2210 my ($self, $envvars) = @_;
2211 my $samba_pid = $envvars->{SAMBA_PID};
2213 if (not defined($samba_pid)) {
2215 } elsif ($samba_pid > 0) {
2216 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2218 if ($childpid == 0) {
2227 # Declare the environments Samba4 makes available.
2228 # To be set up, they will be called as
2229 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2230 # The interdependencies between the testenvs are declared below. Some testenvs
2231 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2232 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2233 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2234 %Samba4::ENV_DEPS = (
2235 # name => [dep_1, dep_2, ...],
2237 ad_dc_ntvfs => ["dns_hub"],
2238 ad_dc => ["dns_hub"],
2239 ad_dc_no_nss => ["dns_hub"],
2240 ad_dc_no_ntlm => ["dns_hub"],
2242 fl2008r2dc => ["ad_dc"],
2243 fl2003dc => ["ad_dc"],
2244 fl2000dc => ["dns_hub"],
2246 vampire_2000_dc => ["fl2000dc"],
2247 vampire_dc => ["ad_dc_ntvfs"],
2248 promoted_dc => ["ad_dc_ntvfs"],
2249 subdom_dc => ["ad_dc_ntvfs"],
2251 rodc => ["ad_dc_ntvfs"],
2252 rpc_proxy => ["ad_dc_ntvfs"],
2253 chgdcpass => ["dns_hub"],
2255 s4member_dflt_domain => ["ad_dc_ntvfs"],
2256 s4member => ["ad_dc_ntvfs"],
2258 # envs that test the server process model
2259 proclimitdc => ["dns_hub"],
2260 preforkrestartdc => ["dns_hub"],
2262 # backup/restore testenvs
2263 backupfromdc => ["dns_hub"],
2264 customdc => ["dns_hub"],
2265 restoredc => ["backupfromdc"],
2266 renamedc => ["backupfromdc"],
2267 offlinebackupdc => ["backupfromdc"],
2268 labdc => ["backupfromdc"],
2275 my ($self, $path, $dc_vars) = @_;
2277 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2280 if (not defined($self->check_or_start($env, "standard"))) {
2288 sub setup_s4member_dflt_domain
2290 my ($self, $path, $dc_vars) = @_;
2292 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2293 "winbind use default domain = yes");
2296 if (not defined($self->check_or_start($env, "standard"))) {
2306 my ($self, $path, $dc_vars) = @_;
2308 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2311 if (not defined($self->check_or_start($env, "standard"))) {
2318 sub setup_ad_dc_ntvfs
2320 my ($self, $path) = @_;
2322 my $env = $self->provision_ad_dc_ntvfs($path);
2324 if (not defined($self->check_or_start($env, "standard"))) {
2325 warn("Failed to start ad_dc_ntvfs");
2334 my ($self, $path) = @_;
2336 my $env = $self->provision_chgdcpass($path);
2338 if (not defined($self->check_or_start($env, "standard"))) {
2347 my ($self, $path) = @_;
2349 my $env = $self->provision_fl2000dc($path);
2351 if (not defined($self->check_or_start($env, "standard"))) {
2361 my ($self, $path, $dc_vars) = @_;
2363 my $env = $self->provision_fl2003dc($path);
2366 if (not defined($self->check_or_start($env, "standard"))) {
2370 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2375 sub setup_fl2008r2dc
2377 my ($self, $path, $dc_vars) = @_;
2379 my $env = $self->provision_fl2008r2dc($path);
2382 if (not defined($self->check_or_start($env, "standard"))) {
2386 my $upn_array = ["$env->{REALM}.upn"];
2387 my $spn_array = ["$env->{REALM}.spn"];
2389 $self->setup_namespaces($env, $upn_array, $spn_array);
2391 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2397 sub setup_vampire_dc
2399 return setup_generic_vampire_dc(@_, "2008");
2402 sub setup_vampire_2000_dc
2404 return setup_generic_vampire_dc(@_, "2000");
2407 sub setup_generic_vampire_dc
2409 my ($self, $path, $dc_vars, $fl) = @_;
2411 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2414 if (not defined($self->check_or_start($env, "single"))) {
2418 # force replicated DC to update repsTo/repsFrom
2419 # for vampired partitions
2420 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2422 # as 'vampired' dc may add data in its local replica
2423 # we need to synchronize data between DCs
2424 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2425 my $cmd = $self->get_cmd_env_vars($env);
2426 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2427 $cmd .= " $dc_vars->{CONFIGURATION}";
2428 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2429 # replicate Configuration NC
2430 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2431 unless(system($cmd_repl) == 0) {
2432 warn("Failed to replicate\n$cmd_repl");
2435 # replicate Default NC
2436 $cmd_repl = "$cmd \"$base_dn\"";
2437 unless(system($cmd_repl) == 0) {
2438 warn("Failed to replicate\n$cmd_repl");
2442 # Pull in a full set of changes from the main DC
2443 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2444 $cmd = $self->get_cmd_env_vars($env);
2445 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2446 $cmd .= " $dc_vars->{CONFIGURATION}";
2447 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2448 # replicate Configuration NC
2449 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2450 unless(system($cmd_repl) == 0) {
2451 warn("Failed to replicate\n$cmd_repl");
2454 # replicate Default NC
2455 $cmd_repl = "$cmd \"$base_dn\"";
2456 unless(system($cmd_repl) == 0) {
2457 warn("Failed to replicate\n$cmd_repl");
2465 sub setup_promoted_dc
2467 my ($self, $path, $dc_vars) = @_;
2469 my $env = $self->provision_promoted_dc($path, $dc_vars);
2472 if (not defined($self->check_or_start($env, "single"))) {
2476 # force source and replicated DC to update repsTo/repsFrom
2477 # for vampired partitions
2478 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2479 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2480 # as 'vampired' dc may add data in its local replica
2481 # we need to synchronize data between DCs
2482 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2483 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2484 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2485 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2486 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2487 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2488 $cmd .= " $dc_vars->{CONFIGURATION}";
2489 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2490 # replicate Configuration NC
2491 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2492 unless(system($cmd_repl) == 0) {
2493 warn("Failed to replicate\n$cmd_repl");
2496 # replicate Default NC
2497 $cmd_repl = "$cmd \"$base_dn\"";
2498 unless(system($cmd_repl) == 0) {
2499 warn("Failed to replicate\n$cmd_repl");
2509 my ($self, $path, $dc_vars) = @_;
2511 my $env = $self->provision_subdom_dc($path, $dc_vars);
2514 if (not defined($self->check_or_start($env, "single"))) {
2518 # force replicated DC to update repsTo/repsFrom
2519 # for primary domain partitions
2520 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2521 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2522 # as 'subdomain' dc may add data in its local replica
2523 # we need to synchronize data between DCs
2524 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2525 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2526 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2527 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2528 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2529 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2530 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2531 $cmd .= " $dc_vars->{CONFIGURATION}";
2532 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2533 # replicate Configuration NC
2534 my $cmd_repl = "$cmd \"$config_dn\"";
2535 unless(system($cmd_repl) == 0) {
2536 warn("Failed to replicate\n$cmd_repl");
2539 # replicate Default NC
2540 $cmd_repl = "$cmd \"$base_dn\"";
2541 unless(system($cmd_repl) == 0) {
2542 warn("Failed to replicate\n$cmd_repl");
2552 my ($self, $path, $dc_vars) = @_;
2554 my $env = $self->provision_rodc($path, $dc_vars);
2560 if (not defined($self->check_or_start($env, "standard"))) {
2564 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2567 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2568 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2569 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2570 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2571 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2572 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2573 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2574 $cmd .= " $dc_vars->{CONFIGURATION}";
2575 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2576 # replicate Configuration NC
2577 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2578 unless(system($cmd_repl) == 0) {
2579 warn("Failed to replicate\n$cmd_repl");
2582 # replicate Default NC
2583 $cmd_repl = "$cmd \"$base_dn\"";
2584 unless(system($cmd_repl) == 0) {
2585 warn("Failed to replicate\n$cmd_repl");
2594 my ($self, $path) = @_;
2596 # If we didn't build with ADS, pretend this env was never available
2597 if (not $self->{target3}->have_ads()) {
2601 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2602 "addom.samba.example.com", "", undef);
2607 if (not defined($self->check_or_start($env, "prefork"))) {
2611 my $upn_array = ["$env->{REALM}.upn"];
2612 my $spn_array = ["$env->{REALM}.spn"];
2614 $self->setup_namespaces($env, $upn_array, $spn_array);
2619 sub setup_ad_dc_no_nss
2621 my ($self, $path) = @_;
2623 # If we didn't build with ADS, pretend this env was never available
2624 if (not $self->{target3}->have_ads()) {
2628 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2629 "adnonssdom.samba.example.com", "", undef);
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, "single"))) {
2641 my $upn_array = ["$env->{REALM}.upn"];
2642 my $spn_array = ["$env->{REALM}.spn"];
2644 $self->setup_namespaces($env, $upn_array, $spn_array);
2649 sub setup_ad_dc_no_ntlm
2651 my ($self, $path) = @_;
2653 # If we didn't build with ADS, pretend this env was never available
2654 if (not $self->{target3}->have_ads()) {
2658 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2659 "adnontlmdom.samba.example.com",
2660 "ntlm auth = disabled", undef);
2665 if (not defined($self->check_or_start($env, "prefork"))) {
2669 my $upn_array = ["$env->{REALM}.upn"];
2670 my $spn_array = ["$env->{REALM}.spn"];
2672 $self->setup_namespaces($env, $upn_array, $spn_array);
2678 # AD DC test environment used solely to test pre-fork process restarts.
2679 # As processes get killed off and restarted it should not be used for other
2680 sub setup_preforkrestartdc
2682 my ($self, $path) = @_;
2684 # If we didn't build with ADS, pretend this env was never available
2685 if (not $self->{target3}->have_ads()) {
2689 # note DC name must be <= 15 chars so we use 'prockill' instead of
2691 my $env = $self->provision_ad_dc(
2695 "prockilldom.samba.example.com",
2696 "prefork backoff increment = 5\nprefork maximum backoff=10");
2701 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2702 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
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);
2717 # ad_dc test environment used solely to test standard process model connection
2718 # process limits. As the limit is set artificially low it should not be used
2720 sub setup_proclimitdc
2722 my ($self, $path) = @_;
2724 # If we didn't build with ADS, pretend this env was never available
2725 if (not $self->{target3}->have_ads()) {
2729 my $env = $self->provision_ad_dc(
2733 "proclimit.samba.example.com",
2734 "max smbd processes = 20");
2739 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2740 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2742 if (not defined($self->check_or_start($env, "standard"))) {
2746 my $upn_array = ["$env->{REALM}.upn"];
2747 my $spn_array = ["$env->{REALM}.spn"];
2749 $self->setup_namespaces($env, $upn_array, $spn_array);
2754 # Sets up a DC that's solely used to do a domain backup from. We then use the
2755 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2756 # process will create a Samba DC that will actually start up.
2757 # We don't use the backup-DC for anything else because its domain will conflict
2758 # with the restore DC.
2759 sub setup_backupfromdc
2761 my ($self, $path) = @_;
2763 # If we didn't build with ADS, pretend this env was never available
2764 if (not $self->{target3}->have_ads()) {
2768 my $provision_args = ["--site=Backup-Site"];
2770 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2771 "backupdom.samba.example.com",
2772 "samba kcc command = /bin/true",
2778 if (not defined($self->check_or_start($env))) {
2782 my $upn_array = ["$env->{REALM}.upn"];
2783 my $spn_array = ["$env->{REALM}.spn"];
2785 $self->setup_namespaces($env, $upn_array, $spn_array);
2790 # returns the server/user-auth params needed to run an online backup cmd
2791 sub get_backup_server_args
2793 # dcvars contains the env info for the backup DC testenv
2794 my ($self, $dcvars) = @_;
2795 my $server = $dcvars->{DC_SERVER_IP};
2796 my $server_args = "--server=$server ";
2797 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2798 $server_args .= " $dcvars->{CONFIGURATION}";
2800 return $server_args;
2803 # Creates a backup of a running testenv DC
2806 # note: dcvars contains the env info for the backup DC testenv
2807 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2809 # get all the env variables we pass in with the samba-tool command
2810 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2811 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2812 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2813 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2815 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2817 # Note: use the backupfrom-DC's krb5.conf to do the backup
2818 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2819 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2821 # use samba-tool to create a backup from the 'backupfromdc' DC
2823 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2825 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2826 $cmd .= " --targetdir=$backupdir";
2828 print "Executing: $cmd\n";
2829 unless(system($cmd) == 0) {
2830 warn("Failed to create backup using: \n$cmd");
2834 # get the name of the backup file created
2835 opendir(DIR, $backupdir);
2836 my @files = grep(/\.tar/, readdir(DIR));
2839 if(scalar @files != 1) {
2840 warn("Backup file not found in directory $backupdir\n");
2843 my $backup_file = "$backupdir/$files[0]";
2844 print "Using backup file $backup_file...\n";
2846 return $backup_file;
2849 # Restores a backup-file to populate a testenv for a new DC
2850 sub restore_backup_file
2852 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2854 # pass the restore command the testenv's smb.conf that we've already
2855 # generated. But move it to a temp-dir first, so that the restore doesn't
2857 my $tmpdir = File::Temp->newdir();
2858 my $tmpconf = "$tmpdir/smb.conf";
2859 my $cmd = "cp $smbconf $tmpconf";
2860 unless(system($cmd) == 0) {
2861 warn("Failed to backup smb.conf using: \n$cmd");
2865 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2866 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2867 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2869 print "Executing: $cmd\n";
2870 unless(system($cmd) == 0) {
2871 warn("Failed to restore backup using: \n$cmd");
2875 print "Restore complete\n";
2879 # sets up the initial directory and returns the new testenv's env info
2880 # (without actually doing a 'domain join')
2881 sub prepare_dc_testenv
2883 my ($self, $prefix, $dcname, $domain, $realm,
2884 $password, $conf_options) = @_;
2886 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2896 # the restore uses a slightly different state-dir location to other testenvs
2897 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2898 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2900 # add support for sysvol/netlogon/tmp shares
2901 $ctx->{share} = "$ctx->{prefix_abs}/share";
2902 push(@{$ctx->{directories}}, "$ctx->{share}");
2903 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2905 $ctx->{smb_conf_extra_options} = "
2908 server max protocol = SMB2
2909 samba kcc command = /bin/true
2910 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2913 path = $ctx->{statedir}/sysvol
2917 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2921 path = $ctx->{share}
2923 posix:sharedelay = 10000
2924 posix:oplocktimeout = 3
2925 posix:writetimeupdatedelay = 50000
2928 path = $ctx->{share}/test1
2930 posix:sharedelay = 100000
2931 posix:oplocktimeout = 3
2932 posix:writetimeupdatedelay = 500000
2935 my $env = $self->provision_raw_step1($ctx);
2937 return ($env, $ctx);
2941 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2942 # commands. This proves that we can backup an online DC ('backupfromdc') and
2943 # use the backup file to create a valid, working samba DC.
2946 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2947 my ($self, $prefix, $dcvars) = @_;
2948 print "Preparing RESTORE DC...\n";
2950 # we arbitrarily designate the restored DC as having SMBv1 disabled
2952 server min protocol = SMB2
2953 client min protocol = SMB2
2954 prefork children = 1";
2956 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2959 $dcvars->{PASSWORD},
2962 # create a backup of the 'backupfromdc'
2963 my $backupdir = File::Temp->newdir();
2964 my $server_args = $self->get_backup_server_args($dcvars);
2965 my $backup_args = "online $server_args";
2966 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2968 unless($backup_file) {
2972 # restore the backup file to populate the restore-DC testenv
2973 my $restore_dir = abs_path($prefix);
2974 my $ret = $self->restore_backup_file($backup_file,
2975 "--newservername=$env->{SERVER}",
2976 $restore_dir, $env->{SERVERCONFFILE});
2977 unless ($ret == 0) {
2981 # start samba for the restored DC
2982 if (not defined($self->check_or_start($env))) {
2989 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2990 # restore commands. This proves that we can backup and rename an online DC
2991 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2994 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2995 my ($self, $prefix, $dcvars) = @_;
2996 print "Preparing RENAME DC...\n";
2997 my $extra_conf = "prefork children = 1";
2999 my $realm = "renamedom.samba.example.com";
3000 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3001 "RENAMEDOMAIN", $realm,
3002 $dcvars->{PASSWORD}, $extra_conf);
3004 # create a backup of the 'backupfromdc' which renames the domain
3005 my $backupdir = File::Temp->newdir();
3006 my $server_args = $self->get_backup_server_args($dcvars);
3007 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3008 $backup_args .= " --backend-store=tdb";
3009 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3011 unless($backup_file) {
3015 # restore the backup file to populate the rename-DC testenv
3016 my $restore_dir = abs_path($prefix);
3017 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3018 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3019 $restore_dir, $env->{SERVERCONFFILE});
3020 unless ($ret == 0) {
3024 # start samba for the restored DC
3025 if (not defined($self->check_or_start($env))) {
3029 my $upn_array = ["$env->{REALM}.upn"];
3030 my $spn_array = ["$env->{REALM}.spn"];
3032 $self->setup_namespaces($env, $upn_array, $spn_array);
3037 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3038 # restore commands. This proves that we do an offline backup of a local DC
3039 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3040 sub setup_offlinebackupdc
3042 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3043 my ($self, $prefix, $dcvars) = @_;
3044 print "Preparing OFFLINE BACKUP DC...\n";
3045 my $extra_conf = "prefork children = 1";
3047 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3050 $dcvars->{PASSWORD}, $extra_conf);
3052 # create an offline backup of the 'backupfromdc' target
3053 my $backupdir = File::Temp->newdir();
3054 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3055 my $backup_file = $self->create_backup($env, $dcvars,
3058 unless($backup_file) {
3062 # restore the backup file to populate the rename-DC testenv
3063 my $restore_dir = abs_path($prefix);
3064 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3065 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3066 $restore_dir, $env->{SERVERCONFFILE});
3067 unless ($ret == 0) {
3071 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3072 Samba::mk_krb5_conf($ctx);
3074 # start samba for the restored DC
3075 if (not defined($self->check_or_start($env))) {
3082 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3083 # restore commands, using the --no-secrets option. This proves that we can
3084 # create a realistic lab environment from an online DC ('backupfromdc').
3087 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3088 my ($self, $prefix, $dcvars) = @_;
3089 print "Preparing LAB-DOMAIN DC...\n";
3090 my $extra_conf = "prefork children = 1";
3092 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3094 "labdom.samba.example.com",
3095 $dcvars->{PASSWORD}, $extra_conf);
3097 # create a backup of the 'backupfromdc' which renames the domain and uses
3098 # the --no-secrets option to scrub any sensitive info
3099 my $backupdir = File::Temp->newdir();
3100 my $server_args = $self->get_backup_server_args($dcvars);
3101 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3102 $backup_args .= " --no-secrets --backend-store=mdb";
3103 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3105 unless($backup_file) {
3109 # restore the backup file to populate the lab-DC testenv
3110 my $restore_dir = abs_path($prefix);
3111 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3112 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3113 $restore_dir, $env->{SERVERCONFFILE});
3114 unless ($ret == 0) {
3118 # because we don't include any secrets in the backup, we need to reset the
3119 # admin user's password back to what the testenv expects
3120 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3121 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3122 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3123 $cmd .= " $env->{CONFIGURATION}";
3125 unless(system($cmd) == 0) {
3126 warn("Failed to reset admin's password: \n$cmd");
3130 # start samba for the restored DC
3131 if (not defined($self->check_or_start($env))) {
3135 my $upn_array = ["$env->{REALM}.upn"];
3136 my $spn_array = ["$env->{REALM}.spn"];
3138 $self->setup_namespaces($env, $upn_array, $spn_array);
3143 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3144 sub get_backup_domain_realm
3146 my ($self, $backup_file) = @_;
3148 print "Determining REALM/DOMAIN values in backup...\n";
3150 # The backup will have the correct domain/realm values in the smb.conf.
3151 # So we can work out the env variables the testenv should use based on
3152 # that. Let's start by extracting the smb.conf
3153 my $tar = Archive::Tar->new($backup_file);
3154 my $tmpdir = File::Temp->newdir();
3155 my $smbconf = "$tmpdir/smb.conf";
3157 # note that the filepaths within the tar-file differ slightly for online
3158 # and offline backups
3159 if ($tar->contains_file("etc/smb.conf")) {
3160 $tar->extract_file("etc/smb.conf", $smbconf);
3161 } elsif ($tar->contains_file("./etc/smb.conf")) {
3162 $tar->extract_file("./etc/smb.conf", $smbconf);
3164 warn("Could not find smb.conf in $backup_file");
3165 return undef, undef;
3168 # now use testparm to read the values we're interested in
3169 my $testparm = Samba::bindir_path($self, "testparm");
3170 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3171 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3174 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3176 return ($domain, $realm);
3179 # This spins up a custom testenv that can be based on any backup-file you want.
3180 # This is just intended for manual testing (rather than automated test-cases)
3183 my ($self, $prefix) = @_;
3184 print "Preparing CUSTOM RESTORE DC...\n";
3185 my $dc_name = "customdc";
3186 my $password = "locDCpass1";
3187 my $backup_file = $ENV{'BACKUP_FILE'};
3189 # user must specify a backup file to restore via an ENV variable, i.e.
3190 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3191 if (not defined($backup_file)) {
3192 warn("Please specify BACKUP_FILE");
3196 # work out the correct domain/realm env values from the backup-file
3197 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3199 # create a placeholder directory and smb.conf, as well as the env vars.
3200 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3201 $domain, $realm, $password, "");
3203 # restore the specified backup file to populate the testenv
3204 my $restore_dir = abs_path($prefix);
3205 my $ret = $self->restore_backup_file($backup_file,
3206 "--newservername=$env->{SERVER}",
3207 $restore_dir, $env->{SERVERCONFFILE});
3208 unless ($ret == 0) {
3212 # Change the admin password to the testenv default, just in case it's
3213 # different, or in case this was a --no-secrets backup
3214 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3215 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3216 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3217 $cmd .= " $env->{CONFIGURATION}";
3219 unless(system($cmd) == 0) {
3220 warn("Failed to reset admin's password: \n$cmd");
3224 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3225 # if the backup-file was an offline backup)
3226 Samba::mk_krb5_conf($ctx);
3228 # start samba for the restored DC
3229 if (not defined($self->check_or_start($env))) {
3233 # if this was a backup-rename, then we may need to setup namespaces
3234 my $upn_array = ["$env->{REALM}.upn"];
3235 my $spn_array = ["$env->{REALM}.spn"];
3237 $self->setup_namespaces($env, $upn_array, $spn_array);
3244 my ($self, $path) = @_;
3247 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",