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 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2227 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2228 my $ret = system($cmd);
2230 warn "'$cmd' failed with '$ret'\n";
2233 # This should cause samba to terminate gracefully
2234 close($envvars->{STDIN_PIPE});
2236 $pid = $envvars->{SAMBA_PID};
2240 # This should give it time to write out the gcov data
2241 until ($count > 15) {
2242 if (Samba::cleanup_child($pid, "samba") != 0) {
2249 # After 15 Seconds, work out why this thing is still alive
2250 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2251 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2253 until ($count > 30) {
2254 if (Samba::cleanup_child($pid, "samba") != 0) {
2261 if (kill(0, $pid)) {
2262 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2266 until ($count > 40) {
2267 if (Samba::cleanup_child($pid, "samba") != 0) {
2273 # If it is still around, kill it
2274 if (kill(0, $pid)) {
2275 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2281 sub teardown_env($$)
2283 my ($self, $envvars) = @_;
2284 teardown_env_terminate($self, $envvars);
2286 $self->slapd_stop($envvars) if ($self->{ldap});
2288 print $self->getlog_env($envvars);
2295 my ($self, $envvars) = @_;
2296 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2299 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2301 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2305 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2308 return "" if $out eq $title;
2315 my ($self, $envvars) = @_;
2316 my $samba_pid = $envvars->{SAMBA_PID};
2318 if (not defined($samba_pid)) {
2320 } elsif ($samba_pid > 0) {
2321 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2323 if ($childpid == 0) {
2332 # Declare the environments Samba4 makes available.
2333 # To be set up, they will be called as
2334 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2335 %Samba4::ENV_DEPS = (
2336 # name => [dep_1, dep_2, ...],
2338 ad_dc_ntvfs => ["dns_hub"],
2339 ad_dc => ["dns_hub"],
2340 ad_dc_no_nss => ["dns_hub"],
2341 ad_dc_no_ntlm => ["dns_hub"],
2342 backupfromdc => ["dns_hub"],
2343 customdc => ["dns_hub"],
2344 preforkrestartdc => ["dns_hub"],
2346 fl2008r2dc => ["ad_dc"],
2347 fl2003dc => ["ad_dc"],
2348 fl2000dc => ["dns_hub"],
2350 vampire_2000_dc => ["fl2000dc"],
2351 vampire_dc => ["ad_dc_ntvfs"],
2352 promoted_dc => ["ad_dc_ntvfs"],
2353 subdom_dc => ["ad_dc_ntvfs"],
2355 rodc => ["ad_dc_ntvfs"],
2356 rpc_proxy => ["ad_dc_ntvfs"],
2357 chgdcpass => ["dns_hub"],
2359 s4member_dflt_domain => ["ad_dc_ntvfs"],
2360 s4member => ["ad_dc_ntvfs"],
2362 restoredc => ["backupfromdc"],
2363 renamedc => ["backupfromdc"],
2364 offlinebackupdc => ["backupfromdc"],
2365 labdc => ["backupfromdc"],
2373 my ($self, $path, $dc_vars) = @_;
2375 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2378 if (not defined($self->check_or_start($env, "standard"))) {
2386 sub setup_s4member_dflt_domain
2388 my ($self, $path, $dc_vars) = @_;
2390 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2391 "winbind use default domain = yes");
2394 if (not defined($self->check_or_start($env, "standard"))) {
2404 my ($self, $path, $dc_vars) = @_;
2406 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2409 if (not defined($self->check_or_start($env, "standard"))) {
2416 sub setup_ad_dc_ntvfs
2418 my ($self, $path) = @_;
2420 my $env = $self->provision_ad_dc_ntvfs($path);
2422 if (not defined($self->check_or_start($env, "standard"))) {
2423 warn("Failed to start ad_dc_ntvfs");
2432 my ($self, $path) = @_;
2434 my $env = $self->provision_chgdcpass($path);
2436 if (not defined($self->check_or_start($env, "standard"))) {
2445 my ($self, $path) = @_;
2447 my $env = $self->provision_fl2000dc($path);
2449 if (not defined($self->check_or_start($env, "standard"))) {
2459 my ($self, $path, $dc_vars) = @_;
2461 my $env = $self->provision_fl2003dc($path);
2464 if (not defined($self->check_or_start($env, "standard"))) {
2468 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2473 sub setup_fl2008r2dc
2475 my ($self, $path, $dc_vars) = @_;
2477 my $env = $self->provision_fl2008r2dc($path);
2480 if (not defined($self->check_or_start($env, "standard"))) {
2484 my $upn_array = ["$env->{REALM}.upn"];
2485 my $spn_array = ["$env->{REALM}.spn"];
2487 $self->setup_namespaces($env, $upn_array, $spn_array);
2489 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2495 sub setup_vampire_dc
2497 return setup_generic_vampire_dc(@_, "2008");
2500 sub setup_vampire_2000_dc
2502 return setup_generic_vampire_dc(@_, "2000");
2505 sub setup_generic_vampire_dc
2507 my ($self, $path, $dc_vars, $fl) = @_;
2509 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2512 if (not defined($self->check_or_start($env, "single"))) {
2516 # force replicated DC to update repsTo/repsFrom
2517 # for vampired partitions
2518 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2520 # as 'vampired' dc may add data in its local replica
2521 # we need to synchronize data between DCs
2522 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2523 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2524 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2525 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2526 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2528 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2530 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2531 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2532 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2533 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2534 $cmd .= " $dc_vars->{CONFIGURATION}";
2535 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2536 # replicate Configuration NC
2537 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2538 unless(system($cmd_repl) == 0) {
2539 warn("Failed to replicate\n$cmd_repl");
2542 # replicate Default NC
2543 $cmd_repl = "$cmd \"$base_dn\"";
2544 unless(system($cmd_repl) == 0) {
2545 warn("Failed to replicate\n$cmd_repl");
2549 # Pull in a full set of changes from the main DC
2550 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2551 $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2552 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2553 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2554 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2556 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2558 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2559 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2560 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2561 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2562 $cmd .= " $dc_vars->{CONFIGURATION}";
2563 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2564 # replicate Configuration NC
2565 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2566 unless(system($cmd_repl) == 0) {
2567 warn("Failed to replicate\n$cmd_repl");
2570 # replicate Default NC
2571 $cmd_repl = "$cmd \"$base_dn\"";
2572 unless(system($cmd_repl) == 0) {
2573 warn("Failed to replicate\n$cmd_repl");
2581 sub setup_promoted_dc
2583 my ($self, $path, $dc_vars) = @_;
2585 my $env = $self->provision_promoted_dc($path, $dc_vars);
2588 if (not defined($self->check_or_start($env, "single"))) {
2592 # force source and replicated DC to update repsTo/repsFrom
2593 # for vampired partitions
2594 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2595 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2596 # as 'vampired' dc may add data in its local replica
2597 # we need to synchronize data between DCs
2598 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2599 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2600 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2601 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2602 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2603 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2604 $cmd .= " $dc_vars->{CONFIGURATION}";
2605 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2606 # replicate Configuration NC
2607 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2608 unless(system($cmd_repl) == 0) {
2609 warn("Failed to replicate\n$cmd_repl");
2612 # replicate Default NC
2613 $cmd_repl = "$cmd \"$base_dn\"";
2614 unless(system($cmd_repl) == 0) {
2615 warn("Failed to replicate\n$cmd_repl");
2625 my ($self, $path, $dc_vars) = @_;
2627 my $env = $self->provision_subdom_dc($path, $dc_vars);
2630 if (not defined($self->check_or_start($env, "single"))) {
2634 # force replicated DC to update repsTo/repsFrom
2635 # for primary domain partitions
2636 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2637 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2638 # as 'subdomain' dc may add data in its local replica
2639 # we need to synchronize data between DCs
2640 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2641 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2642 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2643 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2644 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2645 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2646 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2647 $cmd .= " $dc_vars->{CONFIGURATION}";
2648 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2649 # replicate Configuration NC
2650 my $cmd_repl = "$cmd \"$config_dn\"";
2651 unless(system($cmd_repl) == 0) {
2652 warn("Failed to replicate\n$cmd_repl");
2655 # replicate Default NC
2656 $cmd_repl = "$cmd \"$base_dn\"";
2657 unless(system($cmd_repl) == 0) {
2658 warn("Failed to replicate\n$cmd_repl");
2668 my ($self, $path, $dc_vars) = @_;
2670 my $env = $self->provision_rodc($path, $dc_vars);
2676 if (not defined($self->check_or_start($env, "standard"))) {
2680 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2683 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2684 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2685 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2686 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2687 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2688 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2689 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2690 $cmd .= " $dc_vars->{CONFIGURATION}";
2691 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2692 # replicate Configuration NC
2693 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2694 unless(system($cmd_repl) == 0) {
2695 warn("Failed to replicate\n$cmd_repl");
2698 # replicate Default NC
2699 $cmd_repl = "$cmd \"$base_dn\"";
2700 unless(system($cmd_repl) == 0) {
2701 warn("Failed to replicate\n$cmd_repl");
2710 my ($self, $path) = @_;
2712 # If we didn't build with ADS, pretend this env was never available
2713 if (not $self->{target3}->have_ads()) {
2717 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2718 "addom.samba.example.com", "", undef);
2723 if (not defined($self->check_or_start($env, "prefork"))) {
2727 my $upn_array = ["$env->{REALM}.upn"];
2728 my $spn_array = ["$env->{REALM}.spn"];
2730 $self->setup_namespaces($env, $upn_array, $spn_array);
2735 sub setup_ad_dc_no_nss
2737 my ($self, $path) = @_;
2739 # If we didn't build with ADS, pretend this env was never available
2740 if (not $self->{target3}->have_ads()) {
2744 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2745 "adnonssdom.samba.example.com", "", undef);
2750 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2751 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2753 if (not defined($self->check_or_start($env, "single"))) {
2757 my $upn_array = ["$env->{REALM}.upn"];
2758 my $spn_array = ["$env->{REALM}.spn"];
2760 $self->setup_namespaces($env, $upn_array, $spn_array);
2765 sub setup_ad_dc_no_ntlm
2767 my ($self, $path) = @_;
2769 # If we didn't build with ADS, pretend this env was never available
2770 if (not $self->{target3}->have_ads()) {
2774 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2775 "adnontlmdom.samba.example.com",
2776 "ntlm auth = disabled", undef);
2781 if (not defined($self->check_or_start($env, "prefork"))) {
2785 my $upn_array = ["$env->{REALM}.upn"];
2786 my $spn_array = ["$env->{REALM}.spn"];
2788 $self->setup_namespaces($env, $upn_array, $spn_array);
2794 # AD DC test environment used solely to test pre-fork process restarts.
2795 # As processes get killed off and restarted it should not be used for other
2796 sub setup_preforkrestartdc
2798 my ($self, $path) = @_;
2800 # If we didn't build with ADS, pretend this env was never available
2801 if (not $self->{target3}->have_ads()) {
2805 # note DC name must be <= 15 chars so we use 'prockill' instead of
2807 my $env = $self->provision_ad_dc(
2811 "prockilldom.samba.example.com",
2812 "prefork backoff increment = 5\nprefork maximum backoff=10");
2817 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2818 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2820 if (not defined($self->check_or_start($env, "prefork"))) {
2824 my $upn_array = ["$env->{REALM}.upn"];
2825 my $spn_array = ["$env->{REALM}.spn"];
2827 $self->setup_namespaces($env, $upn_array, $spn_array);
2833 # ad_dc test environment used solely to test standard process model connection
2834 # process limits. As the limit is set artificially low it should not be used
2836 sub setup_proclimitdc
2838 my ($self, $path) = @_;
2840 # If we didn't build with ADS, pretend this env was never available
2841 if (not $self->{target3}->have_ads()) {
2845 my $env = $self->provision_ad_dc(
2849 "proclimit.samba.example.com",
2850 "max smbd processes = 20");
2855 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2856 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2858 if (not defined($self->check_or_start($env, "standard"))) {
2862 my $upn_array = ["$env->{REALM}.upn"];
2863 my $spn_array = ["$env->{REALM}.spn"];
2865 $self->setup_namespaces($env, $upn_array, $spn_array);
2870 # Sets up a DC that's solely used to do a domain backup from. We then use the
2871 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2872 # process will create a Samba DC that will actually start up.
2873 # We don't use the backup-DC for anything else because its domain will conflict
2874 # with the restore DC.
2875 sub setup_backupfromdc
2877 my ($self, $path) = @_;
2879 # If we didn't build with ADS, pretend this env was never available
2880 if (not $self->{target3}->have_ads()) {
2884 my $provision_args = ["--site=Backup-Site"];
2886 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2887 "backupdom.samba.example.com",
2888 "samba kcc command = /bin/true",
2894 if (not defined($self->check_or_start($env, "standard"))) {
2898 my $upn_array = ["$env->{REALM}.upn"];
2899 my $spn_array = ["$env->{REALM}.spn"];
2901 $self->setup_namespaces($env, $upn_array, $spn_array);
2906 # returns the server/user-auth params needed to run an online backup cmd
2907 sub get_backup_server_args
2909 # dcvars contains the env info for the backup DC testenv
2910 my ($self, $dcvars) = @_;
2911 my $server = $dcvars->{DC_SERVER_IP};
2912 my $server_args = "--server=$server ";
2913 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2914 $server_args .= " $dcvars->{CONFIGURATION}";
2916 return $server_args;
2919 # Creates a backup of a running testenv DC
2922 # note: dcvars contains the env info for the backup DC testenv
2923 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2925 # get all the env variables we pass in with the samba-tool command
2926 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2927 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2928 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2929 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2931 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2933 # Note: use the backupfrom-DC's krb5.conf to do the backup
2934 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2935 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2937 # use samba-tool to create a backup from the 'backupfromdc' DC
2939 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2941 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2942 $cmd .= " --targetdir=$backupdir";
2944 print "Executing: $cmd\n";
2945 unless(system($cmd) == 0) {
2946 warn("Failed to create backup using: \n$cmd");
2950 # get the name of the backup file created
2951 opendir(DIR, $backupdir);
2952 my @files = grep(/\.tar/, readdir(DIR));
2955 if(scalar @files != 1) {
2956 warn("Backup file not found in directory $backupdir\n");
2959 my $backup_file = "$backupdir/$files[0]";
2960 print "Using backup file $backup_file...\n";
2962 return $backup_file;
2965 # Restores a backup-file to populate a testenv for a new DC
2966 sub restore_backup_file
2968 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2970 # pass the restore command the testenv's smb.conf that we've already
2971 # generated. But move it to a temp-dir first, so that the restore doesn't
2973 my $tmpdir = File::Temp->newdir();
2974 my $tmpconf = "$tmpdir/smb.conf";
2975 my $cmd = "cp $smbconf $tmpconf";
2976 unless(system($cmd) == 0) {
2977 warn("Failed to backup smb.conf using: \n$cmd");
2981 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2982 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2983 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2985 print "Executing: $cmd\n";
2986 unless(system($cmd) == 0) {
2987 warn("Failed to restore backup using: \n$cmd");
2991 print "Restore complete\n";
2995 # sets up the initial directory and returns the new testenv's env info
2996 # (without actually doing a 'domain join')
2997 sub prepare_dc_testenv
2999 my ($self, $prefix, $dcname, $domain, $realm,
3000 $password, $conf_options) = @_;
3002 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
3012 # the restore uses a slightly different state-dir location to other testenvs
3013 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
3014 push(@{$ctx->{directories}}, "$ctx->{statedir}");
3016 # add support for sysvol/netlogon/tmp shares
3017 $ctx->{share} = "$ctx->{prefix_abs}/share";
3018 push(@{$ctx->{directories}}, "$ctx->{share}");
3019 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
3021 $ctx->{smb_conf_extra_options} = "
3024 server max protocol = SMB2
3025 samba kcc command = /bin/true
3026 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
3029 path = $ctx->{statedir}/sysvol
3033 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
3037 path = $ctx->{share}
3039 posix:sharedelay = 10000
3040 posix:oplocktimeout = 3
3041 posix:writetimeupdatedelay = 50000
3044 path = $ctx->{share}/test1
3046 posix:sharedelay = 100000
3047 posix:oplocktimeout = 3
3048 posix:writetimeupdatedelay = 500000
3051 my $env = $self->provision_raw_step1($ctx);
3053 $env->{DC_SERVER} = $env->{SERVER};
3054 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
3055 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
3056 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
3057 $env->{DC_USERNAME} = $env->{USERNAME};
3058 $env->{DC_PASSWORD} = $env->{PASSWORD};
3060 return ($env, $ctx);
3064 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3065 # commands. This proves that we can backup an online DC ('backupfromdc') and
3066 # use the backup file to create a valid, working samba DC.
3069 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3070 my ($self, $prefix, $dcvars) = @_;
3071 print "Preparing RESTORE DC...\n";
3073 # we arbitrarily designate the restored DC as having SMBv1 disabled
3075 server min protocol = SMB2
3076 client min protocol = SMB2";
3078 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3081 $dcvars->{PASSWORD},
3084 # create a backup of the 'backupfromdc'
3085 my $backupdir = File::Temp->newdir();
3086 my $server_args = $self->get_backup_server_args($dcvars);
3087 my $backup_args = "online $server_args";
3088 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3090 unless($backup_file) {
3094 # restore the backup file to populate the restore-DC testenv
3095 my $restore_dir = abs_path($prefix);
3096 my $ret = $self->restore_backup_file($backup_file,
3097 "--newservername=$env->{SERVER}",
3098 $restore_dir, $env->{SERVERCONFFILE});
3099 unless ($ret == 0) {
3103 # start samba for the restored DC
3104 if (not defined($self->check_or_start($env, "standard"))) {
3111 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3112 # restore commands. This proves that we can backup and rename an online DC
3113 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3116 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3117 my ($self, $prefix, $dcvars) = @_;
3118 print "Preparing RENAME DC...\n";
3120 my $realm = "renamedom.samba.example.com";
3121 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3122 "RENAMEDOMAIN", $realm,
3123 $dcvars->{PASSWORD}, "");
3125 # create a backup of the 'backupfromdc' which renames the domain
3126 my $backupdir = File::Temp->newdir();
3127 my $server_args = $self->get_backup_server_args($dcvars);
3128 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3129 $backup_args .= " --backend-store=tdb";
3130 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3132 unless($backup_file) {
3136 # restore the backup file to populate the rename-DC testenv
3137 my $restore_dir = abs_path($prefix);
3138 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3139 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3140 $restore_dir, $env->{SERVERCONFFILE});
3141 unless ($ret == 0) {
3145 # start samba for the restored DC
3146 if (not defined($self->check_or_start($env, "standard"))) {
3150 my $upn_array = ["$env->{REALM}.upn"];
3151 my $spn_array = ["$env->{REALM}.spn"];
3153 $self->setup_namespaces($env, $upn_array, $spn_array);
3158 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3159 # restore commands. This proves that we do an offline backup of a local DC
3160 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3161 sub setup_offlinebackupdc
3163 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3164 my ($self, $prefix, $dcvars) = @_;
3165 print "Preparing OFFLINE BACKUP DC...\n";
3167 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3170 $dcvars->{PASSWORD}, "");
3172 # create an offline backup of the 'backupfromdc' target
3173 my $backupdir = File::Temp->newdir();
3174 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3175 my $backup_file = $self->create_backup($env, $dcvars,
3178 unless($backup_file) {
3182 # restore the backup file to populate the rename-DC testenv
3183 my $restore_dir = abs_path($prefix);
3184 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3185 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3186 $restore_dir, $env->{SERVERCONFFILE});
3187 unless ($ret == 0) {
3191 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3192 Samba::mk_krb5_conf($ctx);
3194 # start samba for the restored DC
3195 if (not defined($self->check_or_start($env, "standard"))) {
3202 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3203 # restore commands, using the --no-secrets option. This proves that we can
3204 # create a realistic lab environment from an online DC ('backupfromdc').
3207 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3208 my ($self, $prefix, $dcvars) = @_;
3209 print "Preparing LAB-DOMAIN DC...\n";
3211 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3213 "labdom.samba.example.com",
3214 $dcvars->{PASSWORD}, "");
3216 # create a backup of the 'backupfromdc' which renames the domain and uses
3217 # the --no-secrets option to scrub any sensitive info
3218 my $backupdir = File::Temp->newdir();
3219 my $server_args = $self->get_backup_server_args($dcvars);
3220 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3221 $backup_args .= " --no-secrets --backend-store=mdb";
3222 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3224 unless($backup_file) {
3228 # restore the backup file to populate the lab-DC testenv
3229 my $restore_dir = abs_path($prefix);
3230 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3231 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3232 $restore_dir, $env->{SERVERCONFFILE});
3233 unless ($ret == 0) {
3237 # because we don't include any secrets in the backup, we need to reset the
3238 # admin user's password back to what the testenv expects
3239 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3240 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3241 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3242 $cmd .= " $env->{CONFIGURATION}";
3244 unless(system($cmd) == 0) {
3245 warn("Failed to reset admin's password: \n$cmd");
3249 # start samba for the restored DC
3250 if (not defined($self->check_or_start($env, "standard"))) {
3254 my $upn_array = ["$env->{REALM}.upn"];
3255 my $spn_array = ["$env->{REALM}.spn"];
3257 $self->setup_namespaces($env, $upn_array, $spn_array);
3262 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3263 sub get_backup_domain_realm
3265 my ($self, $backup_file) = @_;
3267 print "Determining REALM/DOMAIN values in backup...\n";
3269 # The backup will have the correct domain/realm values in the smb.conf.
3270 # So we can work out the env variables the testenv should use based on
3271 # that. Let's start by extracting the smb.conf
3272 my $tar = Archive::Tar->new($backup_file);
3273 my $tmpdir = File::Temp->newdir();
3274 my $smbconf = "$tmpdir/smb.conf";
3276 # note that the filepaths within the tar-file differ slightly for online
3277 # and offline backups
3278 if ($tar->contains_file("etc/smb.conf")) {
3279 $tar->extract_file("etc/smb.conf", $smbconf);
3280 } elsif ($tar->contains_file("./etc/smb.conf")) {
3281 $tar->extract_file("./etc/smb.conf", $smbconf);
3283 warn("Could not find smb.conf in $backup_file");
3284 return undef, undef;
3287 # now use testparm to read the values we're interested in
3288 my $testparm = Samba::bindir_path($self, "testparm");
3289 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3290 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3293 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3295 return ($domain, $realm);
3298 # This spins up a custom testenv that can be based on any backup-file you want.
3299 # This is just intended for manual testing (rather than automated test-cases)
3302 my ($self, $prefix) = @_;
3303 print "Preparing CUSTOM RESTORE DC...\n";
3304 my $dc_name = "customdc";
3305 my $password = "locDCpass1";
3306 my $backup_file = $ENV{'BACKUP_FILE'};
3308 # user must specify a backup file to restore via an ENV variable, i.e.
3309 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3310 if (not defined($backup_file)) {
3311 warn("Please specify BACKUP_FILE");
3315 # work out the correct domain/realm env values from the backup-file
3316 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3318 # create a placeholder directory and smb.conf, as well as the env vars.
3319 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3320 $domain, $realm, $password, "");
3322 # restore the specified backup file to populate the testenv
3323 my $restore_dir = abs_path($prefix);
3324 my $ret = $self->restore_backup_file($backup_file,
3325 "--newservername=$env->{SERVER}",
3326 $restore_dir, $env->{SERVERCONFFILE});
3327 unless ($ret == 0) {
3331 # Change the admin password to the testenv default, just in case it's
3332 # different, or in case this was a --no-secrets backup
3333 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3334 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3335 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3336 $cmd .= " $env->{CONFIGURATION}";
3338 unless(system($cmd) == 0) {
3339 warn("Failed to reset admin's password: \n$cmd");
3343 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3344 # if the backup-file was an offline backup)
3345 Samba::mk_krb5_conf($ctx);
3347 # start samba for the restored DC
3348 if (not defined($self->check_or_start($env, "standard"))) {
3352 # if this was a backup-rename, then we may need to setup namespaces
3353 my $upn_array = ["$env->{REALM}.upn"];
3354 my $spn_array = ["$env->{REALM}.spn"];
3356 $self->setup_namespaces($env, $upn_array, $spn_array);
3363 my ($self, $path) = @_;
3366 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",