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 close($env_vars->{STDIN_PIPE});
165 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
167 exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--no-process-group", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
169 $env_vars->{SAMBA_PID} = $pid;
170 print "DONE ($pid)\n";
172 close($STDIN_READER);
174 if ($self->wait_for_start($env_vars) != 0) {
175 warn("Samba $pid failed to start up");
182 sub wait_for_start($$)
184 my ($self, $testenv_vars) = @_;
188 if (not $self->check_env($testenv_vars)) {
189 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
193 # This will return quickly when things are up, but be slow if we
194 # need to wait for (eg) SSL init
195 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
198 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
204 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
207 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
208 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
209 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
210 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
211 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
212 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
215 } while ($ret != 0 && $count < 20);
217 warn("nbt not reachable after 20 retries\n");
218 teardown_env($self, $testenv_vars);
222 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
223 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
224 print "waiting for working LDAP and a RID Set to be allocated\n";
225 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
227 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
229 my $search_dn = $base_dn;
230 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
231 # TODO currently no check for actual rIDAllocationPool
232 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
236 # Add hosts file for name lookups
237 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
238 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
239 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
241 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
243 $cmd .= "RESOLV_CONF='$testenv_vars->{RESOLV_CONF}' ";
245 $cmd .= "$ldbsearch ";
246 $cmd .= "$testenv_vars->{CONFIGURATION} ";
247 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
248 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
250 $cmd .= "-b '$search_dn' ";
251 while (system("$cmd >/dev/null") != 0) {
253 if ($count > $max_wait) {
254 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}");
262 my $wbinfo = Samba::bindir_path($self, "wbinfo");
266 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
267 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
268 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
269 $cmd .= "$wbinfo -P";
276 } while ($ret != 0 && $count < 20);
278 warn("winbind not reachable after 20 retries\n");
279 teardown_env($self, $testenv_vars);
283 print $self->getlog_env($testenv_vars);
288 sub write_ldb_file($$$)
290 my ($self, $file, $ldif) = @_;
292 my $ldbadd = Samba::bindir_path($self, "ldbadd");
293 open(LDIF, "|$ldbadd -H $file >/dev/null");
298 sub add_wins_config($$)
300 my ($self, $privatedir) = @_;
302 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
303 dn: name=TORTURE_11,CN=PARTNERS
304 objectClass: wreplPartner
315 my ($self, $ctx) = @_;
317 #Make the subdirectory be as fedora DS would expect
318 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
320 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
322 return ($fedora_ds_dir, $pidfile);
327 my ($self, $ctx) = @_;
329 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
330 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
332 return ($slapd_conf_d, $pidfile);
335 sub setup_dns_hub_internal($$$)
337 my ($self, $hostname, $prefix) = @_;
340 unless(-d $prefix or make_path($prefix, 0777)) {
341 warn("Unable to create $prefix");
344 my $prefix_abs = abs_path($prefix);
346 die ("prefix=''") if $prefix_abs eq "";
347 die ("prefix='/'") if $prefix_abs eq "/";
349 unless (system("rm -rf $prefix_abs/*") == 0) {
350 warn("Unable to clean up");
353 my $swiface = Samba::get_interface($hostname);
356 $env->{prefix} = $prefix;
357 $env->{prefix_abs} = $prefix_abs;
359 $env->{hostname} = $hostname;
360 $env->{swiface} = $swiface;
362 $env->{ipv4} = "127.0.0.$swiface";
363 $env->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
365 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
367 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
369 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
370 print RESOLV_CONF "nameserver $env->{ipv4}\n";
371 print RESOLV_CONF "nameserver $env->{ipv6}\n";
374 # use a pipe for stdin in the child processes. This allows
375 # those processes to monitor the pipe for EOF to ensure they
376 # exit when the test script exits
377 pipe($STDIN_READER, $env->{STDIN_PIPE});
379 print "STARTING rootdnsforwarder...\n";
382 # we want out from samba to go to the log file, but also
383 # to the users terminal when running 'make test' on the command
384 # line. This puts it on stderr on the terminal
385 open STDOUT, "| tee $env->{DNS_HUB_LOG} 1>&2";
386 open STDERR, '>&STDOUT';
388 SocketWrapper::set_default_iface($swiface);
389 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap";
390 SocketWrapper::setup_pcap($pcap_file);
395 if (!defined($ENV{PYTHON})) {
396 push (@preargs, "env");
397 push (@preargs, "python");
399 push (@preargs, $ENV{PYTHON});
401 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "python/samba/tests/dns_forwarder_helpers/dns_hub.py");
402 push (@args, "$self->{server_maxtime}");
403 push (@args, "$env->{ipv4}");
404 close($env->{STDIN_PIPE});
405 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
407 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
408 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
410 $env->{SAMBA_PID} = $pid;
411 $env->{KRB5_CONFIG} = "${prefix_abs}/no_krb5.conf";
412 close($STDIN_READER);
420 my ($self, $prefix) = @_;
422 my $hostname = "rootdnsforwarder";
424 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
426 $self->{dns_hub_env} = $env;
431 sub get_dns_hub_env($)
433 my ($self, $prefix) = @_;
435 if (defined($self->{dns_hub_env})) {
436 return $self->{dns_hub_env};
439 die("get_dns_hub_env() not setup 'dns_hub_env'");
443 sub setup_namespaces($$:$$)
445 my ($self, $localenv, $upn_array, $spn_array) = @_;
447 @{$upn_array} = [] unless defined($upn_array);
449 foreach my $upn (@{$upn_array}) {
450 $upn_args .= " --add-upn-suffix=$upn";
453 @{$spn_array} = [] unless defined($spn_array);
455 foreach my $spn (@{$spn_array}) {
456 $spn_args .= " --add-spn-suffix=$spn";
459 my $samba_tool = Samba::bindir_path($self, "samba-tool");
461 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
462 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
463 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
464 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
466 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
468 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
469 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
470 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
472 my $cmd_config = " $localenv->{CONFIGURATION}";
474 my $namespaces = $cmd_env;
475 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
476 $namespaces .= $cmd_config;
477 unless (system($namespaces) == 0) {
478 warn("Failed to add namespaces \n$namespaces");
485 sub setup_trust($$$$$)
487 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
489 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
490 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
491 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
492 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
493 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
494 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
495 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
496 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
497 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
499 my $samba_tool = Samba::bindir_path($self, "samba-tool");
502 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
503 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
504 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
505 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
507 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
509 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
510 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
511 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
513 my $cmd_config = " $localenv->{CONFIGURATION}";
514 my $cmd_creds = $cmd_config;
515 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
517 my $create = $cmd_env;
518 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
519 $create .= " $extra_args";
520 $create .= $cmd_creds;
521 unless (system($create) == 0) {
522 warn("Failed to create trust \n$create");
526 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
527 my $groupadd = $cmd_env;
528 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
529 unless (system($groupadd) == 0) {
530 warn("Failed to create group \n$groupadd");
533 my $groupmem = $cmd_env;
534 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
535 unless (system($groupmem) == 0) {
536 warn("Failed to add group member \n$groupmem");
543 sub provision_raw_prepare($$$$$$$$$$$$)
545 my ($self, $prefix, $server_role, $hostname,
546 $domain, $realm, $samsid, $functional_level,
547 $password, $kdc_ipv4, $kdc_ipv6) = @_;
550 if (defined $ENV{PYTHON}) {
551 $python_cmd = $ENV{PYTHON} . " ";
553 $ctx->{python} = $python_cmd;
554 my $netbiosname = uc($hostname);
556 unless(-d $prefix or mkdir($prefix, 0777)) {
557 warn("Unable to create $prefix");
560 my $prefix_abs = abs_path($prefix);
562 die ("prefix=''") if $prefix_abs eq "";
563 die ("prefix='/'") if $prefix_abs eq "/";
565 unless (system("rm -rf $prefix_abs/*") == 0) {
566 warn("Unable to clean up");
570 my $swiface = Samba::get_interface($hostname);
572 $ctx->{prefix} = $prefix;
573 $ctx->{prefix_abs} = $prefix_abs;
575 $ctx->{server_role} = $server_role;
576 $ctx->{hostname} = $hostname;
577 $ctx->{netbiosname} = $netbiosname;
578 $ctx->{swiface} = $swiface;
579 $ctx->{password} = $password;
580 $ctx->{kdc_ipv4} = $kdc_ipv4;
581 $ctx->{kdc_ipv6} = $kdc_ipv6;
582 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
583 if ($functional_level eq "2000") {
584 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
588 # Set smbd log level here.
590 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
591 $ctx->{username} = "Administrator";
592 $ctx->{domain} = $domain;
593 $ctx->{realm} = uc($realm);
594 $ctx->{dnsname} = lc($realm);
595 $ctx->{samsid} = $samsid;
597 $ctx->{functional_level} = $functional_level;
599 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
601 $ctx->{unix_name} = $unix_name;
602 $ctx->{unix_uid} = $>;
603 my @mygid = split(" ", $();
604 $ctx->{unix_gid} = $mygid[0];
605 $ctx->{unix_gids_str} = $);
606 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
608 $ctx->{etcdir} = "$prefix_abs/etc";
609 $ctx->{piddir} = "$prefix_abs/pid";
610 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
611 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
612 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
613 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
614 $ctx->{privatedir} = "$prefix_abs/private";
615 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
616 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
617 $ctx->{lockdir} = "$prefix_abs/lockdir";
618 $ctx->{logdir} = "$prefix_abs/logs";
619 $ctx->{statedir} = "$prefix_abs/statedir";
620 $ctx->{cachedir} = "$prefix_abs/cachedir";
621 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
622 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
623 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
624 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
625 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
626 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
627 if ($ENV{SAMBA_DNS_FAKING}) {
628 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
629 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
630 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
632 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
633 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
634 $ctx->{use_resolv_wrapper} = 1;
637 my $dns_hub = $self->get_dns_hub_env();
638 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
640 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
642 $ctx->{ipv4} = "127.0.0.$swiface";
643 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
644 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
646 push(@{$ctx->{directories}}, $ctx->{privatedir});
647 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
648 push(@{$ctx->{directories}}, $ctx->{etcdir});
649 push(@{$ctx->{directories}}, $ctx->{piddir});
650 push(@{$ctx->{directories}}, $ctx->{lockdir});
651 push(@{$ctx->{directories}}, $ctx->{logdir});
652 push(@{$ctx->{directories}}, $ctx->{statedir});
653 push(@{$ctx->{directories}}, $ctx->{cachedir});
655 $ctx->{smb_conf_extra_options} = "";
657 my @provision_options = ();
658 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
659 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
660 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
661 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
662 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
663 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
664 if (defined($ctx->{use_resolv_wrapper})) {
665 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
666 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
668 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
670 if (defined($ENV{GDB_PROVISION})) {
671 push (@provision_options, "gdb --args");
672 if (!defined($ENV{PYTHON})) {
673 push (@provision_options, "env");
674 push (@provision_options, "python");
677 if (defined($ENV{VALGRIND_PROVISION})) {
678 push (@provision_options, "valgrind");
679 if (!defined($ENV{PYTHON})) {
680 push (@provision_options, "env");
681 push (@provision_options, "python");
685 my $samba_tool = Samba::bindir_path($self, "samba-tool");
687 push (@provision_options, $samba_tool);
688 push (@provision_options, "domain");
689 push (@provision_options, "provision");
690 push (@provision_options, "--configfile=$ctx->{smb_conf}");
691 push (@provision_options, "--host-name=$ctx->{hostname}");
692 push (@provision_options, "--host-ip=$ctx->{ipv4}");
693 push (@provision_options, "--quiet");
694 push (@provision_options, "--domain=$ctx->{domain}");
695 push (@provision_options, "--realm=$ctx->{realm}");
696 if (defined($ctx->{samsid})) {
697 push (@provision_options, "--domain-sid=$ctx->{samsid}");
699 push (@provision_options, "--adminpass=$ctx->{password}");
700 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
701 push (@provision_options, "--machinepass=machine$ctx->{password}");
702 push (@provision_options, "--root=$ctx->{unix_name}");
703 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
704 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
706 @{$ctx->{provision_options}} = @provision_options;
713 my ($self, $keyword, @options_list) = @_;
715 # convert the options-list to a hash-map for easy keyword lookup
716 my %options_dict = map { $_ => 1 } @options_list;
718 return exists $options_dict{$keyword};
722 # Step1 creates the basic configuration
724 sub provision_raw_step1($$)
726 my ($self, $ctx) = @_;
728 mkdir($_, 0777) foreach (@{$ctx->{directories}});
731 ## lockdir and piddir must be 0755
733 chmod 0755, $ctx->{lockdir};
734 chmod 0755, $ctx->{piddir};
736 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
737 warn("can't open $ctx->{smb_conf}$?");
741 Samba::prepare_keyblobs($ctx);
742 my $crlfile = "$ctx->{tlsdir}/crl.pem";
743 $crlfile = "" unless -e ${crlfile};
745 # work out which file server to use. Default to source3 smbd (s3fs),
746 # unless the source4 NTVFS (smb) file server has been specified
747 my $services = "-smb +s3fs";
748 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
749 $services = "+smb -s3fs";
754 netbios name = $ctx->{netbiosname}
755 posix:eadb = $ctx->{statedir}/eadb.tdb
756 workgroup = $ctx->{domain}
757 realm = $ctx->{realm}
758 private dir = $ctx->{privatedir}
759 binddns dir = $ctx->{binddnsdir}
760 pid directory = $ctx->{piddir}
761 ncalrpc dir = $ctx->{ncalrpcdir}
762 lock dir = $ctx->{lockdir}
763 state directory = $ctx->{statedir}
764 cache directory = $ctx->{cachedir}
765 winbindd socket directory = $ctx->{winbindd_socket_dir}
766 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
767 winbind separator = /
768 interfaces = $ctx->{interfaces}
769 tls dh params file = $ctx->{tlsdir}/dhparms.pem
770 tls crlfile = ${crlfile}
771 tls verify peer = no_check
772 panic action = $RealBin/gdb_backtrace \%d
774 server role = $ctx->{server_role}
775 server services = +echo $services
776 dcerpc endpoint servers = +winreg +srvsvc
777 notify:inotify = false
779 ldap server require strong auth = yes
780 #We don't want to pass our self-tests if the PAC code is wrong
781 gensec:require_pac = true
782 log file = $ctx->{logdir}/log.\%m
783 log level = $ctx->{server_loglevel}
787 dns update command = $ctx->{samba_dnsupdate}
788 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
789 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
790 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
791 dreplsrv:periodic_startup_interval = 0
792 dsdb:schema update allowed = yes
796 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
798 idmap_ldb:use rfc2307=yes
799 winbind enum users = yes
800 winbind enum groups = yes
802 rpc server port:netlogon = 1026
808 # Begin extra options
809 $ctx->{smb_conf_extra_options}
814 #Default the KDC IP to the server's IP
815 if (not defined($ctx->{kdc_ipv4})) {
816 $ctx->{kdc_ipv4} = $ctx->{ipv4};
818 if (not defined($ctx->{kdc_ipv6})) {
819 $ctx->{kdc_ipv6} = $ctx->{ipv6};
822 Samba::mk_krb5_conf($ctx);
823 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
825 open(PWD, ">$ctx->{nsswrap_passwd}");
826 if ($ctx->{unix_uid} != 0) {
827 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
829 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
830 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
831 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
832 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
833 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
834 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
837 my $uid_rfc2307test = 65533;
839 open(GRP, ">$ctx->{nsswrap_group}");
840 if ($ctx->{unix_gid} != 0) {
841 print GRP "root:x:0:\n";
843 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
844 print GRP "wheel:x:10:
847 nogroup:x:65534:nobody
850 my $gid_rfc2307test = 65532;
852 my $hostname = lc($ctx->{hostname});
853 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
854 if ($hostname eq "localdc") {
855 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
856 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
858 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
859 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
863 my $configuration = "--configfile=$ctx->{smb_conf}";
865 #Ensure the config file is valid before we start
866 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
867 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
868 system("$testparm -v --suppress-prompt $configuration >&2");
869 warn("Failed to create a valid smb.conf configuration $testparm!");
872 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) {
873 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
878 KRB5_CONFIG => $ctx->{krb5_conf},
879 KRB5_CCACHE => $ctx->{krb5_ccache},
880 MITKDC_CONFIG => $ctx->{mitkdc_conf},
881 PIDDIR => $ctx->{piddir},
882 SERVER => $ctx->{hostname},
883 SERVER_IP => $ctx->{ipv4},
884 SERVER_IPV6 => $ctx->{ipv6},
885 NETBIOSNAME => $ctx->{netbiosname},
886 DOMAIN => $ctx->{domain},
887 USERNAME => $ctx->{username},
888 REALM => $ctx->{realm},
889 DNSNAME => $ctx->{dnsname},
890 SAMSID => $ctx->{samsid},
891 PASSWORD => $ctx->{password},
892 LDAPDIR => $ctx->{ldapdir},
893 LDAP_INSTANCE => $ctx->{ldap_instance},
894 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
895 NCALRPCDIR => $ctx->{ncalrpcdir},
896 LOCKDIR => $ctx->{lockdir},
897 STATEDIR => $ctx->{statedir},
898 CACHEDIR => $ctx->{cachedir},
899 PRIVATEDIR => $ctx->{privatedir},
900 BINDDNSDIR => $ctx->{binddnsdir},
901 SERVERCONFFILE => $ctx->{smb_conf},
902 CONFIGURATION => $configuration,
903 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
904 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
905 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
906 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
907 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
908 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
909 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
910 SAMBA_TEST_LOG_POS => 0,
911 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
912 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
913 LOCAL_PATH => $ctx->{share},
914 UID_RFC2307TEST => $uid_rfc2307test,
915 GID_RFC2307TEST => $gid_rfc2307test,
916 SERVER_ROLE => $ctx->{server_role},
917 RESOLV_CONF => $ctx->{resolv_conf}
920 if (defined($ctx->{use_resolv_wrapper})) {
921 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
923 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
926 if ($ctx->{server_role} eq "domain controller") {
927 $ret->{DOMSID} = $ret->{SAMSID};
934 # Step2 runs the provision script
936 sub provision_raw_step2($$$)
938 my ($self, $ctx, $ret) = @_;
940 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
941 unless (system($provision_cmd) == 0) {
942 warn("Unable to provision: \n$provision_cmd\n");
946 my $testallowed_account = "testallowed";
947 my $samba_tool_cmd = "";
948 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
949 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
950 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
951 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
952 unless (system($samba_tool_cmd) == 0) {
953 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
958 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
959 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
960 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
961 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
963 if ($ctx->{server_role} ne "domain controller") {
964 $base_dn = "DC=$ctx->{netbiosname}";
967 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
968 $testallowed_account = "testallowed account";
969 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
970 print LDIF "dn: $user_dn
972 replace: samAccountName
973 samAccountName: $testallowed_account
978 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
979 print LDIF "dn: $user_dn
981 replace: userPrincipalName
982 userPrincipalName: testallowed upn\@$ctx->{realm}
983 replace: servicePrincipalName
984 servicePrincipalName: host/testallowed
989 $samba_tool_cmd = "";
990 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
991 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
992 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
993 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
994 unless (system($samba_tool_cmd) == 0) {
995 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
999 my $user_dn = "cn=testdenied,cn=users,$base_dn";
1000 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1001 print LDIF "dn: $user_dn
1003 replace: userPrincipalName
1004 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1009 $samba_tool_cmd = "";
1010 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1011 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1012 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1013 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1014 unless (system($samba_tool_cmd) == 0) {
1015 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1019 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
1020 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1021 print LDIF "dn: $user_dn
1023 replace: userPrincipalName
1024 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1025 replace: servicePrincipalName
1026 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1031 $samba_tool_cmd = "";
1032 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1033 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1034 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1035 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1036 unless (system($samba_tool_cmd) == 0) {
1037 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1041 # Create to users alice and bob!
1042 my $user_account_array = ["alice", "bob", "jane"];
1044 foreach my $user_account (@{$user_account_array}) {
1045 my $samba_tool_cmd = "";
1047 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1048 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1049 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1050 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1051 unless (system($samba_tool_cmd) == 0) {
1052 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1058 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1059 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1060 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1062 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1063 my $user_dn = "cn=jane,cn=users,$base_dn";
1065 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1066 print LDIF "dn: $user_dn
1068 replace: userPrincipalName
1069 userPrincipalName: jane.doe\@$ctx->{realm}
1077 sub provision($$$$$$$$$$)
1079 my ($self, $prefix, $server_role, $hostname,
1080 $domain, $realm, $functional_level,
1081 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1082 $extra_provision_options) = @_;
1084 my $samsid = Samba::random_domain_sid();
1086 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1091 $password, $kdc_ipv4, $kdc_ipv6);
1093 if (defined($extra_provision_options)) {
1094 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1097 $ctx->{share} = "$ctx->{prefix_abs}/share";
1098 push(@{$ctx->{directories}}, "$ctx->{share}");
1099 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1100 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1102 # precreate directories for printer drivers
1103 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1104 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1105 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1108 $msdfs = "yes" if ($server_role eq "domain controller");
1109 $ctx->{smb_conf_extra_options} = "
1112 server max protocol = SMB2
1116 # fruit:copyfile is a global option
1117 fruit:copyfile = yes
1119 $extra_smbconf_options
1122 path = $ctx->{share}
1124 posix:sharedelay = 100000
1125 posix:oplocktimeout = 3
1126 posix:writetimeupdatedelay = 500000
1129 path = $ctx->{share}
1131 posix:sharedelay = 100000
1132 posix:oplocktimeout = 3
1133 posix:writetimeupdatedelay = 500000
1135 force create mode = 777
1138 path = $ctx->{share}
1141 force create mode = 0
1142 directory mask = 0777
1143 force directory mode = 0
1146 path = $ctx->{share}/test1
1148 posix:sharedelay = 100000
1149 posix:oplocktimeout = 3
1150 posix:writetimeupdatedelay = 500000
1153 path = $ctx->{share}/test2
1155 posix:sharedelay = 100000
1156 posix:oplocktimeout = 3
1157 posix:writetimeupdatedelay = 500000
1160 path = $ctx->{share}/_ignore_cifs_
1162 ntvfs handler = cifs
1163 cifs:server = $ctx->{netbiosname}
1165 cifs:use-s4u2proxy = yes
1166 # There is no username specified here, instead the client is expected
1167 # to log in with kerberos, and the serverwill use delegated credentials.
1168 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1171 path = $ctx->{share}
1173 ntvfs handler = simple
1176 path = $ctx->{statedir}/sysvol
1180 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1185 ntvfs handler = cifsposix
1188 path = $ctx->{share}
1189 vfs objects = catia fruit streams_xattr acl_xattr
1191 fruit:resource = file
1192 fruit:metadata = netatalk
1193 fruit:locking = netatalk
1194 fruit:encoding = native
1196 $extra_smbconf_shares
1199 if (defined($self->{ldap})) {
1200 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1201 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1203 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1204 $ldap_uri =~ s|/|%2F|g;
1205 $ldap_uri = "ldapi://$ldap_uri";
1206 $ctx->{ldap_uri} = $ldap_uri;
1208 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1211 my $ret = $self->provision_raw_step1($ctx);
1212 unless (defined $ret) {
1216 if (defined($self->{ldap})) {
1217 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1218 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1219 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1220 if ($self->{ldap} eq "openldap") {
1221 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1222 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1224 } elsif ($self->{ldap} eq "fedora-ds") {
1225 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1226 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1227 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1232 return $self->provision_raw_step2($ctx, $ret);
1235 sub provision_s4member($$$$$)
1237 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1238 print "PROVISIONING MEMBER...\n";
1239 my $extra_smb_conf = "
1240 passdb backend = samba_dsdb
1241 winbindd:use external pipes = true
1243 # the source4 smb server doesn't allow signing by default
1244 server signing = enabled
1245 raw NTLMv2 auth = yes
1247 rpc_server:default = external
1248 rpc_server:svcctl = embedded
1249 rpc_server:srvsvc = embedded
1250 rpc_server:eventlog = embedded
1251 rpc_server:ntsvcs = embedded
1252 rpc_server:winreg = embedded
1253 rpc_server:spoolss = embedded
1254 rpc_daemon:spoolssd = embedded
1255 rpc_server:tcpip = no
1258 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1260 my $extra_provision_options = ["--use-ntvfs"];
1261 my $ret = $self->provision($prefix,
1268 $dcvars->{SERVER_IP},
1269 $dcvars->{SERVER_IPV6},
1270 $extra_smb_conf, "",
1271 $extra_provision_options);
1276 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1277 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1278 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1279 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1280 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1282 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1284 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1285 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1286 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1287 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1288 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1289 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1291 unless (system($cmd) == 0) {
1292 warn("Join failed\n$cmd");
1296 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1297 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1298 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1299 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1300 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1301 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1303 $ret->{DOMSID} = $dcvars->{DOMSID};
1304 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1305 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1306 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1307 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1308 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1309 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1314 sub provision_rpc_proxy($$$)
1316 my ($self, $prefix, $dcvars) = @_;
1317 print "PROVISIONING RPC PROXY...\n";
1319 my $extra_smbconf_options = "
1320 passdb backend = samba_dsdb
1323 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1324 dcerpc endpoint servers = epmapper, remote
1325 dcerpc_remote:interfaces = rpcecho
1326 dcerpc_remote:allow_anonymous_fallback = yes
1329 path = /tmp/_ignore_cifs_to_dc_/_none_
1331 ntvfs handler = cifs
1332 cifs:server = $dcvars->{SERVER}
1334 cifs:use-s4u2proxy = yes
1335 # There is no username specified here, instead the client is expected
1336 # to log in with kerberos, and the serverwill use delegated credentials.
1337 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1341 my $extra_provision_options = ["--use-ntvfs"];
1342 my $ret = $self->provision($prefix,
1349 $dcvars->{SERVER_IP},
1350 $dcvars->{SERVER_IPV6},
1351 $extra_smbconf_options, "",
1352 $extra_provision_options);
1357 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1359 # The joind runs in the context of the rpc_proxy/member for now
1360 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1361 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1362 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1363 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1365 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1367 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1368 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1369 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1370 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1371 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1372 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1374 unless (system($cmd) == 0) {
1375 warn("Join failed\n$cmd");
1379 # Setting up delegation runs in the context of the DC for now
1381 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1382 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1383 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1384 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1385 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1386 $cmd .= " $dcvars->{CONFIGURATION}";
1389 unless (system($cmd) == 0) {
1390 warn("Delegation failed\n$cmd");
1394 # Setting up delegation runs in the context of the DC for now
1396 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1397 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1398 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1399 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1400 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1401 $cmd .= " $dcvars->{CONFIGURATION}";
1403 unless (system($cmd) == 0) {
1404 warn("Delegation failed\n$cmd");
1408 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1409 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1410 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1411 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1412 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1413 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1415 $ret->{DOMSID} = $dcvars->{DOMSID};
1416 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1417 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1418 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1419 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1420 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1421 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1426 sub provision_promoted_dc($$$)
1428 my ($self, $prefix, $dcvars) = @_;
1429 print "PROVISIONING PROMOTED DC...\n";
1431 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1432 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1438 $dcvars->{PASSWORD},
1439 $dcvars->{SERVER_IP},
1440 $dcvars->{SERVER_IPV6});
1442 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1444 $ctx->{smb_conf_extra_options} = "
1446 server max protocol = SMB2
1448 ntlm auth = ntlmv2-only
1451 path = $ctx->{statedir}/sysvol
1455 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1460 my $ret = $self->provision_raw_step1($ctx);
1465 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1466 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1467 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1468 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1469 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1471 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1473 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1474 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1475 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1476 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1477 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1478 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1480 unless (system($cmd) == 0) {
1481 warn("Join failed\n$cmd");
1485 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1486 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1487 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1488 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1489 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1491 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1493 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1494 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1495 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1496 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1497 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1498 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1500 unless (system($cmd) == 0) {
1501 warn("Join failed\n$cmd");
1505 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1506 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1507 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1508 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1510 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1511 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1512 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1513 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1514 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1515 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1520 sub provision_vampire_dc($$$)
1522 my ($self, $prefix, $dcvars, $fl) = @_;
1523 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1524 my $name = "localvampiredc";
1525 my $extra_conf = "";
1527 if ($fl == "2000") {
1528 $name = "vampire2000dc";
1530 $extra_conf = "drs: immediate link sync = yes
1531 drs: max link sync = 250";
1534 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1535 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1541 $dcvars->{PASSWORD},
1542 $dcvars->{SERVER_IP},
1543 $dcvars->{SERVER_IPV6});
1545 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1547 $ctx->{smb_conf_extra_options} = "
1549 server max protocol = SMB2
1551 ntlm auth = mschapv2-and-ntlmv2-only
1555 path = $ctx->{statedir}/sysvol
1559 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1564 my $ret = $self->provision_raw_step1($ctx);
1569 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1570 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1571 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1572 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1573 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1575 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1577 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1578 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1579 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1580 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1581 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1582 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1583 $cmd .= " --backend-store=mdb";
1585 unless (system($cmd) == 0) {
1586 warn("Join failed\n$cmd");
1590 if ($fl == "2000") {
1591 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1592 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1593 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1594 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1596 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1597 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1598 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1599 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1601 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1602 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1603 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1604 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1605 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1606 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1607 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1612 sub provision_subdom_dc($$$)
1614 my ($self, $prefix, $dcvars) = @_;
1615 print "PROVISIONING SUBDOMAIN DC...\n";
1617 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1618 my $samsid = undef; # TODO pass the domain sid all the way down
1619 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1622 "sub.samba.example.com",
1625 $dcvars->{PASSWORD},
1628 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1630 $ctx->{smb_conf_extra_options} = "
1632 server max protocol = SMB2
1635 path = $ctx->{statedir}/sysvol
1639 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1644 my $ret = $self->provision_raw_step1($ctx);
1649 Samba::mk_krb5_conf($ctx);
1650 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1652 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1653 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1654 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1655 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1656 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1658 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1660 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1661 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1662 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1663 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1664 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1665 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1666 $cmd .= " --adminpass=$ret->{PASSWORD}";
1668 unless (system($cmd) == 0) {
1669 warn("Join failed\n$cmd");
1673 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1674 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1675 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1676 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1678 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1679 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1680 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1681 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1682 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1683 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1688 sub provision_ad_dc_ntvfs($$)
1690 my ($self, $prefix) = @_;
1692 # We keep the old 'winbind' name here in server services to
1693 # ensure upgrades which used that name still work with the now
1696 print "PROVISIONING AD DC (NTVFS)...\n";
1697 my $extra_conf_options = "netbios aliases = localDC1-a
1698 server services = +winbind -winbindd
1699 ldap server require strong auth = allow_sasl_over_tls
1700 allow nt4 crypto = yes
1701 raw NTLMv2 auth = yes
1702 lsa over netlogon = yes
1703 rpc server port = 1027
1704 auth event notification = true
1705 dsdb event notification = true
1706 dsdb password event notification = true
1707 dsdb group change notification = true
1708 server schannel = auto
1710 my $extra_provision_options = ["--use-ntvfs"];
1711 my $ret = $self->provision($prefix,
1712 "domain controller",
1715 "samba.example.com",
1720 $extra_conf_options,
1722 $extra_provision_options);
1727 unless($self->add_wins_config("$prefix/private")) {
1728 warn("Unable to add wins configuration");
1731 $ret->{NETBIOSALIAS} = "localdc1-a";
1732 $ret->{DC_SERVER} = $ret->{SERVER};
1733 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1734 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1735 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1736 $ret->{DC_USERNAME} = $ret->{USERNAME};
1737 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1738 $ret->{DC_REALM} = $ret->{REALM};
1743 sub provision_fl2000dc($$)
1745 my ($self, $prefix) = @_;
1747 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1748 my $extra_conf_options = "
1749 spnego:simulate_w2k=yes
1750 ntlmssp_server:force_old_spnego=yes
1752 my $extra_provision_options = ["--use-ntvfs"];
1753 # This environment uses plain text secrets
1754 # i.e. secret attributes are not encrypted on disk.
1755 # This allows testing of the --plaintext-secrets option for
1757 push (@{$extra_provision_options}, "--plaintext-secrets");
1758 my $ret = $self->provision($prefix,
1759 "domain controller",
1762 "samba2000.example.com",
1767 $extra_conf_options,
1769 $extra_provision_options);
1774 unless($self->add_wins_config("$prefix/private")) {
1775 warn("Unable to add wins configuration");
1778 $ret->{DC_SERVER} = $ret->{SERVER};
1779 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1780 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1781 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1782 $ret->{DC_USERNAME} = $ret->{USERNAME};
1783 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1784 $ret->{DC_REALM} = $ret->{REALM};
1789 sub provision_fl2003dc($$$)
1791 my ($self, $prefix, $dcvars) = @_;
1792 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1793 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1795 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1796 my $extra_conf_options = "allow dns updates = nonsecure and secure
1797 dcesrv:header signing = no
1798 dcesrv:max auth states = 0
1799 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1800 my $extra_provision_options = ["--use-ntvfs"];
1801 my $ret = $self->provision($prefix,
1802 "domain controller",
1805 "samba2003.example.com",
1810 $extra_conf_options,
1812 $extra_provision_options);
1813 unless (defined $ret) {
1817 $ret->{DC_SERVER} = $ret->{SERVER};
1818 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1819 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1820 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1821 $ret->{DC_USERNAME} = $ret->{USERNAME};
1822 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1823 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1824 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1826 my @samba_tool_options;
1827 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1828 push (@samba_tool_options, "domain");
1829 push (@samba_tool_options, "passwordsettings");
1830 push (@samba_tool_options, "set");
1831 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1832 push (@samba_tool_options, "--min-pwd-age=0");
1833 push (@samba_tool_options, "--history-length=1");
1835 my $samba_tool_cmd = join(" ", @samba_tool_options);
1837 unless (system($samba_tool_cmd) == 0) {
1838 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1842 unless($self->add_wins_config("$prefix/private")) {
1843 warn("Unable to add wins configuration");
1850 sub provision_fl2008r2dc($$$)
1852 my ($self, $prefix, $dcvars) = @_;
1854 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1855 my $extra_conf_options = "ldap server require strong auth = no";
1856 my $extra_provision_options = ["--use-ntvfs"];
1857 my $ret = $self->provision($prefix,
1858 "domain controller",
1861 "samba2008R2.example.com",
1866 $extra_conf_options,
1868 $extra_provision_options);
1869 unless (defined $ret) {
1873 unless ($self->add_wins_config("$prefix/private")) {
1874 warn("Unable to add wins configuration");
1877 $ret->{DC_SERVER} = $ret->{SERVER};
1878 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1879 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1880 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1881 $ret->{DC_USERNAME} = $ret->{USERNAME};
1882 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1883 $ret->{DC_REALM} = $ret->{REALM};
1889 sub provision_rodc($$$)
1891 my ($self, $prefix, $dcvars) = @_;
1892 print "PROVISIONING RODC...\n";
1894 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1895 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1901 $dcvars->{PASSWORD},
1902 $dcvars->{SERVER_IP},
1903 $dcvars->{SERVER_IPV6});
1908 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1910 $ctx->{share} = "$ctx->{prefix_abs}/share";
1911 push(@{$ctx->{directories}}, "$ctx->{share}");
1913 $ctx->{smb_conf_extra_options} = "
1915 server max protocol = SMB2
1916 password server = $dcvars->{DC_SERVER}
1919 path = $ctx->{statedir}/sysvol
1923 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1927 path = $ctx->{share}
1929 posix:sharedelay = 10000
1930 posix:oplocktimeout = 3
1931 posix:writetimeupdatedelay = 50000
1935 my $ret = $self->provision_raw_step1($ctx);
1940 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1941 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1942 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1943 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1944 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1946 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1948 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1949 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1950 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1951 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1952 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1953 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1955 unless (system($cmd) == 0) {
1956 warn("RODC join failed\n$cmd");
1960 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1961 # user password verified on the RODC
1962 my $testallowed_account = "testallowed account";
1963 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1964 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1965 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1966 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1967 $cmd .= " --server=$dcvars->{DC_SERVER}";
1969 unless (system($cmd) == 0) {
1970 warn("RODC join failed\n$cmd");
1974 # we overwrite the kdc after the RODC join
1975 # so that use the RODC as kdc and test
1977 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1978 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1979 Samba::mk_krb5_conf($ctx);
1980 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1982 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1983 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1984 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1985 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1987 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1988 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1989 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1990 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1991 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1992 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1997 sub read_config_h($)
2001 open(LF, "<$name") or die("unable to read $name: $!");
2004 next if not (/^#define /);
2005 if (/^#define (.*?)[ \t]+(.*?)$/) {
2009 if (/^#define (.*?)[ \t]+$/) {
2018 sub provision_ad_dc($$$$$$)
2020 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
2021 $extra_provision_options) = @_;
2023 my $prefix_abs = abs_path($prefix);
2025 my $bindir_abs = abs_path($self->{bindir});
2026 my $lockdir="$prefix_abs/lockdir";
2027 my $conffile="$prefix_abs/etc/smb.conf";
2029 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
2030 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
2034 if (defined($ENV{CONFIG_H})) {
2035 $config_h = read_config_h($ENV{CONFIG_H});
2038 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
2039 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
2041 my $extra_smbconf_options = "
2042 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
2044 dbwrap_tdb_mutexes:* = yes
2047 ${password_hash_gpg_key_ids}
2050 kernel change notify = no
2055 printcap name = /dev/null
2060 smbd:sharedelay = 100000
2061 smbd:writetimeupdatedelay = 500000
2064 check parent directory delete on close = yes
2066 dcerpc endpoint servers = -winreg -srvsvc
2068 printcap name = /dev/null
2070 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
2071 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
2074 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
2075 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
2076 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
2077 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
2078 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
2079 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
2080 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
2082 print notify backchannel = yes
2084 server schannel = auto
2085 auth event notification = true
2086 dsdb event notification = true
2087 dsdb password event notification = true
2088 dsdb group change notification = true
2092 my $extra_smbconf_shares = "
2096 smb encrypt = required
2100 case sensitive = yes
2108 hide unreadable = yes
2112 kernel share modes = no
2131 push (@{$extra_provision_options}, "--backend-store=mdb");
2132 print "PROVISIONING AD DC...\n";
2133 my $ret = $self->provision($prefix,
2134 "domain controller",
2142 $extra_smbconf_options,
2143 $extra_smbconf_shares,
2144 $extra_provision_options);
2145 unless (defined $ret) {
2149 unless($self->add_wins_config("$prefix/private")) {
2150 warn("Unable to add wins configuration");
2154 $ret->{DC_SERVER} = $ret->{SERVER};
2155 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2156 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2157 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2158 $ret->{DC_USERNAME} = $ret->{USERNAME};
2159 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2164 sub provision_chgdcpass($$)
2166 my ($self, $prefix) = @_;
2168 print "PROVISIONING CHGDCPASS...\n";
2169 # This environment disallows the use of this password
2170 # (and also removes the default AD complexity checks)
2171 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2172 my $extra_smb_conf = "
2173 check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'
2174 allow dcerpc auth level connect:lsarpc = yes
2175 dcesrv:max auth states = 8
2177 my $extra_provision_options = ["--use-ntvfs"];
2178 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2179 my $ret = $self->provision($prefix,
2180 "domain controller",
2183 "chgdcpassword.samba.example.com",
2190 $extra_provision_options);
2191 unless (defined $ret) {
2195 unless($self->add_wins_config("$prefix/private")) {
2196 warn("Unable to add wins configuration");
2200 # Remove secrets.tdb from this environment to test that we
2201 # still start up on systems without the new matching
2202 # secrets.tdb records.
2203 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2204 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2208 $ret->{DC_SERVER} = $ret->{SERVER};
2209 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2210 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2211 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2212 $ret->{DC_USERNAME} = $ret->{USERNAME};
2213 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2214 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2219 sub teardown_env_terminate($$)
2221 my ($self, $envvars) = @_;
2224 # This should cause samba to terminate gracefully
2225 close($envvars->{STDIN_PIPE});
2227 $pid = $envvars->{SAMBA_PID};
2231 # This should give it time to write out the gcov data
2232 until ($count > 15) {
2233 if (Samba::cleanup_child($pid, "samba") != 0) {
2240 # After 15 Seconds, work out why this thing is still alive
2241 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2242 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2244 until ($count > 30) {
2245 if (Samba::cleanup_child($pid, "samba") != 0) {
2252 if (kill(0, $pid)) {
2253 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2257 until ($count > 40) {
2258 if (Samba::cleanup_child($pid, "samba") != 0) {
2264 # If it is still around, kill it
2265 if (kill(0, $pid)) {
2266 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2272 sub teardown_env($$)
2274 my ($self, $envvars) = @_;
2275 teardown_env_terminate($self, $envvars);
2277 $self->slapd_stop($envvars) if ($self->{ldap});
2279 print $self->getlog_env($envvars);
2286 my ($self, $envvars) = @_;
2287 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2290 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2292 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2296 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2299 return "" if $out eq $title;
2306 my ($self, $envvars) = @_;
2307 my $samba_pid = $envvars->{SAMBA_PID};
2309 if (not defined($samba_pid)) {
2311 } elsif ($samba_pid > 0) {
2312 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2314 if ($childpid == 0) {
2323 # Declare the environments Samba4 makes available.
2324 # To be set up, they will be called as
2325 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2326 %Samba4::ENV_DEPS = (
2327 # name => [dep_1, dep_2, ...],
2329 ad_dc_ntvfs => ["dns_hub"],
2330 ad_dc => ["dns_hub"],
2331 ad_dc_no_nss => ["dns_hub"],
2332 ad_dc_no_ntlm => ["dns_hub"],
2333 backupfromdc => ["dns_hub"],
2334 customdc => ["dns_hub"],
2335 preforkrestartdc => ["dns_hub"],
2337 fl2008r2dc => ["ad_dc"],
2338 fl2003dc => ["ad_dc"],
2339 fl2000dc => ["dns_hub"],
2341 vampire_2000_dc => ["fl2000dc"],
2342 vampire_dc => ["ad_dc_ntvfs"],
2343 promoted_dc => ["ad_dc_ntvfs"],
2344 subdom_dc => ["ad_dc_ntvfs"],
2346 rodc => ["ad_dc_ntvfs"],
2347 rpc_proxy => ["ad_dc_ntvfs"],
2348 chgdcpass => ["dns_hub"],
2350 s4member_dflt_domain => ["ad_dc_ntvfs"],
2351 s4member => ["ad_dc_ntvfs"],
2353 restoredc => ["backupfromdc"],
2354 renamedc => ["backupfromdc"],
2355 offlinebackupdc => ["backupfromdc"],
2356 labdc => ["backupfromdc"],
2364 my ($self, $path, $dc_vars) = @_;
2366 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2369 if (not defined($self->check_or_start($env, "standard"))) {
2377 sub setup_s4member_dflt_domain
2379 my ($self, $path, $dc_vars) = @_;
2381 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2382 "winbind use default domain = yes");
2385 if (not defined($self->check_or_start($env, "standard"))) {
2395 my ($self, $path, $dc_vars) = @_;
2397 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2400 if (not defined($self->check_or_start($env, "standard"))) {
2407 sub setup_ad_dc_ntvfs
2409 my ($self, $path) = @_;
2411 my $env = $self->provision_ad_dc_ntvfs($path);
2413 if (not defined($self->check_or_start($env, "standard"))) {
2414 warn("Failed to start ad_dc_ntvfs");
2423 my ($self, $path) = @_;
2425 my $env = $self->provision_chgdcpass($path);
2427 if (not defined($self->check_or_start($env, "standard"))) {
2436 my ($self, $path) = @_;
2438 my $env = $self->provision_fl2000dc($path);
2440 if (not defined($self->check_or_start($env, "standard"))) {
2450 my ($self, $path, $dc_vars) = @_;
2452 my $env = $self->provision_fl2003dc($path);
2455 if (not defined($self->check_or_start($env, "standard"))) {
2459 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2464 sub setup_fl2008r2dc
2466 my ($self, $path, $dc_vars) = @_;
2468 my $env = $self->provision_fl2008r2dc($path);
2471 if (not defined($self->check_or_start($env, "standard"))) {
2475 my $upn_array = ["$env->{REALM}.upn"];
2476 my $spn_array = ["$env->{REALM}.spn"];
2478 $self->setup_namespaces($env, $upn_array, $spn_array);
2480 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2486 sub setup_vampire_dc
2488 return setup_generic_vampire_dc(@_, "2008");
2491 sub setup_vampire_2000_dc
2493 return setup_generic_vampire_dc(@_, "2000");
2496 sub setup_generic_vampire_dc
2498 my ($self, $path, $dc_vars, $fl) = @_;
2500 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2503 if (not defined($self->check_or_start($env, "single"))) {
2507 # force replicated DC to update repsTo/repsFrom
2508 # for vampired partitions
2509 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2511 # as 'vampired' dc may add data in its local replica
2512 # we need to synchronize data between DCs
2513 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2514 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2515 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2516 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2517 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2519 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2521 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2522 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2523 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2524 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2525 $cmd .= " $dc_vars->{CONFIGURATION}";
2526 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2527 # replicate Configuration NC
2528 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2529 unless(system($cmd_repl) == 0) {
2530 warn("Failed to replicate\n$cmd_repl");
2533 # replicate Default NC
2534 $cmd_repl = "$cmd \"$base_dn\"";
2535 unless(system($cmd_repl) == 0) {
2536 warn("Failed to replicate\n$cmd_repl");
2540 # Pull in a full set of changes from the main DC
2541 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2542 $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2543 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2544 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2545 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2547 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2549 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2550 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2551 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2552 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2553 $cmd .= " $dc_vars->{CONFIGURATION}";
2554 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2555 # replicate Configuration NC
2556 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2557 unless(system($cmd_repl) == 0) {
2558 warn("Failed to replicate\n$cmd_repl");
2561 # replicate Default NC
2562 $cmd_repl = "$cmd \"$base_dn\"";
2563 unless(system($cmd_repl) == 0) {
2564 warn("Failed to replicate\n$cmd_repl");
2572 sub setup_promoted_dc
2574 my ($self, $path, $dc_vars) = @_;
2576 my $env = $self->provision_promoted_dc($path, $dc_vars);
2579 if (not defined($self->check_or_start($env, "single"))) {
2583 # force source and replicated DC to update repsTo/repsFrom
2584 # for vampired partitions
2585 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2586 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2587 # as 'vampired' dc may add data in its local replica
2588 # we need to synchronize data between DCs
2589 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2590 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2591 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2592 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2593 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2594 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2595 $cmd .= " $dc_vars->{CONFIGURATION}";
2596 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2597 # replicate Configuration NC
2598 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2599 unless(system($cmd_repl) == 0) {
2600 warn("Failed to replicate\n$cmd_repl");
2603 # replicate Default NC
2604 $cmd_repl = "$cmd \"$base_dn\"";
2605 unless(system($cmd_repl) == 0) {
2606 warn("Failed to replicate\n$cmd_repl");
2616 my ($self, $path, $dc_vars) = @_;
2618 my $env = $self->provision_subdom_dc($path, $dc_vars);
2621 if (not defined($self->check_or_start($env, "single"))) {
2625 # force replicated DC to update repsTo/repsFrom
2626 # for primary domain partitions
2627 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2628 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2629 # as 'subdomain' dc may add data in its local replica
2630 # we need to synchronize data between DCs
2631 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2632 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2633 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2634 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2635 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2636 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2637 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2638 $cmd .= " $dc_vars->{CONFIGURATION}";
2639 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2640 # replicate Configuration NC
2641 my $cmd_repl = "$cmd \"$config_dn\"";
2642 unless(system($cmd_repl) == 0) {
2643 warn("Failed to replicate\n$cmd_repl");
2646 # replicate Default NC
2647 $cmd_repl = "$cmd \"$base_dn\"";
2648 unless(system($cmd_repl) == 0) {
2649 warn("Failed to replicate\n$cmd_repl");
2659 my ($self, $path, $dc_vars) = @_;
2661 my $env = $self->provision_rodc($path, $dc_vars);
2667 if (not defined($self->check_or_start($env, "standard"))) {
2671 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2674 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2675 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2676 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2677 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2678 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2679 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2680 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2681 $cmd .= " $dc_vars->{CONFIGURATION}";
2682 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2683 # replicate Configuration NC
2684 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2685 unless(system($cmd_repl) == 0) {
2686 warn("Failed to replicate\n$cmd_repl");
2689 # replicate Default NC
2690 $cmd_repl = "$cmd \"$base_dn\"";
2691 unless(system($cmd_repl) == 0) {
2692 warn("Failed to replicate\n$cmd_repl");
2701 my ($self, $path) = @_;
2703 # If we didn't build with ADS, pretend this env was never available
2704 if (not $self->{target3}->have_ads()) {
2708 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2709 "addom.samba.example.com", "", undef);
2714 if (not defined($self->check_or_start($env, "prefork"))) {
2718 my $upn_array = ["$env->{REALM}.upn"];
2719 my $spn_array = ["$env->{REALM}.spn"];
2721 $self->setup_namespaces($env, $upn_array, $spn_array);
2726 sub setup_ad_dc_no_nss
2728 my ($self, $path) = @_;
2730 # If we didn't build with ADS, pretend this env was never available
2731 if (not $self->{target3}->have_ads()) {
2735 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2736 "adnonssdom.samba.example.com", "", undef);
2741 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2742 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2744 if (not defined($self->check_or_start($env, "single"))) {
2748 my $upn_array = ["$env->{REALM}.upn"];
2749 my $spn_array = ["$env->{REALM}.spn"];
2751 $self->setup_namespaces($env, $upn_array, $spn_array);
2756 sub setup_ad_dc_no_ntlm
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 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2766 "adnontlmdom.samba.example.com",
2767 "ntlm auth = disabled", undef);
2772 if (not defined($self->check_or_start($env, "prefork"))) {
2776 my $upn_array = ["$env->{REALM}.upn"];
2777 my $spn_array = ["$env->{REALM}.spn"];
2779 $self->setup_namespaces($env, $upn_array, $spn_array);
2785 # AD DC test environment used solely to test pre-fork process restarts.
2786 # As processes get killed off and restarted it should not be used for other
2787 sub setup_preforkrestartdc
2789 my ($self, $path) = @_;
2791 # If we didn't build with ADS, pretend this env was never available
2792 if (not $self->{target3}->have_ads()) {
2796 # note DC name must be <= 15 chars so we use 'prockill' instead of
2798 my $env = $self->provision_ad_dc(
2802 "prockilldom.samba.example.com",
2803 "prefork backoff increment = 5\nprefork maximum backoff=10");
2808 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2809 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2811 if (not defined($self->check_or_start($env, "prefork"))) {
2815 my $upn_array = ["$env->{REALM}.upn"];
2816 my $spn_array = ["$env->{REALM}.spn"];
2818 $self->setup_namespaces($env, $upn_array, $spn_array);
2824 # ad_dc test environment used solely to test standard process model connection
2825 # process limits. As the limit is set artificially low it should not be used
2827 sub setup_proclimitdc
2829 my ($self, $path) = @_;
2831 # If we didn't build with ADS, pretend this env was never available
2832 if (not $self->{target3}->have_ads()) {
2836 my $env = $self->provision_ad_dc(
2840 "proclimit.samba.example.com",
2841 "max smbd processes = 20");
2846 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2847 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2849 if (not defined($self->check_or_start($env, "standard"))) {
2853 my $upn_array = ["$env->{REALM}.upn"];
2854 my $spn_array = ["$env->{REALM}.spn"];
2856 $self->setup_namespaces($env, $upn_array, $spn_array);
2861 # Sets up a DC that's solely used to do a domain backup from. We then use the
2862 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2863 # process will create a Samba DC that will actually start up.
2864 # We don't use the backup-DC for anything else because its domain will conflict
2865 # with the restore DC.
2866 sub setup_backupfromdc
2868 my ($self, $path) = @_;
2870 # If we didn't build with ADS, pretend this env was never available
2871 if (not $self->{target3}->have_ads()) {
2875 my $provision_args = ["--site=Backup-Site"];
2877 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2878 "backupdom.samba.example.com",
2879 "samba kcc command = /bin/true",
2885 if (not defined($self->check_or_start($env, "standard"))) {
2889 my $upn_array = ["$env->{REALM}.upn"];
2890 my $spn_array = ["$env->{REALM}.spn"];
2892 $self->setup_namespaces($env, $upn_array, $spn_array);
2897 # returns the server/user-auth params needed to run an online backup cmd
2898 sub get_backup_server_args
2900 # dcvars contains the env info for the backup DC testenv
2901 my ($self, $dcvars) = @_;
2902 my $server = $dcvars->{DC_SERVER_IP};
2903 my $server_args = "--server=$server ";
2904 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2905 $server_args .= " $dcvars->{CONFIGURATION}";
2907 return $server_args;
2910 # Creates a backup of a running testenv DC
2913 # note: dcvars contains the env info for the backup DC testenv
2914 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2916 # get all the env variables we pass in with the samba-tool command
2917 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2918 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2919 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2920 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2922 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2924 # Note: use the backupfrom-DC's krb5.conf to do the backup
2925 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2926 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2928 # use samba-tool to create a backup from the 'backupfromdc' DC
2930 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2932 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2933 $cmd .= " --targetdir=$backupdir";
2935 print "Executing: $cmd\n";
2936 unless(system($cmd) == 0) {
2937 warn("Failed to create backup using: \n$cmd");
2941 # get the name of the backup file created
2942 opendir(DIR, $backupdir);
2943 my @files = grep(/\.tar/, readdir(DIR));
2946 if(scalar @files != 1) {
2947 warn("Backup file not found in directory $backupdir\n");
2950 my $backup_file = "$backupdir/$files[0]";
2951 print "Using backup file $backup_file...\n";
2953 return $backup_file;
2956 # Restores a backup-file to populate a testenv for a new DC
2957 sub restore_backup_file
2959 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2961 # pass the restore command the testenv's smb.conf that we've already
2962 # generated. But move it to a temp-dir first, so that the restore doesn't
2964 my $tmpdir = File::Temp->newdir();
2965 my $tmpconf = "$tmpdir/smb.conf";
2966 my $cmd = "cp $smbconf $tmpconf";
2967 unless(system($cmd) == 0) {
2968 warn("Failed to backup smb.conf using: \n$cmd");
2972 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2973 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2974 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2976 print "Executing: $cmd\n";
2977 unless(system($cmd) == 0) {
2978 warn("Failed to restore backup using: \n$cmd");
2982 print "Restore complete\n";
2986 # sets up the initial directory and returns the new testenv's env info
2987 # (without actually doing a 'domain join')
2988 sub prepare_dc_testenv
2990 my ($self, $prefix, $dcname, $domain, $realm,
2991 $password, $conf_options) = @_;
2993 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
3003 # the restore uses a slightly different state-dir location to other testenvs
3004 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
3005 push(@{$ctx->{directories}}, "$ctx->{statedir}");
3007 # add support for sysvol/netlogon/tmp shares
3008 $ctx->{share} = "$ctx->{prefix_abs}/share";
3009 push(@{$ctx->{directories}}, "$ctx->{share}");
3011 $ctx->{smb_conf_extra_options} = "
3014 server max protocol = SMB2
3015 samba kcc command = /bin/true
3018 path = $ctx->{statedir}/sysvol
3022 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
3026 path = $ctx->{share}
3028 posix:sharedelay = 10000
3029 posix:oplocktimeout = 3
3030 posix:writetimeupdatedelay = 50000
3034 my $env = $self->provision_raw_step1($ctx);
3036 $env->{DC_SERVER} = $env->{SERVER};
3037 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
3038 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
3039 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
3040 $env->{DC_USERNAME} = $env->{USERNAME};
3041 $env->{DC_PASSWORD} = $env->{PASSWORD};
3043 return ($env, $ctx);
3047 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3048 # commands. This proves that we can backup an online DC ('backupfromdc') and
3049 # use the backup file to create a valid, working samba DC.
3052 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3053 my ($self, $prefix, $dcvars) = @_;
3054 print "Preparing RESTORE DC...\n";
3056 # we arbitrarily designate the restored DC as having SMBv1 disabled
3058 server min protocol = SMB2
3059 client min protocol = SMB2";
3061 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3064 $dcvars->{PASSWORD},
3067 # create a backup of the 'backupfromdc'
3068 my $backupdir = File::Temp->newdir();
3069 my $server_args = $self->get_backup_server_args($dcvars);
3070 my $backup_args = "online $server_args";
3071 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3073 unless($backup_file) {
3077 # restore the backup file to populate the restore-DC testenv
3078 my $restore_dir = abs_path($prefix);
3079 my $ret = $self->restore_backup_file($backup_file,
3080 "--newservername=$env->{SERVER}",
3081 $restore_dir, $env->{SERVERCONFFILE});
3082 unless ($ret == 0) {
3086 # start samba for the restored DC
3087 if (not defined($self->check_or_start($env, "standard"))) {
3094 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3095 # restore commands. This proves that we can backup and rename an online DC
3096 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3099 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3100 my ($self, $prefix, $dcvars) = @_;
3101 print "Preparing RENAME DC...\n";
3103 my $realm = "renamedom.samba.example.com";
3104 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3105 "RENAMEDOMAIN", $realm,
3106 $dcvars->{PASSWORD}, "");
3108 # create a backup of the 'backupfromdc' which renames the domain
3109 my $backupdir = File::Temp->newdir();
3110 my $server_args = $self->get_backup_server_args($dcvars);
3111 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3112 $backup_args .= " --backend-store=tdb";
3113 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3115 unless($backup_file) {
3119 # restore the backup file to populate the rename-DC testenv
3120 my $restore_dir = abs_path($prefix);
3121 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3122 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3123 $restore_dir, $env->{SERVERCONFFILE});
3124 unless ($ret == 0) {
3128 # start samba for the restored DC
3129 if (not defined($self->check_or_start($env, "standard"))) {
3133 my $upn_array = ["$env->{REALM}.upn"];
3134 my $spn_array = ["$env->{REALM}.spn"];
3136 $self->setup_namespaces($env, $upn_array, $spn_array);
3141 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3142 # restore commands. This proves that we do an offline backup of a local DC
3143 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3144 sub setup_offlinebackupdc
3146 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3147 my ($self, $prefix, $dcvars) = @_;
3148 print "Preparing OFFLINE BACKUP DC...\n";
3150 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3153 $dcvars->{PASSWORD}, "");
3155 # create an offline backup of the 'backupfromdc' target
3156 my $backupdir = File::Temp->newdir();
3157 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3158 my $backup_file = $self->create_backup($env, $dcvars,
3161 unless($backup_file) {
3165 # restore the backup file to populate the rename-DC testenv
3166 my $restore_dir = abs_path($prefix);
3167 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3168 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3169 $restore_dir, $env->{SERVERCONFFILE});
3170 unless ($ret == 0) {
3174 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3175 Samba::mk_krb5_conf($ctx);
3177 # start samba for the restored DC
3178 if (not defined($self->check_or_start($env, "standard"))) {
3185 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3186 # restore commands, using the --no-secrets option. This proves that we can
3187 # create a realistic lab environment from an online DC ('backupfromdc').
3190 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3191 my ($self, $prefix, $dcvars) = @_;
3192 print "Preparing LAB-DOMAIN DC...\n";
3194 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3196 "labdom.samba.example.com",
3197 $dcvars->{PASSWORD}, "");
3199 # create a backup of the 'backupfromdc' which renames the domain and uses
3200 # the --no-secrets option to scrub any sensitive info
3201 my $backupdir = File::Temp->newdir();
3202 my $server_args = $self->get_backup_server_args($dcvars);
3203 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3204 $backup_args .= " --no-secrets --backend-store=mdb";
3205 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3207 unless($backup_file) {
3211 # restore the backup file to populate the lab-DC testenv
3212 my $restore_dir = abs_path($prefix);
3213 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3214 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3215 $restore_dir, $env->{SERVERCONFFILE});
3216 unless ($ret == 0) {
3220 # because we don't include any secrets in the backup, we need to reset the
3221 # admin user's password back to what the testenv expects
3222 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3223 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3224 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3225 $cmd .= " $env->{CONFIGURATION}";
3227 unless(system($cmd) == 0) {
3228 warn("Failed to reset admin's password: \n$cmd");
3232 # start samba for the restored DC
3233 if (not defined($self->check_or_start($env, "standard"))) {
3237 my $upn_array = ["$env->{REALM}.upn"];
3238 my $spn_array = ["$env->{REALM}.spn"];
3240 $self->setup_namespaces($env, $upn_array, $spn_array);
3245 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3246 sub get_backup_domain_realm
3248 my ($self, $backup_file) = @_;
3250 print "Determining REALM/DOMAIN values in backup...\n";
3252 # The backup will have the correct domain/realm values in the smb.conf.
3253 # So we can work out the env variables the testenv should use based on
3254 # that. Let's start by extracting the smb.conf
3255 my $tar = Archive::Tar->new($backup_file);
3256 my $tmpdir = File::Temp->newdir();
3257 my $smbconf = "$tmpdir/smb.conf";
3259 # note that the filepaths within the tar-file differ slightly for online
3260 # and offline backups
3261 if ($tar->contains_file("etc/smb.conf")) {
3262 $tar->extract_file("etc/smb.conf", $smbconf);
3263 } elsif ($tar->contains_file("./etc/smb.conf")) {
3264 $tar->extract_file("./etc/smb.conf", $smbconf);
3266 warn("Could not find smb.conf in $backup_file");
3267 return undef, undef;
3270 # now use testparm to read the values we're interested in
3271 my $testparm = Samba::bindir_path($self, "testparm");
3272 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3273 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3276 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3278 return ($domain, $realm);
3281 # This spins up a custom testenv that can be based on any backup-file you want.
3282 # This is just intended for manual testing (rather than automated test-cases)
3285 my ($self, $prefix) = @_;
3286 print "Preparing CUSTOM RESTORE DC...\n";
3287 my $dc_name = "customdc";
3288 my $password = "locDCpass1";
3289 my $backup_file = $ENV{'BACKUP_FILE'};
3291 # user must specify a backup file to restore via an ENV variable, i.e.
3292 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3293 if (not defined($backup_file)) {
3294 warn("Please specify BACKUP_FILE");
3298 # work out the correct domain/realm env values from the backup-file
3299 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3301 # create a placeholder directory and smb.conf, as well as the env vars.
3302 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3303 $domain, $realm, $password, "");
3305 # restore the specified backup file to populate the testenv
3306 my $restore_dir = abs_path($prefix);
3307 my $ret = $self->restore_backup_file($backup_file,
3308 "--newservername=$env->{SERVER}",
3309 $restore_dir, $env->{SERVERCONFFILE});
3310 unless ($ret == 0) {
3314 # Change the admin password to the testenv default, just in case it's
3315 # different, or in case this was a --no-secrets backup
3316 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3317 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3318 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3319 $cmd .= " $env->{CONFIGURATION}";
3321 unless(system($cmd) == 0) {
3322 warn("Failed to reset admin's password: \n$cmd");
3326 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3327 # if the backup-file was an offline backup)
3328 Samba::mk_krb5_conf($ctx);
3330 # start samba for the restored DC
3331 if (not defined($self->check_or_start($env, "standard"))) {
3335 # if this was a backup-rename, then we may need to setup namespaces
3336 my $upn_array = ["$env->{REALM}.upn"];
3337 my $spn_array = ["$env->{REALM}.spn"];
3339 $self->setup_namespaces($env, $upn_array, $spn_array);
3346 my ($self, $path) = @_;
3349 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",