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};
535 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
536 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
537 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
538 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
539 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
540 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
541 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
542 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
544 my $samba_tool = Samba::bindir_path($self, "samba-tool");
547 my $cmd_env = $self->get_cmd_env_vars($localenv);
549 my $cmd_config = " $localenv->{CONFIGURATION}";
550 my $cmd_creds = $cmd_config;
551 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
553 my $create = $cmd_env;
554 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
555 $create .= " $extra_args";
556 $create .= $cmd_creds;
557 unless (system($create) == 0) {
558 warn("Failed to create trust \n$create");
562 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
563 my $groupadd = $cmd_env;
564 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
565 unless (system($groupadd) == 0) {
566 warn("Failed to create group \n$groupadd");
569 my $groupmem = $cmd_env;
570 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
571 unless (system($groupmem) == 0) {
572 warn("Failed to add group member \n$groupmem");
579 sub provision_raw_prepare($$$$$$$$$$$$)
581 my ($self, $prefix, $server_role, $hostname,
582 $domain, $realm, $samsid, $functional_level,
583 $password, $kdc_ipv4, $kdc_ipv6) = @_;
586 if (defined $ENV{PYTHON}) {
587 $python_cmd = $ENV{PYTHON} . " ";
589 $ctx->{python} = $python_cmd;
590 my $netbiosname = uc($hostname);
592 unless(-d $prefix or mkdir($prefix, 0777)) {
593 warn("Unable to create $prefix");
596 my $prefix_abs = abs_path($prefix);
598 die ("prefix=''") if $prefix_abs eq "";
599 die ("prefix='/'") if $prefix_abs eq "/";
601 unless (system("rm -rf $prefix_abs/*") == 0) {
602 warn("Unable to clean up");
606 my $swiface = Samba::get_interface($hostname);
608 $ctx->{prefix} = $prefix;
609 $ctx->{prefix_abs} = $prefix_abs;
611 $ctx->{server_role} = $server_role;
612 $ctx->{hostname} = $hostname;
613 $ctx->{netbiosname} = $netbiosname;
614 $ctx->{swiface} = $swiface;
615 $ctx->{password} = $password;
616 $ctx->{kdc_ipv4} = $kdc_ipv4;
617 $ctx->{kdc_ipv6} = $kdc_ipv6;
618 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
619 if ($functional_level eq "2000") {
620 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
624 # Set smbd log level here.
626 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
627 $ctx->{username} = "Administrator";
628 $ctx->{domain} = $domain;
629 $ctx->{realm} = uc($realm);
630 $ctx->{dnsname} = lc($realm);
631 $ctx->{samsid} = $samsid;
633 $ctx->{functional_level} = $functional_level;
635 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
637 $ctx->{unix_name} = $unix_name;
638 $ctx->{unix_uid} = $>;
639 my @mygid = split(" ", $();
640 $ctx->{unix_gid} = $mygid[0];
641 $ctx->{unix_gids_str} = $);
642 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
644 $ctx->{etcdir} = "$prefix_abs/etc";
645 $ctx->{piddir} = "$prefix_abs/pid";
646 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
647 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
648 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
649 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
650 $ctx->{privatedir} = "$prefix_abs/private";
651 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
652 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
653 $ctx->{lockdir} = "$prefix_abs/lockdir";
654 $ctx->{logdir} = "$prefix_abs/logs";
655 $ctx->{statedir} = "$prefix_abs/statedir";
656 $ctx->{cachedir} = "$prefix_abs/cachedir";
657 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
658 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
659 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
660 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
661 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
662 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
663 if ($ENV{SAMBA_DNS_FAKING}) {
664 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
665 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
666 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
668 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
669 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
670 $ctx->{use_resolv_wrapper} = 1;
673 my $dns_hub = $self->get_dns_hub_env();
674 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
676 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
678 $ctx->{ipv4} = "127.0.0.$swiface";
679 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
680 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
682 push(@{$ctx->{directories}}, $ctx->{privatedir});
683 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
684 push(@{$ctx->{directories}}, $ctx->{etcdir});
685 push(@{$ctx->{directories}}, $ctx->{piddir});
686 push(@{$ctx->{directories}}, $ctx->{lockdir});
687 push(@{$ctx->{directories}}, $ctx->{logdir});
688 push(@{$ctx->{directories}}, $ctx->{statedir});
689 push(@{$ctx->{directories}}, $ctx->{cachedir});
691 $ctx->{smb_conf_extra_options} = "";
693 my @provision_options = ();
694 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
695 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
696 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
697 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
698 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
699 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
700 if (defined($ctx->{use_resolv_wrapper})) {
701 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
702 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
704 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
706 if (defined($ENV{GDB_PROVISION})) {
707 push (@provision_options, "gdb --args");
708 if (!defined($ENV{PYTHON})) {
709 push (@provision_options, "env");
710 push (@provision_options, "python");
713 if (defined($ENV{VALGRIND_PROVISION})) {
714 push (@provision_options, "valgrind");
715 if (!defined($ENV{PYTHON})) {
716 push (@provision_options, "env");
717 push (@provision_options, "python");
721 my $samba_tool = Samba::bindir_path($self, "samba-tool");
723 push (@provision_options, $samba_tool);
724 push (@provision_options, "domain");
725 push (@provision_options, "provision");
726 push (@provision_options, "--configfile=$ctx->{smb_conf}");
727 push (@provision_options, "--host-name=$ctx->{hostname}");
728 push (@provision_options, "--host-ip=$ctx->{ipv4}");
729 push (@provision_options, "--quiet");
730 push (@provision_options, "--domain=$ctx->{domain}");
731 push (@provision_options, "--realm=$ctx->{realm}");
732 if (defined($ctx->{samsid})) {
733 push (@provision_options, "--domain-sid=$ctx->{samsid}");
735 push (@provision_options, "--adminpass=$ctx->{password}");
736 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
737 push (@provision_options, "--machinepass=machine$ctx->{password}");
738 push (@provision_options, "--root=$ctx->{unix_name}");
739 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
740 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
742 @{$ctx->{provision_options}} = @provision_options;
749 my ($self, $keyword, @options_list) = @_;
751 # convert the options-list to a hash-map for easy keyword lookup
752 my %options_dict = map { $_ => 1 } @options_list;
754 return exists $options_dict{$keyword};
758 # Step1 creates the basic configuration
760 sub provision_raw_step1($$)
762 my ($self, $ctx) = @_;
764 mkdir($_, 0777) foreach (@{$ctx->{directories}});
767 ## lockdir and piddir must be 0755
769 chmod 0755, $ctx->{lockdir};
770 chmod 0755, $ctx->{piddir};
772 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
773 warn("can't open $ctx->{smb_conf}$?");
777 Samba::prepare_keyblobs($ctx);
778 my $crlfile = "$ctx->{tlsdir}/crl.pem";
779 $crlfile = "" unless -e ${crlfile};
781 # work out which file server to use. Default to source3 smbd (s3fs),
782 # unless the source4 NTVFS (smb) file server has been specified
783 my $services = "-smb +s3fs";
784 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
785 $services = "+smb -s3fs";
790 netbios name = $ctx->{netbiosname}
791 posix:eadb = $ctx->{statedir}/eadb.tdb
792 workgroup = $ctx->{domain}
793 realm = $ctx->{realm}
794 private dir = $ctx->{privatedir}
795 binddns dir = $ctx->{binddnsdir}
796 pid directory = $ctx->{piddir}
797 ncalrpc dir = $ctx->{ncalrpcdir}
798 lock dir = $ctx->{lockdir}
799 state directory = $ctx->{statedir}
800 cache directory = $ctx->{cachedir}
801 winbindd socket directory = $ctx->{winbindd_socket_dir}
802 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
803 winbind separator = /
804 interfaces = $ctx->{interfaces}
805 tls dh params file = $ctx->{tlsdir}/dhparms.pem
806 tls crlfile = ${crlfile}
807 tls verify peer = no_check
808 panic action = $RealBin/gdb_backtrace \%d
810 server role = $ctx->{server_role}
811 server services = +echo $services
812 dcerpc endpoint servers = +winreg +srvsvc
813 notify:inotify = false
815 ldap server require strong auth = yes
816 #We don't want to pass our self-tests if the PAC code is wrong
817 gensec:require_pac = true
818 log file = $ctx->{logdir}/log.\%m
819 log level = $ctx->{server_loglevel}
823 dns update command = $ctx->{samba_dnsupdate}
824 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
825 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
826 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
827 dreplsrv:periodic_startup_interval = 0
828 dsdb:schema update allowed = yes
830 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
832 idmap_ldb:use rfc2307=yes
833 winbind enum users = yes
834 winbind enum groups = yes
836 rpc server port:netlogon = 1026
842 # Begin extra options
843 $ctx->{smb_conf_extra_options}
848 #Default the KDC IP to the server's IP
849 if (not defined($ctx->{kdc_ipv4})) {
850 $ctx->{kdc_ipv4} = $ctx->{ipv4};
852 if (not defined($ctx->{kdc_ipv6})) {
853 $ctx->{kdc_ipv6} = $ctx->{ipv6};
856 Samba::mk_krb5_conf($ctx);
857 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
859 open(PWD, ">$ctx->{nsswrap_passwd}");
860 if ($ctx->{unix_uid} != 0) {
861 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
863 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
864 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
865 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
866 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
867 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
868 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
871 my $uid_rfc2307test = 65533;
873 open(GRP, ">$ctx->{nsswrap_group}");
874 if ($ctx->{unix_gid} != 0) {
875 print GRP "root:x:0:\n";
877 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
878 print GRP "wheel:x:10:
881 nogroup:x:65534:nobody
884 my $gid_rfc2307test = 65532;
886 my $hostname = lc($ctx->{hostname});
887 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
888 if ($hostname eq "localdc") {
889 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
890 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
892 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
893 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
897 my $configuration = "--configfile=$ctx->{smb_conf}";
899 #Ensure the config file is valid before we start
900 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
901 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
902 system("$testparm -v --suppress-prompt $configuration >&2");
903 warn("Failed to create a valid smb.conf configuration $testparm!");
906 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) {
907 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
912 KRB5_CONFIG => $ctx->{krb5_conf},
913 KRB5_CCACHE => $ctx->{krb5_ccache},
914 MITKDC_CONFIG => $ctx->{mitkdc_conf},
915 PIDDIR => $ctx->{piddir},
916 SERVER => $ctx->{hostname},
917 SERVER_IP => $ctx->{ipv4},
918 SERVER_IPV6 => $ctx->{ipv6},
919 NETBIOSNAME => $ctx->{netbiosname},
920 DOMAIN => $ctx->{domain},
921 USERNAME => $ctx->{username},
922 REALM => $ctx->{realm},
923 DNSNAME => $ctx->{dnsname},
924 SAMSID => $ctx->{samsid},
925 PASSWORD => $ctx->{password},
926 LDAPDIR => $ctx->{ldapdir},
927 LDAP_INSTANCE => $ctx->{ldap_instance},
928 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
929 NCALRPCDIR => $ctx->{ncalrpcdir},
930 LOCKDIR => $ctx->{lockdir},
931 STATEDIR => $ctx->{statedir},
932 CACHEDIR => $ctx->{cachedir},
933 PRIVATEDIR => $ctx->{privatedir},
934 BINDDNSDIR => $ctx->{binddnsdir},
935 SERVERCONFFILE => $ctx->{smb_conf},
936 CONFIGURATION => $configuration,
937 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
938 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
939 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
940 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
941 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
942 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
943 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
944 SAMBA_TEST_LOG_POS => 0,
945 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
946 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
947 LOCAL_PATH => $ctx->{share},
948 UID_RFC2307TEST => $uid_rfc2307test,
949 GID_RFC2307TEST => $gid_rfc2307test,
950 SERVER_ROLE => $ctx->{server_role},
951 RESOLV_CONF => $ctx->{resolv_conf}
954 if (defined($ctx->{use_resolv_wrapper})) {
955 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
957 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
960 if ($ctx->{server_role} eq "domain controller") {
961 $ret->{DOMSID} = $ret->{SAMSID};
968 # Step2 runs the provision script
970 sub provision_raw_step2($$$)
972 my ($self, $ctx, $ret) = @_;
974 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
975 unless (system($provision_cmd) == 0) {
976 warn("Unable to provision: \n$provision_cmd\n");
980 my $testallowed_account = "testallowed";
981 my $samba_tool_cmd = "";
982 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
983 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
984 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
985 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
986 unless (system($samba_tool_cmd) == 0) {
987 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
992 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
993 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
994 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
995 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
997 if ($ctx->{server_role} ne "domain controller") {
998 $base_dn = "DC=$ctx->{netbiosname}";
1001 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
1002 $testallowed_account = "testallowed account";
1003 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1004 print LDIF "dn: $user_dn
1006 replace: samAccountName
1007 samAccountName: $testallowed_account
1012 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1013 print LDIF "dn: $user_dn
1015 replace: userPrincipalName
1016 userPrincipalName: testallowed upn\@$ctx->{realm}
1017 replace: servicePrincipalName
1018 servicePrincipalName: host/testallowed
1023 $samba_tool_cmd = "";
1024 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1025 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1026 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1027 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1028 unless (system($samba_tool_cmd) == 0) {
1029 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1033 my $user_dn = "cn=testdenied,cn=users,$base_dn";
1034 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1035 print LDIF "dn: $user_dn
1037 replace: userPrincipalName
1038 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1043 $samba_tool_cmd = "";
1044 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1045 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1046 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1047 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1048 unless (system($samba_tool_cmd) == 0) {
1049 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1053 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
1054 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1055 print LDIF "dn: $user_dn
1057 replace: userPrincipalName
1058 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1059 replace: servicePrincipalName
1060 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1065 $samba_tool_cmd = "";
1066 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1067 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1068 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1069 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1070 unless (system($samba_tool_cmd) == 0) {
1071 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1075 # Create to users alice and bob!
1076 my $user_account_array = ["alice", "bob", "jane"];
1078 foreach my $user_account (@{$user_account_array}) {
1079 my $samba_tool_cmd = "";
1081 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1082 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1083 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1084 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1085 unless (system($samba_tool_cmd) == 0) {
1086 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1092 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1093 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1094 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1096 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1097 my $user_dn = "cn=jane,cn=users,$base_dn";
1099 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1100 print LDIF "dn: $user_dn
1102 replace: userPrincipalName
1103 userPrincipalName: jane.doe\@$ctx->{realm}
1111 sub provision($$$$$$$$$$)
1113 my ($self, $prefix, $server_role, $hostname,
1114 $domain, $realm, $functional_level,
1115 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1116 $extra_provision_options) = @_;
1118 my $samsid = Samba::random_domain_sid();
1120 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1125 $password, $kdc_ipv4, $kdc_ipv6);
1127 if (defined($extra_provision_options)) {
1128 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1131 $ctx->{share} = "$ctx->{prefix_abs}/share";
1132 push(@{$ctx->{directories}}, "$ctx->{share}");
1133 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1134 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1136 # precreate directories for printer drivers
1137 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1138 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1139 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1142 $msdfs = "yes" if ($server_role eq "domain controller");
1143 $ctx->{smb_conf_extra_options} = "
1146 server max protocol = SMB2
1150 # fruit:copyfile is a global option
1151 fruit:copyfile = yes
1153 $extra_smbconf_options
1156 path = $ctx->{share}
1158 posix:sharedelay = 100000
1159 posix:oplocktimeout = 3
1160 posix:writetimeupdatedelay = 500000
1163 path = $ctx->{share}
1165 posix:sharedelay = 100000
1166 posix:oplocktimeout = 3
1167 posix:writetimeupdatedelay = 500000
1169 force create mode = 777
1172 path = $ctx->{share}
1175 force create mode = 0
1176 directory mask = 0777
1177 force directory mode = 0
1180 path = $ctx->{share}/test1
1182 posix:sharedelay = 100000
1183 posix:oplocktimeout = 3
1184 posix:writetimeupdatedelay = 500000
1187 path = $ctx->{share}/test2
1189 posix:sharedelay = 100000
1190 posix:oplocktimeout = 3
1191 posix:writetimeupdatedelay = 500000
1194 path = $ctx->{share}/_ignore_cifs_
1196 ntvfs handler = cifs
1197 cifs:server = $ctx->{netbiosname}
1199 cifs:use-s4u2proxy = yes
1200 # There is no username specified here, instead the client is expected
1201 # to log in with kerberos, and the serverwill use delegated credentials.
1202 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1205 path = $ctx->{share}
1207 ntvfs handler = simple
1210 path = $ctx->{statedir}/sysvol
1214 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1219 ntvfs handler = cifsposix
1222 path = $ctx->{share}
1223 vfs objects = catia fruit streams_xattr acl_xattr
1225 fruit:resource = file
1226 fruit:metadata = netatalk
1227 fruit:locking = netatalk
1228 fruit:encoding = native
1230 $extra_smbconf_shares
1233 if (defined($self->{ldap})) {
1234 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1235 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1237 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1238 $ldap_uri =~ s|/|%2F|g;
1239 $ldap_uri = "ldapi://$ldap_uri";
1240 $ctx->{ldap_uri} = $ldap_uri;
1242 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1245 my $ret = $self->provision_raw_step1($ctx);
1246 unless (defined $ret) {
1250 if (defined($self->{ldap})) {
1251 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1252 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1253 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1254 if ($self->{ldap} eq "openldap") {
1255 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1256 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1258 } elsif ($self->{ldap} eq "fedora-ds") {
1259 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1260 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1261 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1266 return $self->provision_raw_step2($ctx, $ret);
1269 sub provision_s4member($$$$$)
1271 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1272 print "PROVISIONING MEMBER...\n";
1273 my $extra_smb_conf = "
1274 passdb backend = samba_dsdb
1275 winbindd:use external pipes = true
1277 # the source4 smb server doesn't allow signing by default
1278 server signing = enabled
1279 raw NTLMv2 auth = yes
1281 rpc_server:default = external
1282 rpc_server:svcctl = embedded
1283 rpc_server:srvsvc = embedded
1284 rpc_server:eventlog = embedded
1285 rpc_server:ntsvcs = embedded
1286 rpc_server:winreg = embedded
1287 rpc_server:spoolss = embedded
1288 rpc_daemon:spoolssd = embedded
1289 rpc_server:tcpip = no
1292 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1294 my $extra_provision_options = ["--use-ntvfs"];
1295 my $ret = $self->provision($prefix,
1302 $dcvars->{SERVER_IP},
1303 $dcvars->{SERVER_IPV6},
1304 $extra_smb_conf, "",
1305 $extra_provision_options);
1310 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1311 my $cmd = $self->get_cmd_env_vars($ret);
1312 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1313 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1314 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1316 unless (system($cmd) == 0) {
1317 warn("Join failed\n$cmd");
1321 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1322 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1323 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1324 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1325 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1326 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1328 $ret->{DOMSID} = $dcvars->{DOMSID};
1329 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1330 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1331 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1332 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1333 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1334 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1339 sub provision_rpc_proxy($$$)
1341 my ($self, $prefix, $dcvars) = @_;
1342 print "PROVISIONING RPC PROXY...\n";
1344 my $extra_smbconf_options = "
1345 passdb backend = samba_dsdb
1348 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1349 dcerpc endpoint servers = epmapper, remote
1350 dcerpc_remote:interfaces = rpcecho
1351 dcerpc_remote:allow_anonymous_fallback = yes
1354 path = /tmp/_ignore_cifs_to_dc_/_none_
1356 ntvfs handler = cifs
1357 cifs:server = $dcvars->{SERVER}
1359 cifs:use-s4u2proxy = yes
1360 # There is no username specified here, instead the client is expected
1361 # to log in with kerberos, and the serverwill use delegated credentials.
1362 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1366 my $extra_provision_options = ["--use-ntvfs"];
1367 my $ret = $self->provision($prefix,
1374 $dcvars->{SERVER_IP},
1375 $dcvars->{SERVER_IPV6},
1376 $extra_smbconf_options, "",
1377 $extra_provision_options);
1382 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1384 # The joind runs in the context of the rpc_proxy/member for now
1385 my $cmd = $self->get_cmd_env_vars($ret);
1386 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1387 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1388 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1390 unless (system($cmd) == 0) {
1391 warn("Join failed\n$cmd");
1395 # Setting up delegation runs in the context of the DC for now
1397 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1398 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1399 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1400 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1401 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1402 $cmd .= " $dcvars->{CONFIGURATION}";
1405 unless (system($cmd) == 0) {
1406 warn("Delegation failed\n$cmd");
1410 # Setting up delegation runs in the context of the DC for now
1412 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1413 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1414 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1415 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1416 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1417 $cmd .= " $dcvars->{CONFIGURATION}";
1419 unless (system($cmd) == 0) {
1420 warn("Delegation failed\n$cmd");
1424 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1425 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1426 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1427 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1428 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1429 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1431 $ret->{DOMSID} = $dcvars->{DOMSID};
1432 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1433 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1434 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1435 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1436 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1437 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1442 sub provision_promoted_dc($$$)
1444 my ($self, $prefix, $dcvars) = @_;
1445 print "PROVISIONING PROMOTED DC...\n";
1447 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1448 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1454 $dcvars->{PASSWORD},
1455 $dcvars->{SERVER_IP},
1456 $dcvars->{SERVER_IPV6});
1458 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1460 $ctx->{smb_conf_extra_options} = "
1462 server max protocol = SMB2
1464 ntlm auth = ntlmv2-only
1467 path = $ctx->{statedir}/sysvol
1471 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1476 my $ret = $self->provision_raw_step1($ctx);
1481 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1482 my $cmd = $self->get_cmd_env_vars($ret);
1483 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1484 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1485 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1487 unless (system($cmd) == 0) {
1488 warn("Join failed\n$cmd");
1492 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1493 my $cmd = $self->get_cmd_env_vars($ret);
1494 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1495 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1496 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1498 unless (system($cmd) == 0) {
1499 warn("Join failed\n$cmd");
1503 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1504 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1505 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1506 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1508 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1509 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1510 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1511 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1512 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1513 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1518 sub provision_vampire_dc($$$)
1520 my ($self, $prefix, $dcvars, $fl) = @_;
1521 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1522 my $name = "localvampiredc";
1523 my $extra_conf = "";
1525 if ($fl == "2000") {
1526 $name = "vampire2000dc";
1528 $extra_conf = "drs: immediate link sync = yes
1529 drs: max link sync = 250";
1532 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1533 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1539 $dcvars->{PASSWORD},
1540 $dcvars->{SERVER_IP},
1541 $dcvars->{SERVER_IPV6});
1543 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1545 $ctx->{smb_conf_extra_options} = "
1547 server max protocol = SMB2
1549 ntlm auth = mschapv2-and-ntlmv2-only
1553 path = $ctx->{statedir}/sysvol
1557 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1562 my $ret = $self->provision_raw_step1($ctx);
1567 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1568 my $cmd = $self->get_cmd_env_vars($ret);
1569 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1570 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1571 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1572 $cmd .= " --backend-store=mdb";
1574 unless (system($cmd) == 0) {
1575 warn("Join failed\n$cmd");
1579 if ($fl == "2000") {
1580 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1581 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1582 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1583 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1585 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1586 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1587 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1588 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1590 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1591 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1592 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1593 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1594 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1595 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1596 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1601 sub provision_subdom_dc($$$)
1603 my ($self, $prefix, $dcvars) = @_;
1604 print "PROVISIONING SUBDOMAIN DC...\n";
1606 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1607 my $samsid = undef; # TODO pass the domain sid all the way down
1608 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1611 "sub.samba.example.com",
1614 $dcvars->{PASSWORD},
1617 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1619 $ctx->{smb_conf_extra_options} = "
1621 server max protocol = SMB2
1624 path = $ctx->{statedir}/sysvol
1628 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1633 my $ret = $self->provision_raw_step1($ctx);
1638 Samba::mk_krb5_conf($ctx);
1639 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1641 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1642 my $cmd = $self->get_cmd_env_vars($ret);
1643 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1644 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1645 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1646 $cmd .= " --adminpass=$ret->{PASSWORD}";
1648 unless (system($cmd) == 0) {
1649 warn("Join failed\n$cmd");
1653 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1654 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1655 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1656 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1658 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1659 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1660 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1661 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1662 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1663 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1668 sub provision_ad_dc_ntvfs($$)
1670 my ($self, $prefix) = @_;
1672 # We keep the old 'winbind' name here in server services to
1673 # ensure upgrades which used that name still work with the now
1676 print "PROVISIONING AD DC (NTVFS)...\n";
1677 my $extra_conf_options = "netbios aliases = localDC1-a
1678 server services = +winbind -winbindd
1679 ldap server require strong auth = allow_sasl_over_tls
1680 allow nt4 crypto = yes
1681 raw NTLMv2 auth = yes
1682 lsa over netlogon = yes
1683 rpc server port = 1027
1684 auth event notification = true
1685 dsdb event notification = true
1686 dsdb password event notification = true
1687 dsdb group change notification = true
1688 server schannel = auto
1690 my $extra_provision_options = ["--use-ntvfs"];
1691 my $ret = $self->provision($prefix,
1692 "domain controller",
1695 "samba.example.com",
1700 $extra_conf_options,
1702 $extra_provision_options);
1707 unless($self->add_wins_config("$prefix/private")) {
1708 warn("Unable to add wins configuration");
1711 $ret->{NETBIOSALIAS} = "localdc1-a";
1712 $ret->{DC_SERVER} = $ret->{SERVER};
1713 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1714 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1715 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1716 $ret->{DC_USERNAME} = $ret->{USERNAME};
1717 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1718 $ret->{DC_REALM} = $ret->{REALM};
1723 sub provision_fl2000dc($$)
1725 my ($self, $prefix) = @_;
1727 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1728 my $extra_conf_options = "
1729 spnego:simulate_w2k=yes
1730 ntlmssp_server:force_old_spnego=yes
1732 my $extra_provision_options = ["--use-ntvfs"];
1733 # This environment uses plain text secrets
1734 # i.e. secret attributes are not encrypted on disk.
1735 # This allows testing of the --plaintext-secrets option for
1737 push (@{$extra_provision_options}, "--plaintext-secrets");
1738 my $ret = $self->provision($prefix,
1739 "domain controller",
1742 "samba2000.example.com",
1747 $extra_conf_options,
1749 $extra_provision_options);
1754 unless($self->add_wins_config("$prefix/private")) {
1755 warn("Unable to add wins configuration");
1758 $ret->{DC_SERVER} = $ret->{SERVER};
1759 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1760 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1761 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1762 $ret->{DC_USERNAME} = $ret->{USERNAME};
1763 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1764 $ret->{DC_REALM} = $ret->{REALM};
1769 sub provision_fl2003dc($$$)
1771 my ($self, $prefix, $dcvars) = @_;
1772 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1773 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1775 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1776 my $extra_conf_options = "allow dns updates = nonsecure and secure
1777 dcesrv:header signing = no
1778 dcesrv:max auth states = 0
1779 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1780 my $extra_provision_options = ["--use-ntvfs"];
1781 my $ret = $self->provision($prefix,
1782 "domain controller",
1785 "samba2003.example.com",
1790 $extra_conf_options,
1792 $extra_provision_options);
1793 unless (defined $ret) {
1797 $ret->{DC_SERVER} = $ret->{SERVER};
1798 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1799 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1800 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1801 $ret->{DC_USERNAME} = $ret->{USERNAME};
1802 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1803 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1804 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1806 my @samba_tool_options;
1807 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1808 push (@samba_tool_options, "domain");
1809 push (@samba_tool_options, "passwordsettings");
1810 push (@samba_tool_options, "set");
1811 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1812 push (@samba_tool_options, "--min-pwd-age=0");
1813 push (@samba_tool_options, "--history-length=1");
1815 my $samba_tool_cmd = join(" ", @samba_tool_options);
1817 unless (system($samba_tool_cmd) == 0) {
1818 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1822 unless($self->add_wins_config("$prefix/private")) {
1823 warn("Unable to add wins configuration");
1830 sub provision_fl2008r2dc($$$)
1832 my ($self, $prefix, $dcvars) = @_;
1834 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1835 my $extra_conf_options = "ldap server require strong auth = no";
1836 my $extra_provision_options = ["--use-ntvfs"];
1837 my $ret = $self->provision($prefix,
1838 "domain controller",
1841 "samba2008R2.example.com",
1846 $extra_conf_options,
1848 $extra_provision_options);
1849 unless (defined $ret) {
1853 unless ($self->add_wins_config("$prefix/private")) {
1854 warn("Unable to add wins configuration");
1857 $ret->{DC_SERVER} = $ret->{SERVER};
1858 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1859 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1860 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1861 $ret->{DC_USERNAME} = $ret->{USERNAME};
1862 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1863 $ret->{DC_REALM} = $ret->{REALM};
1869 sub provision_rodc($$$)
1871 my ($self, $prefix, $dcvars) = @_;
1872 print "PROVISIONING RODC...\n";
1874 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1875 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1881 $dcvars->{PASSWORD},
1882 $dcvars->{SERVER_IP},
1883 $dcvars->{SERVER_IPV6});
1888 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1890 $ctx->{share} = "$ctx->{prefix_abs}/share";
1891 push(@{$ctx->{directories}}, "$ctx->{share}");
1893 $ctx->{smb_conf_extra_options} = "
1895 server max protocol = SMB2
1896 password server = $dcvars->{DC_SERVER}
1899 path = $ctx->{statedir}/sysvol
1903 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1907 path = $ctx->{share}
1909 posix:sharedelay = 10000
1910 posix:oplocktimeout = 3
1911 posix:writetimeupdatedelay = 50000
1915 my $ret = $self->provision_raw_step1($ctx);
1920 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1921 my $cmd = $self->get_cmd_env_vars($ret);
1922 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1923 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1924 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1926 unless (system($cmd) == 0) {
1927 warn("RODC join failed\n$cmd");
1931 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1932 # user password verified on the RODC
1933 my $testallowed_account = "testallowed account";
1934 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1935 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1936 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1937 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1938 $cmd .= " --server=$dcvars->{DC_SERVER}";
1940 unless (system($cmd) == 0) {
1941 warn("RODC join failed\n$cmd");
1945 # we overwrite the kdc after the RODC join
1946 # so that use the RODC as kdc and test
1948 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1949 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1950 Samba::mk_krb5_conf($ctx);
1951 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1953 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1954 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1955 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1956 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1958 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1959 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1960 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1961 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1962 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1963 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1968 sub read_config_h($)
1972 open(LF, "<$name") or die("unable to read $name: $!");
1975 next if not (/^#define /);
1976 if (/^#define (.*?)[ \t]+(.*?)$/) {
1980 if (/^#define (.*?)[ \t]+$/) {
1989 sub provision_ad_dc($$$$$$)
1991 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1992 $extra_provision_options) = @_;
1994 my $prefix_abs = abs_path($prefix);
1996 my $bindir_abs = abs_path($self->{bindir});
1997 my $lockdir="$prefix_abs/lockdir";
1998 my $conffile="$prefix_abs/etc/smb.conf";
2000 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
2001 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
2005 if (defined($ENV{CONFIG_H})) {
2006 $config_h = read_config_h($ENV{CONFIG_H});
2009 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
2010 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
2012 my $extra_smbconf_options = "
2013 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
2015 dbwrap_tdb_mutexes:* = yes
2018 ${password_hash_gpg_key_ids}
2021 kernel change notify = no
2026 printcap name = /dev/null
2031 smbd:sharedelay = 100000
2032 smbd:writetimeupdatedelay = 500000
2035 check parent directory delete on close = yes
2037 dcerpc endpoint servers = -winreg -srvsvc
2039 printcap name = /dev/null
2041 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
2042 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
2045 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
2046 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
2047 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
2048 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
2049 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
2050 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
2051 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
2053 print notify backchannel = yes
2055 server schannel = auto
2056 auth event notification = true
2057 dsdb event notification = true
2058 dsdb password event notification = true
2059 dsdb group change notification = true
2063 my $extra_smbconf_shares = "
2067 smb encrypt = required
2071 case sensitive = yes
2079 hide unreadable = yes
2083 kernel share modes = no
2102 push (@{$extra_provision_options}, "--backend-store=mdb");
2103 print "PROVISIONING AD DC...\n";
2104 my $ret = $self->provision($prefix,
2105 "domain controller",
2113 $extra_smbconf_options,
2114 $extra_smbconf_shares,
2115 $extra_provision_options);
2116 unless (defined $ret) {
2120 unless($self->add_wins_config("$prefix/private")) {
2121 warn("Unable to add wins configuration");
2125 $ret->{DC_SERVER} = $ret->{SERVER};
2126 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2127 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2128 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2129 $ret->{DC_USERNAME} = $ret->{USERNAME};
2130 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2135 sub provision_chgdcpass($$)
2137 my ($self, $prefix) = @_;
2139 print "PROVISIONING CHGDCPASS...\n";
2140 # This environment disallows the use of this password
2141 # (and also removes the default AD complexity checks)
2142 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2143 my $extra_smb_conf = "
2144 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
2145 allow dcerpc auth level connect:lsarpc = yes
2146 dcesrv:max auth states = 8
2148 my $extra_provision_options = ["--use-ntvfs"];
2149 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2150 my $ret = $self->provision($prefix,
2151 "domain controller",
2154 "chgdcpassword.samba.example.com",
2161 $extra_provision_options);
2162 unless (defined $ret) {
2166 unless($self->add_wins_config("$prefix/private")) {
2167 warn("Unable to add wins configuration");
2171 # Remove secrets.tdb from this environment to test that we
2172 # still start up on systems without the new matching
2173 # secrets.tdb records.
2174 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2175 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2179 $ret->{DC_SERVER} = $ret->{SERVER};
2180 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2181 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2182 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2183 $ret->{DC_USERNAME} = $ret->{USERNAME};
2184 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2185 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2190 sub teardown_env_terminate($$)
2192 my ($self, $envvars) = @_;
2195 # This should cause samba to terminate gracefully
2196 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2198 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2199 my $ret = system($cmd);
2201 warn "'$cmd' failed with '$ret'\n";
2204 # This should cause samba to terminate gracefully
2205 close($envvars->{STDIN_PIPE});
2207 $pid = $envvars->{SAMBA_PID};
2211 # This should give it time to write out the gcov data
2212 until ($count > 15) {
2213 if (Samba::cleanup_child($pid, "samba") != 0) {
2220 # After 15 Seconds, work out why this thing is still alive
2221 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2222 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2224 until ($count > 30) {
2225 if (Samba::cleanup_child($pid, "samba") != 0) {
2232 if (kill(0, $pid)) {
2233 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2237 until ($count > 40) {
2238 if (Samba::cleanup_child($pid, "samba") != 0) {
2244 # If it is still around, kill it
2245 if (kill(0, $pid)) {
2246 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2252 sub teardown_env($$)
2254 my ($self, $envvars) = @_;
2255 teardown_env_terminate($self, $envvars);
2257 $self->slapd_stop($envvars) if ($self->{ldap});
2259 print $self->getlog_env($envvars);
2266 my ($self, $envvars) = @_;
2267 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2270 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2272 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2276 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2279 return "" if $out eq $title;
2286 my ($self, $envvars) = @_;
2287 my $samba_pid = $envvars->{SAMBA_PID};
2289 if (not defined($samba_pid)) {
2291 } elsif ($samba_pid > 0) {
2292 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2294 if ($childpid == 0) {
2303 # Declare the environments Samba4 makes available.
2304 # To be set up, they will be called as
2305 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2306 # The interdependencies between the testenvs are declared below. Some testenvs
2307 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2308 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2309 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2310 %Samba4::ENV_DEPS = (
2311 # name => [dep_1, dep_2, ...],
2313 ad_dc_ntvfs => ["dns_hub"],
2314 ad_dc => ["dns_hub"],
2315 ad_dc_no_nss => ["dns_hub"],
2316 ad_dc_no_ntlm => ["dns_hub"],
2318 fl2008r2dc => ["ad_dc"],
2319 fl2003dc => ["ad_dc"],
2320 fl2000dc => ["dns_hub"],
2322 vampire_2000_dc => ["fl2000dc"],
2323 vampire_dc => ["ad_dc_ntvfs"],
2324 promoted_dc => ["ad_dc_ntvfs"],
2325 subdom_dc => ["ad_dc_ntvfs"],
2327 rodc => ["ad_dc_ntvfs"],
2328 rpc_proxy => ["ad_dc_ntvfs"],
2329 chgdcpass => ["dns_hub"],
2331 s4member_dflt_domain => ["ad_dc_ntvfs"],
2332 s4member => ["ad_dc_ntvfs"],
2334 # envs that test the server process model
2335 proclimitdc => ["dns_hub"],
2336 preforkrestartdc => ["dns_hub"],
2338 # backup/restore testenvs
2339 backupfromdc => ["dns_hub"],
2340 customdc => ["dns_hub"],
2341 restoredc => ["backupfromdc"],
2342 renamedc => ["backupfromdc"],
2343 offlinebackupdc => ["backupfromdc"],
2344 labdc => ["backupfromdc"],
2351 my ($self, $path, $dc_vars) = @_;
2353 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2356 if (not defined($self->check_or_start($env, "standard"))) {
2364 sub setup_s4member_dflt_domain
2366 my ($self, $path, $dc_vars) = @_;
2368 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2369 "winbind use default domain = yes");
2372 if (not defined($self->check_or_start($env, "standard"))) {
2382 my ($self, $path, $dc_vars) = @_;
2384 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2387 if (not defined($self->check_or_start($env, "standard"))) {
2394 sub setup_ad_dc_ntvfs
2396 my ($self, $path) = @_;
2398 my $env = $self->provision_ad_dc_ntvfs($path);
2400 if (not defined($self->check_or_start($env, "standard"))) {
2401 warn("Failed to start ad_dc_ntvfs");
2410 my ($self, $path) = @_;
2412 my $env = $self->provision_chgdcpass($path);
2414 if (not defined($self->check_or_start($env, "standard"))) {
2423 my ($self, $path) = @_;
2425 my $env = $self->provision_fl2000dc($path);
2427 if (not defined($self->check_or_start($env, "standard"))) {
2437 my ($self, $path, $dc_vars) = @_;
2439 my $env = $self->provision_fl2003dc($path);
2442 if (not defined($self->check_or_start($env, "standard"))) {
2446 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2451 sub setup_fl2008r2dc
2453 my ($self, $path, $dc_vars) = @_;
2455 my $env = $self->provision_fl2008r2dc($path);
2458 if (not defined($self->check_or_start($env, "standard"))) {
2462 my $upn_array = ["$env->{REALM}.upn"];
2463 my $spn_array = ["$env->{REALM}.spn"];
2465 $self->setup_namespaces($env, $upn_array, $spn_array);
2467 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2473 sub setup_vampire_dc
2475 return setup_generic_vampire_dc(@_, "2008");
2478 sub setup_vampire_2000_dc
2480 return setup_generic_vampire_dc(@_, "2000");
2483 sub setup_generic_vampire_dc
2485 my ($self, $path, $dc_vars, $fl) = @_;
2487 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2490 if (not defined($self->check_or_start($env, "single"))) {
2494 # force replicated DC to update repsTo/repsFrom
2495 # for vampired partitions
2496 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2498 # as 'vampired' dc may add data in its local replica
2499 # we need to synchronize data between DCs
2500 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2501 my $cmd = $self->get_cmd_env_vars($env);
2502 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2503 $cmd .= " $dc_vars->{CONFIGURATION}";
2504 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2505 # replicate Configuration NC
2506 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2507 unless(system($cmd_repl) == 0) {
2508 warn("Failed to replicate\n$cmd_repl");
2511 # replicate Default NC
2512 $cmd_repl = "$cmd \"$base_dn\"";
2513 unless(system($cmd_repl) == 0) {
2514 warn("Failed to replicate\n$cmd_repl");
2518 # Pull in a full set of changes from the main DC
2519 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2520 $cmd = $self->get_cmd_env_vars($env);
2521 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2522 $cmd .= " $dc_vars->{CONFIGURATION}";
2523 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2524 # replicate Configuration NC
2525 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2526 unless(system($cmd_repl) == 0) {
2527 warn("Failed to replicate\n$cmd_repl");
2530 # replicate Default NC
2531 $cmd_repl = "$cmd \"$base_dn\"";
2532 unless(system($cmd_repl) == 0) {
2533 warn("Failed to replicate\n$cmd_repl");
2541 sub setup_promoted_dc
2543 my ($self, $path, $dc_vars) = @_;
2545 my $env = $self->provision_promoted_dc($path, $dc_vars);
2548 if (not defined($self->check_or_start($env, "single"))) {
2552 # force source and replicated DC to update repsTo/repsFrom
2553 # for vampired partitions
2554 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2555 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2556 # as 'vampired' dc may add data in its local replica
2557 # we need to synchronize data between DCs
2558 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2559 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2560 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2561 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2562 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2563 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2564 $cmd .= " $dc_vars->{CONFIGURATION}";
2565 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2566 # replicate Configuration NC
2567 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2568 unless(system($cmd_repl) == 0) {
2569 warn("Failed to replicate\n$cmd_repl");
2572 # replicate Default NC
2573 $cmd_repl = "$cmd \"$base_dn\"";
2574 unless(system($cmd_repl) == 0) {
2575 warn("Failed to replicate\n$cmd_repl");
2585 my ($self, $path, $dc_vars) = @_;
2587 my $env = $self->provision_subdom_dc($path, $dc_vars);
2590 if (not defined($self->check_or_start($env, "single"))) {
2594 # force replicated DC to update repsTo/repsFrom
2595 # for primary domain partitions
2596 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2597 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2598 # as 'subdomain' dc may add data in its local replica
2599 # we need to synchronize data between DCs
2600 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2601 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2602 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2603 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2604 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2605 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2606 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2607 $cmd .= " $dc_vars->{CONFIGURATION}";
2608 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2609 # replicate Configuration NC
2610 my $cmd_repl = "$cmd \"$config_dn\"";
2611 unless(system($cmd_repl) == 0) {
2612 warn("Failed to replicate\n$cmd_repl");
2615 # replicate Default NC
2616 $cmd_repl = "$cmd \"$base_dn\"";
2617 unless(system($cmd_repl) == 0) {
2618 warn("Failed to replicate\n$cmd_repl");
2628 my ($self, $path, $dc_vars) = @_;
2630 my $env = $self->provision_rodc($path, $dc_vars);
2636 if (not defined($self->check_or_start($env, "standard"))) {
2640 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2643 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2644 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2645 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2646 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2647 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2648 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2649 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2650 $cmd .= " $dc_vars->{CONFIGURATION}";
2651 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2652 # replicate Configuration NC
2653 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2654 unless(system($cmd_repl) == 0) {
2655 warn("Failed to replicate\n$cmd_repl");
2658 # replicate Default NC
2659 $cmd_repl = "$cmd \"$base_dn\"";
2660 unless(system($cmd_repl) == 0) {
2661 warn("Failed to replicate\n$cmd_repl");
2670 my ($self, $path) = @_;
2672 # If we didn't build with ADS, pretend this env was never available
2673 if (not $self->{target3}->have_ads()) {
2677 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2678 "addom.samba.example.com", "", undef);
2683 if (not defined($self->check_or_start($env, "prefork"))) {
2687 my $upn_array = ["$env->{REALM}.upn"];
2688 my $spn_array = ["$env->{REALM}.spn"];
2690 $self->setup_namespaces($env, $upn_array, $spn_array);
2695 sub setup_ad_dc_no_nss
2697 my ($self, $path) = @_;
2699 # If we didn't build with ADS, pretend this env was never available
2700 if (not $self->{target3}->have_ads()) {
2704 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2705 "adnonssdom.samba.example.com", "", undef);
2710 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2711 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2713 if (not defined($self->check_or_start($env, "single"))) {
2717 my $upn_array = ["$env->{REALM}.upn"];
2718 my $spn_array = ["$env->{REALM}.spn"];
2720 $self->setup_namespaces($env, $upn_array, $spn_array);
2725 sub setup_ad_dc_no_ntlm
2727 my ($self, $path) = @_;
2729 # If we didn't build with ADS, pretend this env was never available
2730 if (not $self->{target3}->have_ads()) {
2734 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2735 "adnontlmdom.samba.example.com",
2736 "ntlm auth = disabled", undef);
2741 if (not defined($self->check_or_start($env, "prefork"))) {
2745 my $upn_array = ["$env->{REALM}.upn"];
2746 my $spn_array = ["$env->{REALM}.spn"];
2748 $self->setup_namespaces($env, $upn_array, $spn_array);
2754 # AD DC test environment used solely to test pre-fork process restarts.
2755 # As processes get killed off and restarted it should not be used for other
2756 sub setup_preforkrestartdc
2758 my ($self, $path) = @_;
2760 # If we didn't build with ADS, pretend this env was never available
2761 if (not $self->{target3}->have_ads()) {
2765 # note DC name must be <= 15 chars so we use 'prockill' instead of
2767 my $env = $self->provision_ad_dc(
2771 "prockilldom.samba.example.com",
2772 "prefork backoff increment = 5\nprefork maximum backoff=10");
2777 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2778 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2780 if (not defined($self->check_or_start($env, "prefork"))) {
2784 my $upn_array = ["$env->{REALM}.upn"];
2785 my $spn_array = ["$env->{REALM}.spn"];
2787 $self->setup_namespaces($env, $upn_array, $spn_array);
2793 # ad_dc test environment used solely to test standard process model connection
2794 # process limits. As the limit is set artificially low it should not be used
2796 sub setup_proclimitdc
2798 my ($self, $path) = @_;
2800 # If we didn't build with ADS, pretend this env was never available
2801 if (not $self->{target3}->have_ads()) {
2805 my $env = $self->provision_ad_dc(
2809 "proclimit.samba.example.com",
2810 "max smbd processes = 20");
2815 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2816 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2818 if (not defined($self->check_or_start($env, "standard"))) {
2822 my $upn_array = ["$env->{REALM}.upn"];
2823 my $spn_array = ["$env->{REALM}.spn"];
2825 $self->setup_namespaces($env, $upn_array, $spn_array);
2830 # Sets up a DC that's solely used to do a domain backup from. We then use the
2831 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2832 # process will create a Samba DC that will actually start up.
2833 # We don't use the backup-DC for anything else because its domain will conflict
2834 # with the restore DC.
2835 sub setup_backupfromdc
2837 my ($self, $path) = @_;
2839 # If we didn't build with ADS, pretend this env was never available
2840 if (not $self->{target3}->have_ads()) {
2844 my $provision_args = ["--site=Backup-Site"];
2846 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2847 "backupdom.samba.example.com",
2848 "samba kcc command = /bin/true",
2854 if (not defined($self->check_or_start($env))) {
2858 my $upn_array = ["$env->{REALM}.upn"];
2859 my $spn_array = ["$env->{REALM}.spn"];
2861 $self->setup_namespaces($env, $upn_array, $spn_array);
2866 # returns the server/user-auth params needed to run an online backup cmd
2867 sub get_backup_server_args
2869 # dcvars contains the env info for the backup DC testenv
2870 my ($self, $dcvars) = @_;
2871 my $server = $dcvars->{DC_SERVER_IP};
2872 my $server_args = "--server=$server ";
2873 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2874 $server_args .= " $dcvars->{CONFIGURATION}";
2876 return $server_args;
2879 # Creates a backup of a running testenv DC
2882 # note: dcvars contains the env info for the backup DC testenv
2883 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2885 # get all the env variables we pass in with the samba-tool command
2886 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2887 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2888 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2889 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2891 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2893 # Note: use the backupfrom-DC's krb5.conf to do the backup
2894 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2895 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2897 # use samba-tool to create a backup from the 'backupfromdc' DC
2899 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2901 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2902 $cmd .= " --targetdir=$backupdir";
2904 print "Executing: $cmd\n";
2905 unless(system($cmd) == 0) {
2906 warn("Failed to create backup using: \n$cmd");
2910 # get the name of the backup file created
2911 opendir(DIR, $backupdir);
2912 my @files = grep(/\.tar/, readdir(DIR));
2915 if(scalar @files != 1) {
2916 warn("Backup file not found in directory $backupdir\n");
2919 my $backup_file = "$backupdir/$files[0]";
2920 print "Using backup file $backup_file...\n";
2922 return $backup_file;
2925 # Restores a backup-file to populate a testenv for a new DC
2926 sub restore_backup_file
2928 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2930 # pass the restore command the testenv's smb.conf that we've already
2931 # generated. But move it to a temp-dir first, so that the restore doesn't
2933 my $tmpdir = File::Temp->newdir();
2934 my $tmpconf = "$tmpdir/smb.conf";
2935 my $cmd = "cp $smbconf $tmpconf";
2936 unless(system($cmd) == 0) {
2937 warn("Failed to backup smb.conf using: \n$cmd");
2941 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2942 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2943 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2945 print "Executing: $cmd\n";
2946 unless(system($cmd) == 0) {
2947 warn("Failed to restore backup using: \n$cmd");
2951 print "Restore complete\n";
2955 # sets up the initial directory and returns the new testenv's env info
2956 # (without actually doing a 'domain join')
2957 sub prepare_dc_testenv
2959 my ($self, $prefix, $dcname, $domain, $realm,
2960 $password, $conf_options) = @_;
2962 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2972 # the restore uses a slightly different state-dir location to other testenvs
2973 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2974 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2976 # add support for sysvol/netlogon/tmp shares
2977 $ctx->{share} = "$ctx->{prefix_abs}/share";
2978 push(@{$ctx->{directories}}, "$ctx->{share}");
2979 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2981 $ctx->{smb_conf_extra_options} = "
2984 server max protocol = SMB2
2985 samba kcc command = /bin/true
2986 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2989 path = $ctx->{statedir}/sysvol
2993 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2997 path = $ctx->{share}
2999 posix:sharedelay = 10000
3000 posix:oplocktimeout = 3
3001 posix:writetimeupdatedelay = 50000
3004 path = $ctx->{share}/test1
3006 posix:sharedelay = 100000
3007 posix:oplocktimeout = 3
3008 posix:writetimeupdatedelay = 500000
3011 my $env = $self->provision_raw_step1($ctx);
3013 $env->{DC_SERVER} = $env->{SERVER};
3014 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
3015 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
3016 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
3017 $env->{DC_USERNAME} = $env->{USERNAME};
3018 $env->{DC_PASSWORD} = $env->{PASSWORD};
3020 return ($env, $ctx);
3024 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3025 # commands. This proves that we can backup an online DC ('backupfromdc') and
3026 # use the backup file to create a valid, working samba DC.
3029 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3030 my ($self, $prefix, $dcvars) = @_;
3031 print "Preparing RESTORE DC...\n";
3033 # we arbitrarily designate the restored DC as having SMBv1 disabled
3035 server min protocol = SMB2
3036 client min protocol = SMB2
3037 prefork children = 1";
3039 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3042 $dcvars->{PASSWORD},
3045 # create a backup of the 'backupfromdc'
3046 my $backupdir = File::Temp->newdir();
3047 my $server_args = $self->get_backup_server_args($dcvars);
3048 my $backup_args = "online $server_args";
3049 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3051 unless($backup_file) {
3055 # restore the backup file to populate the restore-DC testenv
3056 my $restore_dir = abs_path($prefix);
3057 my $ret = $self->restore_backup_file($backup_file,
3058 "--newservername=$env->{SERVER}",
3059 $restore_dir, $env->{SERVERCONFFILE});
3060 unless ($ret == 0) {
3064 # start samba for the restored DC
3065 if (not defined($self->check_or_start($env))) {
3072 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3073 # restore commands. This proves that we can backup and rename an online DC
3074 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3077 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3078 my ($self, $prefix, $dcvars) = @_;
3079 print "Preparing RENAME DC...\n";
3080 my $extra_conf = "prefork children = 1";
3082 my $realm = "renamedom.samba.example.com";
3083 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3084 "RENAMEDOMAIN", $realm,
3085 $dcvars->{PASSWORD}, $extra_conf);
3087 # create a backup of the 'backupfromdc' which renames the domain
3088 my $backupdir = File::Temp->newdir();
3089 my $server_args = $self->get_backup_server_args($dcvars);
3090 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3091 $backup_args .= " --backend-store=tdb";
3092 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3094 unless($backup_file) {
3098 # restore the backup file to populate the rename-DC testenv
3099 my $restore_dir = abs_path($prefix);
3100 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3101 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3102 $restore_dir, $env->{SERVERCONFFILE});
3103 unless ($ret == 0) {
3107 # start samba for the restored DC
3108 if (not defined($self->check_or_start($env))) {
3112 my $upn_array = ["$env->{REALM}.upn"];
3113 my $spn_array = ["$env->{REALM}.spn"];
3115 $self->setup_namespaces($env, $upn_array, $spn_array);
3120 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3121 # restore commands. This proves that we do an offline backup of a local DC
3122 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3123 sub setup_offlinebackupdc
3125 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3126 my ($self, $prefix, $dcvars) = @_;
3127 print "Preparing OFFLINE BACKUP DC...\n";
3128 my $extra_conf = "prefork children = 1";
3130 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3133 $dcvars->{PASSWORD}, $extra_conf);
3135 # create an offline backup of the 'backupfromdc' target
3136 my $backupdir = File::Temp->newdir();
3137 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3138 my $backup_file = $self->create_backup($env, $dcvars,
3141 unless($backup_file) {
3145 # restore the backup file to populate the rename-DC testenv
3146 my $restore_dir = abs_path($prefix);
3147 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3148 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3149 $restore_dir, $env->{SERVERCONFFILE});
3150 unless ($ret == 0) {
3154 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3155 Samba::mk_krb5_conf($ctx);
3157 # start samba for the restored DC
3158 if (not defined($self->check_or_start($env))) {
3165 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3166 # restore commands, using the --no-secrets option. This proves that we can
3167 # create a realistic lab environment from an online DC ('backupfromdc').
3170 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3171 my ($self, $prefix, $dcvars) = @_;
3172 print "Preparing LAB-DOMAIN DC...\n";
3173 my $extra_conf = "prefork children = 1";
3175 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3177 "labdom.samba.example.com",
3178 $dcvars->{PASSWORD}, $extra_conf);
3180 # create a backup of the 'backupfromdc' which renames the domain and uses
3181 # the --no-secrets option to scrub any sensitive info
3182 my $backupdir = File::Temp->newdir();
3183 my $server_args = $self->get_backup_server_args($dcvars);
3184 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3185 $backup_args .= " --no-secrets --backend-store=mdb";
3186 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3188 unless($backup_file) {
3192 # restore the backup file to populate the lab-DC testenv
3193 my $restore_dir = abs_path($prefix);
3194 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3195 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3196 $restore_dir, $env->{SERVERCONFFILE});
3197 unless ($ret == 0) {
3201 # because we don't include any secrets in the backup, we need to reset the
3202 # admin user's password back to what the testenv expects
3203 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3204 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3205 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3206 $cmd .= " $env->{CONFIGURATION}";
3208 unless(system($cmd) == 0) {
3209 warn("Failed to reset admin's password: \n$cmd");
3213 # start samba for the restored DC
3214 if (not defined($self->check_or_start($env))) {
3218 my $upn_array = ["$env->{REALM}.upn"];
3219 my $spn_array = ["$env->{REALM}.spn"];
3221 $self->setup_namespaces($env, $upn_array, $spn_array);
3226 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3227 sub get_backup_domain_realm
3229 my ($self, $backup_file) = @_;
3231 print "Determining REALM/DOMAIN values in backup...\n";
3233 # The backup will have the correct domain/realm values in the smb.conf.
3234 # So we can work out the env variables the testenv should use based on
3235 # that. Let's start by extracting the smb.conf
3236 my $tar = Archive::Tar->new($backup_file);
3237 my $tmpdir = File::Temp->newdir();
3238 my $smbconf = "$tmpdir/smb.conf";
3240 # note that the filepaths within the tar-file differ slightly for online
3241 # and offline backups
3242 if ($tar->contains_file("etc/smb.conf")) {
3243 $tar->extract_file("etc/smb.conf", $smbconf);
3244 } elsif ($tar->contains_file("./etc/smb.conf")) {
3245 $tar->extract_file("./etc/smb.conf", $smbconf);
3247 warn("Could not find smb.conf in $backup_file");
3248 return undef, undef;
3251 # now use testparm to read the values we're interested in
3252 my $testparm = Samba::bindir_path($self, "testparm");
3253 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3254 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3257 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3259 return ($domain, $realm);
3262 # This spins up a custom testenv that can be based on any backup-file you want.
3263 # This is just intended for manual testing (rather than automated test-cases)
3266 my ($self, $prefix) = @_;
3267 print "Preparing CUSTOM RESTORE DC...\n";
3268 my $dc_name = "customdc";
3269 my $password = "locDCpass1";
3270 my $backup_file = $ENV{'BACKUP_FILE'};
3272 # user must specify a backup file to restore via an ENV variable, i.e.
3273 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3274 if (not defined($backup_file)) {
3275 warn("Please specify BACKUP_FILE");
3279 # work out the correct domain/realm env values from the backup-file
3280 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3282 # create a placeholder directory and smb.conf, as well as the env vars.
3283 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3284 $domain, $realm, $password, "");
3286 # restore the specified backup file to populate the testenv
3287 my $restore_dir = abs_path($prefix);
3288 my $ret = $self->restore_backup_file($backup_file,
3289 "--newservername=$env->{SERVER}",
3290 $restore_dir, $env->{SERVERCONFFILE});
3291 unless ($ret == 0) {
3295 # Change the admin password to the testenv default, just in case it's
3296 # different, or in case this was a --no-secrets backup
3297 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3298 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3299 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3300 $cmd .= " $env->{CONFIGURATION}";
3302 unless(system($cmd) == 0) {
3303 warn("Failed to reset admin's password: \n$cmd");
3307 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3308 # if the backup-file was an offline backup)
3309 Samba::mk_krb5_conf($ctx);
3311 # start samba for the restored DC
3312 if (not defined($self->check_or_start($env))) {
3316 # if this was a backup-rename, then we may need to setup namespaces
3317 my $upn_array = ["$env->{REALM}.upn"];
3318 my $spn_array = ["$env->{REALM}.spn"];
3320 $self->setup_namespaces($env, $upn_array, $spn_array);
3327 my ($self, $path) = @_;
3330 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",