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};
150 $ENV{UID_WRAPPER} = "1";
151 $ENV{UID_WRAPPER_ROOT} = "1";
153 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
156 if (defined($ENV{SAMBA_OPTIONS})) {
157 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
159 if(defined($ENV{SAMBA_VALGRIND})) {
160 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
163 close($env_vars->{STDIN_PIPE});
164 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
166 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: $!");
168 $env_vars->{SAMBA_PID} = $pid;
169 print "DONE ($pid)\n";
171 close($STDIN_READER);
173 if ($self->wait_for_start($env_vars) != 0) {
174 warn("Samba $pid failed to start up");
181 sub wait_for_start($$)
183 my ($self, $testenv_vars) = @_;
187 if (not $self->check_env($testenv_vars)) {
188 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
192 # This will return quickly when things are up, but be slow if we
193 # need to wait for (eg) SSL init
194 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
197 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
201 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
204 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
207 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
208 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
209 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
210 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
211 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
214 } while ($ret != 0 && $count < 20);
216 warn("nbt not reachable after 20 retries\n");
217 teardown_env($self, $testenv_vars);
221 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
222 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
223 print "waiting for working LDAP and a RID Set to be allocated\n";
224 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
226 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
228 my $search_dn = $base_dn;
229 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
230 # TODO currently no check for actual rIDAllocationPool
231 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
235 # Add hosts file for name lookups
236 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
237 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
238 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
240 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
243 $cmd .= "$ldbsearch ";
244 $cmd .= "$testenv_vars->{CONFIGURATION} ";
245 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
246 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
248 $cmd .= "-b '$search_dn' ";
249 while (system("$cmd >/dev/null") != 0) {
251 if ($count > $max_wait) {
252 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}");
260 my $wbinfo = Samba::bindir_path($self, "wbinfo");
264 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
265 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
266 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
267 $cmd .= "$wbinfo -P";
274 } while ($ret != 0 && $count < 20);
276 warn("winbind not reachable after 20 retries\n");
277 teardown_env($self, $testenv_vars);
281 print $self->getlog_env($testenv_vars);
286 sub write_ldb_file($$$)
288 my ($self, $file, $ldif) = @_;
290 my $ldbadd = Samba::bindir_path($self, "ldbadd");
291 open(LDIF, "|$ldbadd -H $file >/dev/null");
296 sub add_wins_config($$)
298 my ($self, $privatedir) = @_;
300 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
301 dn: name=TORTURE_11,CN=PARTNERS
302 objectClass: wreplPartner
313 my ($self, $ctx) = @_;
315 #Make the subdirectory be as fedora DS would expect
316 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
318 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
320 return ($fedora_ds_dir, $pidfile);
325 my ($self, $ctx) = @_;
327 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
328 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
330 return ($slapd_conf_d, $pidfile);
333 sub setup_dns_hub_internal($$$)
335 my ($self, $hostname, $prefix) = @_;
338 unless(-d $prefix or make_path($prefix, 0777)) {
339 warn("Unable to create $prefix");
342 my $prefix_abs = abs_path($prefix);
344 die ("prefix=''") if $prefix_abs eq "";
345 die ("prefix='/'") if $prefix_abs eq "/";
347 unless (system("rm -rf $prefix_abs/*") == 0) {
348 warn("Unable to clean up");
351 my $swiface = Samba::get_interface($hostname);
354 $env->{prefix} = $prefix;
355 $env->{prefix_abs} = $prefix_abs;
357 $env->{hostname} = $hostname;
358 $env->{swiface} = $swiface;
360 $env->{ipv4} = "127.0.0.$swiface";
361 $env->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
363 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
365 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
367 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
368 print RESOLV_CONF "nameserver $env->{ipv4}\n";
369 print RESOLV_CONF "nameserver $env->{ipv6}\n";
372 # use a pipe for stdin in the child processes. This allows
373 # those processes to monitor the pipe for EOF to ensure they
374 # exit when the test script exits
375 pipe($STDIN_READER, $env->{STDIN_PIPE});
377 print "STARTING rootdnsforwarder...\n";
380 # we want out from samba to go to the log file, but also
381 # to the users terminal when running 'make test' on the command
382 # line. This puts it on stderr on the terminal
383 open STDOUT, "| tee $env->{DNS_HUB_LOG} 1>&2";
384 open STDERR, '>&STDOUT';
386 SocketWrapper::set_default_iface($swiface);
387 my $pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap";
388 SocketWrapper::setup_pcap($pcap_file);
393 if (!defined($ENV{PYTHON})) {
394 push (@preargs, "env");
395 push (@preargs, "python");
397 push (@preargs, $ENV{PYTHON});
399 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "python/samba/tests/dns_forwarder_helpers/dns_hub.py");
400 push (@args, "$self->{server_maxtime}");
401 push (@args, "$env->{ipv4}");
402 close($env->{STDIN_PIPE});
403 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
405 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
406 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
408 $env->{SAMBA_PID} = $pid;
409 $env->{KRB5_CONFIG} = "${prefix_abs}/no_krb5.conf";
410 close($STDIN_READER);
418 my ($self, $prefix) = @_;
420 my $hostname = "rootdnsforwarder";
422 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
424 $self->{dns_hub_env} = $env;
429 sub get_dns_hub_env($)
431 my ($self, $prefix) = @_;
433 if (defined($self->{dns_hub_env})) {
434 return $self->{dns_hub_env};
437 die("get_dns_hub_env() not setup 'dns_hub_env'");
441 sub setup_namespaces($$:$$)
443 my ($self, $localenv, $upn_array, $spn_array) = @_;
445 @{$upn_array} = [] unless defined($upn_array);
447 foreach my $upn (@{$upn_array}) {
448 $upn_args .= " --add-upn-suffix=$upn";
451 @{$spn_array} = [] unless defined($spn_array);
453 foreach my $spn (@{$spn_array}) {
454 $spn_args .= " --add-spn-suffix=$spn";
457 my $samba_tool = Samba::bindir_path($self, "samba-tool");
459 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
460 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
461 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
462 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
464 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
466 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
467 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
469 my $cmd_config = " $localenv->{CONFIGURATION}";
471 my $namespaces = $cmd_env;
472 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
473 $namespaces .= $cmd_config;
474 unless (system($namespaces) == 0) {
475 warn("Failed to add namespaces \n$namespaces");
482 sub setup_trust($$$$$)
484 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
486 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
487 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
488 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
489 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
490 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
491 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
492 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
493 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
494 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
496 my $samba_tool = Samba::bindir_path($self, "samba-tool");
499 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
500 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
501 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
502 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
504 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
506 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
507 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
509 my $cmd_config = " $localenv->{CONFIGURATION}";
510 my $cmd_creds = $cmd_config;
511 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
513 my $create = $cmd_env;
514 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
515 $create .= " $extra_args";
516 $create .= $cmd_creds;
517 unless (system($create) == 0) {
518 warn("Failed to create trust \n$create");
522 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
523 my $groupadd = $cmd_env;
524 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
525 unless (system($groupadd) == 0) {
526 warn("Failed to create group \n$groupadd");
529 my $groupmem = $cmd_env;
530 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
531 unless (system($groupmem) == 0) {
532 warn("Failed to add group member \n$groupmem");
539 sub provision_raw_prepare($$$$$$$$$$$$)
541 my ($self, $prefix, $server_role, $hostname,
542 $domain, $realm, $samsid, $functional_level,
543 $password, $kdc_ipv4, $kdc_ipv6) = @_;
546 if (defined $ENV{PYTHON}) {
547 $python_cmd = $ENV{PYTHON} . " ";
549 $ctx->{python} = $python_cmd;
550 my $netbiosname = uc($hostname);
552 unless(-d $prefix or mkdir($prefix, 0777)) {
553 warn("Unable to create $prefix");
556 my $prefix_abs = abs_path($prefix);
558 die ("prefix=''") if $prefix_abs eq "";
559 die ("prefix='/'") if $prefix_abs eq "/";
561 unless (system("rm -rf $prefix_abs/*") == 0) {
562 warn("Unable to clean up");
566 my $swiface = Samba::get_interface($hostname);
568 $ctx->{prefix} = $prefix;
569 $ctx->{prefix_abs} = $prefix_abs;
571 $ctx->{server_role} = $server_role;
572 $ctx->{hostname} = $hostname;
573 $ctx->{netbiosname} = $netbiosname;
574 $ctx->{swiface} = $swiface;
575 $ctx->{password} = $password;
576 $ctx->{kdc_ipv4} = $kdc_ipv4;
577 $ctx->{kdc_ipv6} = $kdc_ipv6;
578 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
579 if ($functional_level eq "2000") {
580 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
584 # Set smbd log level here.
586 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
587 $ctx->{username} = "Administrator";
588 $ctx->{domain} = $domain;
589 $ctx->{realm} = uc($realm);
590 $ctx->{dnsname} = lc($realm);
591 $ctx->{samsid} = $samsid;
593 $ctx->{functional_level} = $functional_level;
595 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
597 $ctx->{unix_name} = $unix_name;
598 $ctx->{unix_uid} = $>;
599 my @mygid = split(" ", $();
600 $ctx->{unix_gid} = $mygid[0];
601 $ctx->{unix_gids_str} = $);
602 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
604 $ctx->{etcdir} = "$prefix_abs/etc";
605 $ctx->{piddir} = "$prefix_abs/pid";
606 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
607 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
608 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
609 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
610 $ctx->{privatedir} = "$prefix_abs/private";
611 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
612 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
613 $ctx->{lockdir} = "$prefix_abs/lockdir";
614 $ctx->{logdir} = "$prefix_abs/logs";
615 $ctx->{statedir} = "$prefix_abs/statedir";
616 $ctx->{cachedir} = "$prefix_abs/cachedir";
617 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
618 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
619 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
620 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
621 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
622 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
623 if ($ENV{SAMBA_DNS_FAKING}) {
624 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
625 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
626 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
628 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
629 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
630 $ctx->{use_resolv_wrapper} = 1;
632 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
634 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
636 $ctx->{ipv4} = "127.0.0.$swiface";
637 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
638 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
640 push(@{$ctx->{directories}}, $ctx->{privatedir});
641 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
642 push(@{$ctx->{directories}}, $ctx->{etcdir});
643 push(@{$ctx->{directories}}, $ctx->{piddir});
644 push(@{$ctx->{directories}}, $ctx->{lockdir});
645 push(@{$ctx->{directories}}, $ctx->{logdir});
646 push(@{$ctx->{directories}}, $ctx->{statedir});
647 push(@{$ctx->{directories}}, $ctx->{cachedir});
649 $ctx->{smb_conf_extra_options} = "";
651 my @provision_options = ();
652 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
653 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
654 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
655 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
656 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
657 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
658 if (defined($ctx->{use_resolv_wrapper})) {
659 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
661 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
663 if (defined($ENV{GDB_PROVISION})) {
664 push (@provision_options, "gdb --args");
665 if (!defined($ENV{PYTHON})) {
666 push (@provision_options, "env");
667 push (@provision_options, "python");
670 if (defined($ENV{VALGRIND_PROVISION})) {
671 push (@provision_options, "valgrind");
672 if (!defined($ENV{PYTHON})) {
673 push (@provision_options, "env");
674 push (@provision_options, "python");
678 my $samba_tool = Samba::bindir_path($self, "samba-tool");
680 push (@provision_options, $samba_tool);
681 push (@provision_options, "domain");
682 push (@provision_options, "provision");
683 push (@provision_options, "--configfile=$ctx->{smb_conf}");
684 push (@provision_options, "--host-name=$ctx->{hostname}");
685 push (@provision_options, "--host-ip=$ctx->{ipv4}");
686 push (@provision_options, "--quiet");
687 push (@provision_options, "--domain=$ctx->{domain}");
688 push (@provision_options, "--realm=$ctx->{realm}");
689 if (defined($ctx->{samsid})) {
690 push (@provision_options, "--domain-sid=$ctx->{samsid}");
692 push (@provision_options, "--adminpass=$ctx->{password}");
693 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
694 push (@provision_options, "--machinepass=machine$ctx->{password}");
695 push (@provision_options, "--root=$ctx->{unix_name}");
696 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
697 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
699 @{$ctx->{provision_options}} = @provision_options;
706 my ($self, $keyword, @options_list) = @_;
708 # convert the options-list to a hash-map for easy keyword lookup
709 my %options_dict = map { $_ => 1 } @options_list;
711 return exists $options_dict{$keyword};
715 # Step1 creates the basic configuration
717 sub provision_raw_step1($$)
719 my ($self, $ctx) = @_;
721 mkdir($_, 0777) foreach (@{$ctx->{directories}});
724 ## lockdir and piddir must be 0755
726 chmod 0755, $ctx->{lockdir};
727 chmod 0755, $ctx->{piddir};
729 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
730 warn("can't open $ctx->{smb_conf}$?");
734 Samba::prepare_keyblobs($ctx);
735 my $crlfile = "$ctx->{tlsdir}/crl.pem";
736 $crlfile = "" unless -e ${crlfile};
738 # work out which file server to use. Default to source3 smbd (s3fs),
739 # unless the source4 NTVFS (smb) file server has been specified
740 my $services = "-smb +s3fs";
741 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
742 $services = "+smb -s3fs";
747 netbios name = $ctx->{netbiosname}
748 posix:eadb = $ctx->{statedir}/eadb.tdb
749 workgroup = $ctx->{domain}
750 realm = $ctx->{realm}
751 private dir = $ctx->{privatedir}
752 binddns dir = $ctx->{binddnsdir}
753 pid directory = $ctx->{piddir}
754 ncalrpc dir = $ctx->{ncalrpcdir}
755 lock dir = $ctx->{lockdir}
756 state directory = $ctx->{statedir}
757 cache directory = $ctx->{cachedir}
758 winbindd socket directory = $ctx->{winbindd_socket_dir}
759 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
760 winbind separator = /
761 interfaces = $ctx->{interfaces}
762 tls dh params file = $ctx->{tlsdir}/dhparms.pem
763 tls crlfile = ${crlfile}
764 tls verify peer = no_check
765 panic action = $RealBin/gdb_backtrace \%d
767 server role = $ctx->{server_role}
768 server services = +echo $services
769 dcerpc endpoint servers = +winreg +srvsvc
770 notify:inotify = false
772 ldap server require strong auth = yes
773 #We don't want to pass our self-tests if the PAC code is wrong
774 gensec:require_pac = true
775 log file = $ctx->{logdir}/log.\%m
776 log level = $ctx->{server_loglevel}
780 dns update command = $ctx->{samba_dnsupdate}
781 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
782 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
783 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
784 dreplsrv:periodic_startup_interval = 0
785 dsdb:schema update allowed = yes
789 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
791 idmap_ldb:use rfc2307=yes
792 winbind enum users = yes
793 winbind enum groups = yes
795 rpc server port:netlogon = 1026
801 # Begin extra options
802 $ctx->{smb_conf_extra_options}
807 #Default the KDC IP to the server's IP
808 if (not defined($ctx->{kdc_ipv4})) {
809 $ctx->{kdc_ipv4} = $ctx->{ipv4};
811 if (not defined($ctx->{kdc_ipv6})) {
812 $ctx->{kdc_ipv6} = $ctx->{ipv6};
815 Samba::mk_krb5_conf($ctx);
816 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
818 open(PWD, ">$ctx->{nsswrap_passwd}");
819 if ($ctx->{unix_uid} != 0) {
820 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
822 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
823 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
824 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
825 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
826 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
827 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
830 my $uid_rfc2307test = 65533;
832 open(GRP, ">$ctx->{nsswrap_group}");
833 if ($ctx->{unix_gid} != 0) {
834 print GRP "root:x:0:\n";
836 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
837 print GRP "wheel:x:10:
840 nogroup:x:65534:nobody
843 my $gid_rfc2307test = 65532;
845 my $hostname = lc($ctx->{hostname});
846 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
847 if ($hostname eq "localdc") {
848 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
849 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
851 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
852 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
856 if (defined($ctx->{resolv_conf})) {
857 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
858 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
859 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\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 .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1287 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1288 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1290 unless (system($cmd) == 0) {
1291 warn("Join failed\n$cmd");
1295 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1296 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1297 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1298 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1299 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1300 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1302 $ret->{DOMSID} = $dcvars->{DOMSID};
1303 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1304 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1305 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1306 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1307 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1308 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1313 sub provision_rpc_proxy($$$)
1315 my ($self, $prefix, $dcvars) = @_;
1316 print "PROVISIONING RPC PROXY...\n";
1318 my $extra_smbconf_options = "
1319 passdb backend = samba_dsdb
1322 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1323 dcerpc endpoint servers = epmapper, remote
1324 dcerpc_remote:interfaces = rpcecho
1325 dcerpc_remote:allow_anonymous_fallback = yes
1328 path = /tmp/_ignore_cifs_to_dc_/_none_
1330 ntvfs handler = cifs
1331 cifs:server = $dcvars->{SERVER}
1333 cifs:use-s4u2proxy = yes
1334 # There is no username specified here, instead the client is expected
1335 # to log in with kerberos, and the serverwill use delegated credentials.
1336 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1340 my $extra_provision_options = ["--use-ntvfs"];
1341 my $ret = $self->provision($prefix,
1348 $dcvars->{SERVER_IP},
1349 $dcvars->{SERVER_IPV6},
1350 $extra_smbconf_options, "",
1351 $extra_provision_options);
1356 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1358 # The joind runs in the context of the rpc_proxy/member for now
1359 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1360 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1361 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1362 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1364 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1366 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1367 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1368 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1369 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1370 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1372 unless (system($cmd) == 0) {
1373 warn("Join failed\n$cmd");
1377 # Setting up delegation runs in the context of the DC for now
1379 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1380 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1381 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1382 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1383 $cmd .= " $dcvars->{CONFIGURATION}";
1386 unless (system($cmd) == 0) {
1387 warn("Delegation failed\n$cmd");
1391 # Setting up delegation runs in the context of the DC for now
1393 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1394 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1395 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1396 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1397 $cmd .= " $dcvars->{CONFIGURATION}";
1399 unless (system($cmd) == 0) {
1400 warn("Delegation failed\n$cmd");
1404 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1405 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1406 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1407 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1408 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1409 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1411 $ret->{DOMSID} = $dcvars->{DOMSID};
1412 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1413 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1414 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1415 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1416 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1417 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1422 sub provision_promoted_dc($$$)
1424 my ($self, $prefix, $dcvars) = @_;
1425 print "PROVISIONING PROMOTED DC...\n";
1427 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1428 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1434 $dcvars->{PASSWORD},
1435 $dcvars->{SERVER_IP},
1436 $dcvars->{SERVER_IPV6});
1438 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1440 $ctx->{smb_conf_extra_options} = "
1442 server max protocol = SMB2
1444 ntlm auth = ntlmv2-only
1447 path = $ctx->{statedir}/sysvol
1451 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1456 my $ret = $self->provision_raw_step1($ctx);
1461 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1462 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1463 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1464 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1465 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1467 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1469 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1470 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1471 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1472 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1473 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1475 unless (system($cmd) == 0) {
1476 warn("Join failed\n$cmd");
1480 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1481 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1482 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1483 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1484 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1486 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1488 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1489 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1490 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1491 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1492 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1494 unless (system($cmd) == 0) {
1495 warn("Join failed\n$cmd");
1499 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1500 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1501 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1502 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1504 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1505 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1506 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1507 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1508 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1509 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1514 sub provision_vampire_dc($$$)
1516 my ($self, $prefix, $dcvars, $fl) = @_;
1517 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1518 my $name = "localvampiredc";
1519 my $extra_conf = "";
1521 if ($fl == "2000") {
1522 $name = "vampire2000dc";
1524 $extra_conf = "drs: immediate link sync = yes
1525 drs: max link sync = 250";
1528 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1529 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1535 $dcvars->{PASSWORD},
1536 $dcvars->{SERVER_IP},
1537 $dcvars->{SERVER_IPV6});
1539 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1541 $ctx->{smb_conf_extra_options} = "
1543 server max protocol = SMB2
1545 ntlm auth = mschapv2-and-ntlmv2-only
1549 path = $ctx->{statedir}/sysvol
1553 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1558 my $ret = $self->provision_raw_step1($ctx);
1563 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1564 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1565 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1566 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1567 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1569 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1571 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1572 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1573 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1574 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1575 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1576 $cmd .= " --backend-store=mdb";
1578 unless (system($cmd) == 0) {
1579 warn("Join failed\n$cmd");
1583 if ($fl == "2000") {
1584 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1585 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1586 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1587 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1589 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1590 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1591 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1592 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1594 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1595 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1596 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1597 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1598 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1599 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1600 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1605 sub provision_subdom_dc($$$)
1607 my ($self, $prefix, $dcvars) = @_;
1608 print "PROVISIONING SUBDOMAIN DC...\n";
1610 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1611 my $samsid = undef; # TODO pass the domain sid all the way down
1612 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1615 "sub.samba.example.com",
1618 $dcvars->{PASSWORD},
1621 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1623 $ctx->{smb_conf_extra_options} = "
1625 server max protocol = SMB2
1628 path = $ctx->{statedir}/sysvol
1632 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1637 my $ret = $self->provision_raw_step1($ctx);
1642 Samba::mk_krb5_conf($ctx);
1643 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1645 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1646 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1647 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1648 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1649 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1651 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1653 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1654 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1655 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1656 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1657 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1658 $cmd .= " --adminpass=$ret->{PASSWORD}";
1660 unless (system($cmd) == 0) {
1661 warn("Join failed\n$cmd");
1665 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1666 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1667 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1668 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1670 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1671 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1672 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1673 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1674 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1675 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1680 sub provision_ad_dc_ntvfs($$)
1682 my ($self, $prefix) = @_;
1684 # We keep the old 'winbind' name here in server services to
1685 # ensure upgrades which used that name still work with the now
1688 print "PROVISIONING AD DC (NTVFS)...\n";
1689 my $extra_conf_options = "netbios aliases = localDC1-a
1690 server services = +winbind -winbindd
1691 ldap server require strong auth = allow_sasl_over_tls
1692 allow nt4 crypto = yes
1693 raw NTLMv2 auth = yes
1694 lsa over netlogon = yes
1695 rpc server port = 1027
1696 auth event notification = true
1697 dsdb event notification = true
1698 dsdb password event notification = true
1699 dsdb group change notification = true
1700 server schannel = auto
1702 my $extra_provision_options = ["--use-ntvfs"];
1703 my $ret = $self->provision($prefix,
1704 "domain controller",
1707 "samba.example.com",
1712 $extra_conf_options,
1714 $extra_provision_options);
1719 unless($self->add_wins_config("$prefix/private")) {
1720 warn("Unable to add wins configuration");
1723 $ret->{NETBIOSALIAS} = "localdc1-a";
1724 $ret->{DC_SERVER} = $ret->{SERVER};
1725 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1726 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1727 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1728 $ret->{DC_USERNAME} = $ret->{USERNAME};
1729 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1730 $ret->{DC_REALM} = $ret->{REALM};
1735 sub provision_fl2000dc($$)
1737 my ($self, $prefix) = @_;
1739 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1740 my $extra_conf_options = "
1741 spnego:simulate_w2k=yes
1742 ntlmssp_server:force_old_spnego=yes
1744 my $extra_provision_options = ["--use-ntvfs"];
1745 # This environment uses plain text secrets
1746 # i.e. secret attributes are not encrypted on disk.
1747 # This allows testing of the --plaintext-secrets option for
1749 push (@{$extra_provision_options}, "--plaintext-secrets");
1750 my $ret = $self->provision($prefix,
1751 "domain controller",
1754 "samba2000.example.com",
1759 $extra_conf_options,
1761 $extra_provision_options);
1766 unless($self->add_wins_config("$prefix/private")) {
1767 warn("Unable to add wins configuration");
1770 $ret->{DC_SERVER} = $ret->{SERVER};
1771 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1772 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1773 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1774 $ret->{DC_USERNAME} = $ret->{USERNAME};
1775 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1776 $ret->{DC_REALM} = $ret->{REALM};
1781 sub provision_fl2003dc($$$)
1783 my ($self, $prefix, $dcvars) = @_;
1784 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1785 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1787 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1788 my $extra_conf_options = "allow dns updates = nonsecure and secure
1789 dcesrv:header signing = no
1790 dcesrv:max auth states = 0
1791 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1792 my $extra_provision_options = ["--use-ntvfs"];
1793 my $ret = $self->provision($prefix,
1794 "domain controller",
1797 "samba2003.example.com",
1802 $extra_conf_options,
1804 $extra_provision_options);
1805 unless (defined $ret) {
1809 $ret->{DC_SERVER} = $ret->{SERVER};
1810 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1811 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1812 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1813 $ret->{DC_USERNAME} = $ret->{USERNAME};
1814 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1815 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1816 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1818 my @samba_tool_options;
1819 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1820 push (@samba_tool_options, "domain");
1821 push (@samba_tool_options, "passwordsettings");
1822 push (@samba_tool_options, "set");
1823 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1824 push (@samba_tool_options, "--min-pwd-age=0");
1825 push (@samba_tool_options, "--history-length=1");
1827 my $samba_tool_cmd = join(" ", @samba_tool_options);
1829 unless (system($samba_tool_cmd) == 0) {
1830 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1834 unless($self->add_wins_config("$prefix/private")) {
1835 warn("Unable to add wins configuration");
1842 sub provision_fl2008r2dc($$$)
1844 my ($self, $prefix, $dcvars) = @_;
1846 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1847 my $extra_conf_options = "ldap server require strong auth = no";
1848 my $extra_provision_options = ["--use-ntvfs"];
1849 my $ret = $self->provision($prefix,
1850 "domain controller",
1853 "samba2008R2.example.com",
1858 $extra_conf_options,
1860 $extra_provision_options);
1861 unless (defined $ret) {
1865 unless ($self->add_wins_config("$prefix/private")) {
1866 warn("Unable to add wins configuration");
1869 $ret->{DC_SERVER} = $ret->{SERVER};
1870 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1871 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1872 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1873 $ret->{DC_USERNAME} = $ret->{USERNAME};
1874 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1875 $ret->{DC_REALM} = $ret->{REALM};
1881 sub provision_rodc($$$)
1883 my ($self, $prefix, $dcvars) = @_;
1884 print "PROVISIONING RODC...\n";
1886 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1887 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1893 $dcvars->{PASSWORD},
1894 $dcvars->{SERVER_IP},
1895 $dcvars->{SERVER_IPV6});
1900 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1902 $ctx->{share} = "$ctx->{prefix_abs}/share";
1903 push(@{$ctx->{directories}}, "$ctx->{share}");
1905 $ctx->{smb_conf_extra_options} = "
1907 server max protocol = SMB2
1908 password server = $dcvars->{DC_SERVER}
1911 path = $ctx->{statedir}/sysvol
1915 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1919 path = $ctx->{share}
1921 posix:sharedelay = 10000
1922 posix:oplocktimeout = 3
1923 posix:writetimeupdatedelay = 50000
1927 my $ret = $self->provision_raw_step1($ctx);
1932 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1933 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1934 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1935 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1936 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1938 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1940 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1941 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1942 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1943 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1944 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1946 unless (system($cmd) == 0) {
1947 warn("RODC join failed\n$cmd");
1951 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1952 # user password verified on the RODC
1953 my $testallowed_account = "testallowed account";
1954 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1955 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1956 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1957 $cmd .= " --server=$dcvars->{DC_SERVER}";
1959 unless (system($cmd) == 0) {
1960 warn("RODC join failed\n$cmd");
1964 # we overwrite the kdc after the RODC join
1965 # so that use the RODC as kdc and test
1967 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1968 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1969 Samba::mk_krb5_conf($ctx);
1970 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1972 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1973 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1974 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1975 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1977 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1978 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1979 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1980 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1981 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1982 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1987 sub read_config_h($)
1991 open(LF, "<$name") or die("unable to read $name: $!");
1994 next if not (/^#define /);
1995 if (/^#define (.*?)[ \t]+(.*?)$/) {
1999 if (/^#define (.*?)[ \t]+$/) {
2008 sub provision_ad_dc($$$$$$)
2010 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
2011 $extra_provision_options) = @_;
2013 my $prefix_abs = abs_path($prefix);
2015 my $bindir_abs = abs_path($self->{bindir});
2016 my $lockdir="$prefix_abs/lockdir";
2017 my $conffile="$prefix_abs/etc/smb.conf";
2019 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
2020 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
2024 if (defined($ENV{CONFIG_H})) {
2025 $config_h = read_config_h($ENV{CONFIG_H});
2028 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
2029 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
2031 my $extra_smbconf_options = "
2032 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
2034 dbwrap_tdb_mutexes:* = yes
2037 ${password_hash_gpg_key_ids}
2040 kernel change notify = no
2045 printcap name = /dev/null
2050 smbd:sharedelay = 100000
2051 smbd:writetimeupdatedelay = 500000
2054 check parent directory delete on close = yes
2056 dcerpc endpoint servers = -winreg -srvsvc
2058 printcap name = /dev/null
2060 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
2061 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
2064 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
2065 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
2066 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
2067 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
2068 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
2069 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
2070 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
2072 print notify backchannel = yes
2074 server schannel = auto
2075 auth event notification = true
2076 dsdb event notification = true
2077 dsdb password event notification = true
2078 dsdb group change notification = true
2082 my $extra_smbconf_shares = "
2086 smb encrypt = required
2090 case sensitive = yes
2098 hide unreadable = yes
2102 kernel share modes = no
2121 push (@{$extra_provision_options}, "--backend-store=mdb");
2122 print "PROVISIONING AD DC...\n";
2123 my $ret = $self->provision($prefix,
2124 "domain controller",
2132 $extra_smbconf_options,
2133 $extra_smbconf_shares,
2134 $extra_provision_options);
2135 unless (defined $ret) {
2139 unless($self->add_wins_config("$prefix/private")) {
2140 warn("Unable to add wins configuration");
2144 $ret->{DC_SERVER} = $ret->{SERVER};
2145 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2146 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2147 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2148 $ret->{DC_USERNAME} = $ret->{USERNAME};
2149 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2154 sub provision_chgdcpass($$)
2156 my ($self, $prefix) = @_;
2158 print "PROVISIONING CHGDCPASS...\n";
2159 # This environment disallows the use of this password
2160 # (and also removes the default AD complexity checks)
2161 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2162 my $extra_smb_conf = "
2163 check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'
2164 allow dcerpc auth level connect:lsarpc = yes
2165 dcesrv:max auth states = 8
2167 my $extra_provision_options = ["--use-ntvfs"];
2168 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2169 my $ret = $self->provision($prefix,
2170 "domain controller",
2173 "chgdcpassword.samba.example.com",
2180 $extra_provision_options);
2181 unless (defined $ret) {
2185 unless($self->add_wins_config("$prefix/private")) {
2186 warn("Unable to add wins configuration");
2190 # Remove secrets.tdb from this environment to test that we
2191 # still start up on systems without the new matching
2192 # secrets.tdb records.
2193 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2194 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2198 $ret->{DC_SERVER} = $ret->{SERVER};
2199 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2200 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2201 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2202 $ret->{DC_USERNAME} = $ret->{USERNAME};
2203 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2204 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2209 sub teardown_env_terminate($$)
2211 my ($self, $envvars) = @_;
2214 # This should cause samba to terminate gracefully
2215 close($envvars->{STDIN_PIPE});
2217 $pid = $envvars->{SAMBA_PID};
2221 # This should give it time to write out the gcov data
2222 until ($count > 15) {
2223 if (Samba::cleanup_child($pid, "samba") != 0) {
2230 # After 15 Seconds, work out why this thing is still alive
2231 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2232 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2234 until ($count > 30) {
2235 if (Samba::cleanup_child($pid, "samba") != 0) {
2242 if (kill(0, $pid)) {
2243 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2247 until ($count > 40) {
2248 if (Samba::cleanup_child($pid, "samba") != 0) {
2254 # If it is still around, kill it
2255 if (kill(0, $pid)) {
2256 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2262 sub teardown_env($$)
2264 my ($self, $envvars) = @_;
2265 teardown_env_terminate($self, $envvars);
2267 $self->slapd_stop($envvars) if ($self->{ldap});
2269 print $self->getlog_env($envvars);
2276 my ($self, $envvars) = @_;
2277 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2280 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2282 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2286 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2289 return "" if $out eq $title;
2296 my ($self, $envvars) = @_;
2297 my $samba_pid = $envvars->{SAMBA_PID};
2299 if (not defined($samba_pid)) {
2301 } elsif ($samba_pid > 0) {
2302 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2304 if ($childpid == 0) {
2313 # Declare the environments Samba4 makes available.
2314 # To be set up, they will be called as
2315 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2316 %Samba4::ENV_DEPS = (
2317 # name => [dep_1, dep_2, ...],
2321 ad_dc_no_ntlm => [],
2324 preforkrestartdc => [],
2326 fl2008r2dc => ["ad_dc"],
2327 fl2003dc => ["ad_dc"],
2330 vampire_2000_dc => ["fl2000dc"],
2331 vampire_dc => ["ad_dc_ntvfs"],
2332 promoted_dc => ["ad_dc_ntvfs"],
2333 subdom_dc => ["ad_dc_ntvfs"],
2335 rodc => ["ad_dc_ntvfs"],
2336 rpc_proxy => ["ad_dc_ntvfs"],
2339 s4member_dflt_domain => ["ad_dc_ntvfs"],
2340 s4member => ["ad_dc_ntvfs"],
2342 restoredc => ["backupfromdc"],
2343 renamedc => ["backupfromdc"],
2344 offlinebackupdc => ["backupfromdc"],
2345 labdc => ["backupfromdc"],
2353 my ($self, $path, $dc_vars) = @_;
2355 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2358 if (not defined($self->check_or_start($env, "standard"))) {
2366 sub setup_s4member_dflt_domain
2368 my ($self, $path, $dc_vars) = @_;
2370 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2371 "winbind use default domain = yes");
2374 if (not defined($self->check_or_start($env, "standard"))) {
2384 my ($self, $path, $dc_vars) = @_;
2386 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2389 if (not defined($self->check_or_start($env, "standard"))) {
2396 sub setup_ad_dc_ntvfs
2398 my ($self, $path) = @_;
2400 my $env = $self->provision_ad_dc_ntvfs($path);
2402 if (not defined($self->check_or_start($env, "standard"))) {
2403 warn("Failed to start ad_dc_ntvfs");
2412 my ($self, $path) = @_;
2414 my $env = $self->provision_chgdcpass($path);
2416 if (not defined($self->check_or_start($env, "standard"))) {
2425 my ($self, $path) = @_;
2427 my $env = $self->provision_fl2000dc($path);
2429 if (not defined($self->check_or_start($env, "standard"))) {
2439 my ($self, $path, $dc_vars) = @_;
2441 my $env = $self->provision_fl2003dc($path);
2444 if (not defined($self->check_or_start($env, "standard"))) {
2448 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2453 sub setup_fl2008r2dc
2455 my ($self, $path, $dc_vars) = @_;
2457 my $env = $self->provision_fl2008r2dc($path);
2460 if (not defined($self->check_or_start($env, "standard"))) {
2464 my $upn_array = ["$env->{REALM}.upn"];
2465 my $spn_array = ["$env->{REALM}.spn"];
2467 $self->setup_namespaces($env, $upn_array, $spn_array);
2469 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2475 sub setup_vampire_dc
2477 return setup_generic_vampire_dc(@_, "2008");
2480 sub setup_vampire_2000_dc
2482 return setup_generic_vampire_dc(@_, "2000");
2485 sub setup_generic_vampire_dc
2487 my ($self, $path, $dc_vars, $fl) = @_;
2489 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2492 if (not defined($self->check_or_start($env, "single"))) {
2496 # force replicated DC to update repsTo/repsFrom
2497 # for vampired partitions
2498 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2500 # as 'vampired' dc may add data in its local replica
2501 # we need to synchronize data between DCs
2502 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2503 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2504 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2505 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2506 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2508 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2510 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2511 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2512 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2513 $cmd .= " $dc_vars->{CONFIGURATION}";
2514 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2515 # replicate Configuration NC
2516 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2517 unless(system($cmd_repl) == 0) {
2518 warn("Failed to replicate\n$cmd_repl");
2521 # replicate Default NC
2522 $cmd_repl = "$cmd \"$base_dn\"";
2523 unless(system($cmd_repl) == 0) {
2524 warn("Failed to replicate\n$cmd_repl");
2528 # Pull in a full set of changes from the main DC
2529 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2530 $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2531 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2532 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2533 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2535 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2537 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2538 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2539 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2540 $cmd .= " $dc_vars->{CONFIGURATION}";
2541 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2542 # replicate Configuration NC
2543 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2544 unless(system($cmd_repl) == 0) {
2545 warn("Failed to replicate\n$cmd_repl");
2548 # replicate Default NC
2549 $cmd_repl = "$cmd \"$base_dn\"";
2550 unless(system($cmd_repl) == 0) {
2551 warn("Failed to replicate\n$cmd_repl");
2559 sub setup_promoted_dc
2561 my ($self, $path, $dc_vars) = @_;
2563 my $env = $self->provision_promoted_dc($path, $dc_vars);
2566 if (not defined($self->check_or_start($env, "single"))) {
2570 # force source and replicated DC to update repsTo/repsFrom
2571 # for vampired partitions
2572 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2573 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2574 # as 'vampired' dc may add data in its local replica
2575 # we need to synchronize data between DCs
2576 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2577 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2578 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2579 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2580 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2581 $cmd .= " $dc_vars->{CONFIGURATION}";
2582 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2583 # replicate Configuration NC
2584 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2585 unless(system($cmd_repl) == 0) {
2586 warn("Failed to replicate\n$cmd_repl");
2589 # replicate Default NC
2590 $cmd_repl = "$cmd \"$base_dn\"";
2591 unless(system($cmd_repl) == 0) {
2592 warn("Failed to replicate\n$cmd_repl");
2602 my ($self, $path, $dc_vars) = @_;
2604 my $env = $self->provision_subdom_dc($path, $dc_vars);
2607 if (not defined($self->check_or_start($env, "single"))) {
2611 # force replicated DC to update repsTo/repsFrom
2612 # for primary domain partitions
2613 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2614 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2615 # as 'subdomain' dc may add data in its local replica
2616 # we need to synchronize data between DCs
2617 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2618 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2619 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2620 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2621 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2622 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2623 $cmd .= " $dc_vars->{CONFIGURATION}";
2624 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2625 # replicate Configuration NC
2626 my $cmd_repl = "$cmd \"$config_dn\"";
2627 unless(system($cmd_repl) == 0) {
2628 warn("Failed to replicate\n$cmd_repl");
2631 # replicate Default NC
2632 $cmd_repl = "$cmd \"$base_dn\"";
2633 unless(system($cmd_repl) == 0) {
2634 warn("Failed to replicate\n$cmd_repl");
2644 my ($self, $path, $dc_vars) = @_;
2646 my $env = $self->provision_rodc($path, $dc_vars);
2652 if (not defined($self->check_or_start($env, "standard"))) {
2656 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2659 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2660 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2661 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2662 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2663 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2664 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2665 $cmd .= " $dc_vars->{CONFIGURATION}";
2666 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2667 # replicate Configuration NC
2668 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2669 unless(system($cmd_repl) == 0) {
2670 warn("Failed to replicate\n$cmd_repl");
2673 # replicate Default NC
2674 $cmd_repl = "$cmd \"$base_dn\"";
2675 unless(system($cmd_repl) == 0) {
2676 warn("Failed to replicate\n$cmd_repl");
2685 my ($self, $path) = @_;
2687 # If we didn't build with ADS, pretend this env was never available
2688 if (not $self->{target3}->have_ads()) {
2692 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2693 "addom.samba.example.com", "", undef);
2698 if (not defined($self->check_or_start($env, "prefork"))) {
2702 my $upn_array = ["$env->{REALM}.upn"];
2703 my $spn_array = ["$env->{REALM}.spn"];
2705 $self->setup_namespaces($env, $upn_array, $spn_array);
2710 sub setup_ad_dc_no_nss
2712 my ($self, $path) = @_;
2714 # If we didn't build with ADS, pretend this env was never available
2715 if (not $self->{target3}->have_ads()) {
2719 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2720 "adnonssdom.samba.example.com", "", undef);
2725 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2726 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2728 if (not defined($self->check_or_start($env, "single"))) {
2732 my $upn_array = ["$env->{REALM}.upn"];
2733 my $spn_array = ["$env->{REALM}.spn"];
2735 $self->setup_namespaces($env, $upn_array, $spn_array);
2740 sub setup_ad_dc_no_ntlm
2742 my ($self, $path) = @_;
2744 # If we didn't build with ADS, pretend this env was never available
2745 if (not $self->{target3}->have_ads()) {
2749 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2750 "adnontlmdom.samba.example.com",
2751 "ntlm auth = disabled", undef);
2756 if (not defined($self->check_or_start($env, "prefork"))) {
2760 my $upn_array = ["$env->{REALM}.upn"];
2761 my $spn_array = ["$env->{REALM}.spn"];
2763 $self->setup_namespaces($env, $upn_array, $spn_array);
2769 # AD DC test environment used solely to test pre-fork process restarts.
2770 # As processes get killed off and restarted it should not be used for other
2771 sub setup_preforkrestartdc
2773 my ($self, $path) = @_;
2775 # If we didn't build with ADS, pretend this env was never available
2776 if (not $self->{target3}->have_ads()) {
2780 # note DC name must be <= 15 chars so we use 'prockill' instead of
2782 my $env = $self->provision_ad_dc(
2786 "prockilldom.samba.example.com",
2787 "prefork backoff increment = 5\nprefork maximum backoff=10");
2792 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2793 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2795 if (not defined($self->check_or_start($env, "prefork"))) {
2799 my $upn_array = ["$env->{REALM}.upn"];
2800 my $spn_array = ["$env->{REALM}.spn"];
2802 $self->setup_namespaces($env, $upn_array, $spn_array);
2808 # ad_dc test environment used solely to test standard process model connection
2809 # process limits. As the limit is set artificially low it should not be used
2811 sub setup_proclimitdc
2813 my ($self, $path) = @_;
2815 # If we didn't build with ADS, pretend this env was never available
2816 if (not $self->{target3}->have_ads()) {
2820 my $env = $self->provision_ad_dc(
2824 "proclimit.samba.example.com",
2825 "max smbd processes = 20");
2830 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2831 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2833 if (not defined($self->check_or_start($env, "standard"))) {
2837 my $upn_array = ["$env->{REALM}.upn"];
2838 my $spn_array = ["$env->{REALM}.spn"];
2840 $self->setup_namespaces($env, $upn_array, $spn_array);
2845 # Sets up a DC that's solely used to do a domain backup from. We then use the
2846 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2847 # process will create a Samba DC that will actually start up.
2848 # We don't use the backup-DC for anything else because its domain will conflict
2849 # with the restore DC.
2850 sub setup_backupfromdc
2852 my ($self, $path) = @_;
2854 # If we didn't build with ADS, pretend this env was never available
2855 if (not $self->{target3}->have_ads()) {
2859 my $provision_args = ["--site=Backup-Site"];
2861 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2862 "backupdom.samba.example.com",
2863 "samba kcc command = /bin/true",
2869 if (not defined($self->check_or_start($env, "standard"))) {
2873 my $upn_array = ["$env->{REALM}.upn"];
2874 my $spn_array = ["$env->{REALM}.spn"];
2876 $self->setup_namespaces($env, $upn_array, $spn_array);
2881 # returns the server/user-auth params needed to run an online backup cmd
2882 sub get_backup_server_args
2884 # dcvars contains the env info for the backup DC testenv
2885 my ($self, $dcvars) = @_;
2886 my $server = $dcvars->{DC_SERVER_IP};
2887 my $server_args = "--server=$server ";
2888 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2889 $server_args .= " $dcvars->{CONFIGURATION}";
2891 return $server_args;
2894 # Creates a backup of a running testenv DC
2897 # note: dcvars contains the env info for the backup DC testenv
2898 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2900 # get all the env variables we pass in with the samba-tool command
2901 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2902 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2903 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2904 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2906 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2908 # Note: use the backupfrom-DC's krb5.conf to do the backup
2909 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2910 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2912 # use samba-tool to create a backup from the 'backupfromdc' DC
2914 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2916 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2917 $cmd .= " --targetdir=$backupdir";
2919 print "Executing: $cmd\n";
2920 unless(system($cmd) == 0) {
2921 warn("Failed to create backup using: \n$cmd");
2925 # get the name of the backup file created
2926 opendir(DIR, $backupdir);
2927 my @files = grep(/\.tar/, readdir(DIR));
2930 if(scalar @files != 1) {
2931 warn("Backup file not found in directory $backupdir\n");
2934 my $backup_file = "$backupdir/$files[0]";
2935 print "Using backup file $backup_file...\n";
2937 return $backup_file;
2940 # Restores a backup-file to populate a testenv for a new DC
2941 sub restore_backup_file
2943 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2945 # pass the restore command the testenv's smb.conf that we've already
2946 # generated. But move it to a temp-dir first, so that the restore doesn't
2948 my $tmpdir = File::Temp->newdir();
2949 my $tmpconf = "$tmpdir/smb.conf";
2950 my $cmd = "cp $smbconf $tmpconf";
2951 unless(system($cmd) == 0) {
2952 warn("Failed to backup smb.conf using: \n$cmd");
2956 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2957 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2958 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2960 print "Executing: $cmd\n";
2961 unless(system($cmd) == 0) {
2962 warn("Failed to restore backup using: \n$cmd");
2966 print "Restore complete\n";
2970 # sets up the initial directory and returns the new testenv's env info
2971 # (without actually doing a 'domain join')
2972 sub prepare_dc_testenv
2974 my ($self, $prefix, $dcname, $domain, $realm,
2975 $password, $conf_options) = @_;
2977 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2987 # the restore uses a slightly different state-dir location to other testenvs
2988 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2989 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2991 # add support for sysvol/netlogon/tmp shares
2992 $ctx->{share} = "$ctx->{prefix_abs}/share";
2993 push(@{$ctx->{directories}}, "$ctx->{share}");
2995 $ctx->{smb_conf_extra_options} = "
2998 server max protocol = SMB2
2999 samba kcc command = /bin/true
3002 path = $ctx->{statedir}/sysvol
3006 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
3010 path = $ctx->{share}
3012 posix:sharedelay = 10000
3013 posix:oplocktimeout = 3
3014 posix:writetimeupdatedelay = 50000
3018 my $env = $self->provision_raw_step1($ctx);
3020 $env->{DC_SERVER} = $env->{SERVER};
3021 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
3022 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
3023 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
3024 $env->{DC_USERNAME} = $env->{USERNAME};
3025 $env->{DC_PASSWORD} = $env->{PASSWORD};
3027 return ($env, $ctx);
3031 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3032 # commands. This proves that we can backup an online DC ('backupfromdc') and
3033 # use the backup file to create a valid, working samba DC.
3036 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3037 my ($self, $prefix, $dcvars) = @_;
3038 print "Preparing RESTORE DC...\n";
3040 # we arbitrarily designate the restored DC as having SMBv1 disabled
3042 server min protocol = SMB2
3043 client min protocol = SMB2";
3045 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3048 $dcvars->{PASSWORD},
3051 # create a backup of the 'backupfromdc'
3052 my $backupdir = File::Temp->newdir();
3053 my $server_args = $self->get_backup_server_args($dcvars);
3054 my $backup_args = "online $server_args";
3055 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3057 unless($backup_file) {
3061 # restore the backup file to populate the restore-DC testenv
3062 my $restore_dir = abs_path($prefix);
3063 my $ret = $self->restore_backup_file($backup_file,
3064 "--newservername=$env->{SERVER}",
3065 $restore_dir, $env->{SERVERCONFFILE});
3066 unless ($ret == 0) {
3070 # start samba for the restored DC
3071 if (not defined($self->check_or_start($env, "standard"))) {
3078 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3079 # restore commands. This proves that we can backup and rename an online DC
3080 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3083 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3084 my ($self, $prefix, $dcvars) = @_;
3085 print "Preparing RENAME DC...\n";
3087 my $realm = "renamedom.samba.example.com";
3088 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3089 "RENAMEDOMAIN", $realm,
3090 $dcvars->{PASSWORD}, "");
3092 # create a backup of the 'backupfromdc' which renames the domain
3093 my $backupdir = File::Temp->newdir();
3094 my $server_args = $self->get_backup_server_args($dcvars);
3095 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3096 $backup_args .= " --backend-store=tdb";
3097 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3099 unless($backup_file) {
3103 # restore the backup file to populate the rename-DC testenv
3104 my $restore_dir = abs_path($prefix);
3105 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3106 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3107 $restore_dir, $env->{SERVERCONFFILE});
3108 unless ($ret == 0) {
3112 # start samba for the restored DC
3113 if (not defined($self->check_or_start($env, "standard"))) {
3117 my $upn_array = ["$env->{REALM}.upn"];
3118 my $spn_array = ["$env->{REALM}.spn"];
3120 $self->setup_namespaces($env, $upn_array, $spn_array);
3125 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3126 # restore commands. This proves that we do an offline backup of a local DC
3127 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3128 sub setup_offlinebackupdc
3130 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3131 my ($self, $prefix, $dcvars) = @_;
3132 print "Preparing OFFLINE BACKUP DC...\n";
3134 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3137 $dcvars->{PASSWORD}, "");
3139 # create an offline backup of the 'backupfromdc' target
3140 my $backupdir = File::Temp->newdir();
3141 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3142 my $backup_file = $self->create_backup($env, $dcvars,
3145 unless($backup_file) {
3149 # restore the backup file to populate the rename-DC testenv
3150 my $restore_dir = abs_path($prefix);
3151 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3152 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3153 $restore_dir, $env->{SERVERCONFFILE});
3154 unless ($ret == 0) {
3158 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3159 Samba::mk_krb5_conf($ctx);
3161 # start samba for the restored DC
3162 if (not defined($self->check_or_start($env, "standard"))) {
3169 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3170 # restore commands, using the --no-secrets option. This proves that we can
3171 # create a realistic lab environment from an online DC ('backupfromdc').
3174 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3175 my ($self, $prefix, $dcvars) = @_;
3176 print "Preparing LAB-DOMAIN DC...\n";
3178 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3180 "labdom.samba.example.com",
3181 $dcvars->{PASSWORD}, "");
3183 # create a backup of the 'backupfromdc' which renames the domain and uses
3184 # the --no-secrets option to scrub any sensitive info
3185 my $backupdir = File::Temp->newdir();
3186 my $server_args = $self->get_backup_server_args($dcvars);
3187 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3188 $backup_args .= " --no-secrets --backend-store=mdb";
3189 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3191 unless($backup_file) {
3195 # restore the backup file to populate the lab-DC testenv
3196 my $restore_dir = abs_path($prefix);
3197 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3198 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3199 $restore_dir, $env->{SERVERCONFFILE});
3200 unless ($ret == 0) {
3204 # because we don't include any secrets in the backup, we need to reset the
3205 # admin user's password back to what the testenv expects
3206 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3207 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3208 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3209 $cmd .= " $env->{CONFIGURATION}";
3211 unless(system($cmd) == 0) {
3212 warn("Failed to reset admin's password: \n$cmd");
3216 # start samba for the restored DC
3217 if (not defined($self->check_or_start($env, "standard"))) {
3221 my $upn_array = ["$env->{REALM}.upn"];
3222 my $spn_array = ["$env->{REALM}.spn"];
3224 $self->setup_namespaces($env, $upn_array, $spn_array);
3229 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3230 sub get_backup_domain_realm
3232 my ($self, $backup_file) = @_;
3234 print "Determining REALM/DOMAIN values in backup...\n";
3236 # The backup will have the correct domain/realm values in the smb.conf.
3237 # So we can work out the env variables the testenv should use based on
3238 # that. Let's start by extracting the smb.conf
3239 my $tar = Archive::Tar->new($backup_file);
3240 my $tmpdir = File::Temp->newdir();
3241 my $smbconf = "$tmpdir/smb.conf";
3243 # note that the filepaths within the tar-file differ slightly for online
3244 # and offline backups
3245 if ($tar->contains_file("etc/smb.conf")) {
3246 $tar->extract_file("etc/smb.conf", $smbconf);
3247 } elsif ($tar->contains_file("./etc/smb.conf")) {
3248 $tar->extract_file("./etc/smb.conf", $smbconf);
3250 warn("Could not find smb.conf in $backup_file");
3251 return undef, undef;
3254 # now use testparm to read the values we're interested in
3255 my $testparm = Samba::bindir_path($self, "testparm");
3256 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3257 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3260 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3262 return ($domain, $realm);
3265 # This spins up a custom testenv that can be based on any backup-file you want.
3266 # This is just intended for manual testing (rather than automated test-cases)
3269 my ($self, $prefix) = @_;
3270 print "Preparing CUSTOM RESTORE DC...\n";
3271 my $dc_name = "customdc";
3272 my $password = "locDCpass1";
3273 my $backup_file = $ENV{'BACKUP_FILE'};
3275 # user must specify a backup file to restore via an ENV variable, i.e.
3276 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3277 if (not defined($backup_file)) {
3278 warn("Please specify BACKUP_FILE");
3282 # work out the correct domain/realm env values from the backup-file
3283 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3285 # create a placeholder directory and smb.conf, as well as the env vars.
3286 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3287 $domain, $realm, $password, "");
3289 # restore the specified backup file to populate the testenv
3290 my $restore_dir = abs_path($prefix);
3291 my $ret = $self->restore_backup_file($backup_file,
3292 "--newservername=$env->{SERVER}",
3293 $restore_dir, $env->{SERVERCONFFILE});
3294 unless ($ret == 0) {
3298 # Change the admin password to the testenv default, just in case it's
3299 # different, or in case this was a --no-secrets backup
3300 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3301 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3302 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3303 $cmd .= " $env->{CONFIGURATION}";
3305 unless(system($cmd) == 0) {
3306 warn("Failed to reset admin's password: \n$cmd");
3310 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3311 # if the backup-file was an offline backup)
3312 Samba::mk_krb5_conf($ctx);
3314 # start samba for the restored DC
3315 if (not defined($self->check_or_start($env, "standard"))) {
3319 # if this was a backup-rename, then we may need to setup namespaces
3320 my $upn_array = ["$env->{REALM}.upn"];
3321 my $spn_array = ["$env->{REALM}.spn"];
3323 $self->setup_namespaces($env, $upn_array, $spn_array);
3330 my ($self, $path) = @_;
3333 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",