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.
10 use FindBin qw($RealBin);
17 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
24 server_maxtime => $server_maxtime,
25 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
31 sub scriptdir_path($$) {
32 my ($self, $path) = @_;
33 return "$self->{srcdir}/source4/scripting/$path";
36 sub openldap_start($$$) {
42 my ($self, $env_vars, $STDIN_READER) = @_;
43 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
45 my $uri = $env_vars->{LDAP_URI};
47 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
48 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
51 # running slapd in the background means it stays in the same process group, so it can be
55 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
56 open STDERR, '>&STDOUT';
57 close($env_vars->{STDIN_PIPE});
58 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
60 if ($self->{ldap} eq "fedora-ds") {
61 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
62 } elsif ($self->{ldap} eq "openldap") {
63 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
65 die("Unable to start slapd: $!");
67 $env_vars->{SLAPD_PID} = $pid;
69 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
72 $self->slapd_stop($env_vars);
82 my ($self, $envvars) = @_;
83 kill 9, $envvars->{SLAPD_PID};
87 sub check_or_start($$$)
89 my ($self, $env_vars, $process_model) = @_;
92 my $env_ok = $self->check_env($env_vars);
94 return $env_vars->{SAMBA_PID};
95 } elsif (defined($env_vars->{SAMBA_PID})) {
96 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
100 # use a pipe for stdin in the child processes. This allows
101 # those processes to monitor the pipe for EOF to ensure they
102 # exit when the test script exits
103 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
105 # Start slapd before samba, but with the fifo on stdin
106 if (defined($self->{ldap})) {
107 unless($self->slapd_start($env_vars, $STDIN_READER)) {
108 warn("couldn't start slapd (main run)");
113 print "STARTING SAMBA...\n";
116 # we want out from samba to go to the log file, but also
117 # to the users terminal when running 'make test' on the command
118 # line. This puts it on stderr on the terminal
119 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
120 open STDERR, '>&STDOUT';
122 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
124 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
125 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
126 if (defined($ENV{MITKRB5})) {
127 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
129 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
130 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
132 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
133 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
134 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
135 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
136 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
137 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
139 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
140 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
142 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
145 $ENV{UID_WRAPPER} = "1";
146 $ENV{UID_WRAPPER_ROOT} = "1";
148 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
151 if (defined($ENV{SAMBA_OPTIONS})) {
152 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
154 if(defined($ENV{SAMBA_VALGRIND})) {
155 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
158 close($env_vars->{STDIN_PIPE});
159 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
161 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: $!");
163 $env_vars->{SAMBA_PID} = $pid;
164 print "DONE ($pid)\n";
166 close($STDIN_READER);
168 if ($self->wait_for_start($env_vars) != 0) {
169 warn("Samba $pid failed to start up");
176 sub wait_for_start($$)
178 my ($self, $testenv_vars) = @_;
182 if (not $self->check_env($testenv_vars)) {
183 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
187 # This will return quickly when things are up, but be slow if we
188 # need to wait for (eg) SSL init
189 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
192 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
199 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
200 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
201 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}");
209 } while ($ret != 0 && $count < 20);
211 warn("nbt not reachable after 20 retries\n");
212 teardown_env($self, $testenv_vars);
216 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
217 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
218 print "waiting for working LDAP and a RID Set to be allocated\n";
219 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
221 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
223 my $search_dn = $base_dn;
224 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
225 # TODO currently no check for actual rIDAllocationPool
226 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
230 # Add hosts file for name lookups
231 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
232 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
233 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
235 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
238 $cmd .= "$ldbsearch ";
239 $cmd .= "$testenv_vars->{CONFIGURATION} ";
240 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
241 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
243 $cmd .= "-b '$search_dn' ";
244 while (system("$cmd >/dev/null") != 0) {
246 if ($count > $max_wait) {
247 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}");
255 my $wbinfo = Samba::bindir_path($self, "wbinfo");
259 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
260 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
261 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
262 $cmd .= "$wbinfo -p";
269 } while ($ret != 0 && $count < 20);
271 warn("winbind not reachable after 20 retries\n");
272 teardown_env($self, $testenv_vars);
276 print $self->getlog_env($testenv_vars);
281 sub write_ldb_file($$$)
283 my ($self, $file, $ldif) = @_;
285 my $ldbadd = Samba::bindir_path($self, "ldbadd");
286 open(LDIF, "|$ldbadd -H $file >/dev/null");
291 sub add_wins_config($$)
293 my ($self, $privatedir) = @_;
295 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
296 dn: name=TORTURE_11,CN=PARTNERS
297 objectClass: wreplPartner
308 my ($self, $ctx) = @_;
310 #Make the subdirectory be as fedora DS would expect
311 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
313 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
315 return ($fedora_ds_dir, $pidfile);
320 my ($self, $ctx) = @_;
322 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
323 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
325 return ($slapd_conf_d, $pidfile);
328 sub setup_namespaces($$:$$)
330 my ($self, $localenv, $upn_array, $spn_array) = @_;
332 @{$upn_array} = [] unless defined($upn_array);
334 foreach my $upn (@{$upn_array}) {
335 $upn_args .= " --add-upn-suffix=$upn";
338 @{$spn_array} = [] unless defined($spn_array);
340 foreach my $spn (@{$spn_array}) {
341 $spn_args .= " --add-spn-suffix=$spn";
344 my $samba_tool = Samba::bindir_path($self, "samba-tool");
347 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
348 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
349 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
351 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
353 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
354 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
356 my $cmd_config = " $localenv->{CONFIGURATION}";
358 my $namespaces = $cmd_env;
359 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
360 $namespaces .= $cmd_config;
361 unless (system($namespaces) == 0) {
362 warn("Failed to add namespaces \n$namespaces");
369 sub setup_trust($$$$$)
371 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
373 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
374 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
375 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
376 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
377 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
378 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
379 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
380 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
381 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
383 my $samba_tool = Samba::bindir_path($self, "samba-tool");
386 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
387 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
388 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
390 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
392 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
393 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
395 my $cmd_config = " $localenv->{CONFIGURATION}";
396 my $cmd_creds = $cmd_config;
397 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
399 my $create = $cmd_env;
400 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
401 $create .= " $extra_args";
402 $create .= $cmd_creds;
403 unless (system($create) == 0) {
404 warn("Failed to create trust \n$create");
408 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
409 my $groupadd = $cmd_env;
410 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
411 unless (system($groupadd) == 0) {
412 warn("Failed to create group \n$groupadd");
415 my $groupmem = $cmd_env;
416 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
417 unless (system($groupmem) == 0) {
418 warn("Failed to add group member \n$groupmem");
425 sub provision_raw_prepare($$$$$$$$$$$$)
427 my ($self, $prefix, $server_role, $hostname,
428 $domain, $realm, $samsid, $functional_level,
429 $password, $kdc_ipv4, $kdc_ipv6) = @_;
431 my $netbiosname = uc($hostname);
433 unless(-d $prefix or mkdir($prefix, 0777)) {
434 warn("Unable to create $prefix");
437 my $prefix_abs = abs_path($prefix);
439 die ("prefix=''") if $prefix_abs eq "";
440 die ("prefix='/'") if $prefix_abs eq "/";
442 unless (system("rm -rf $prefix_abs/*") == 0) {
443 warn("Unable to clean up");
447 my $swiface = Samba::get_interface($hostname);
449 $ctx->{prefix} = $prefix;
450 $ctx->{prefix_abs} = $prefix_abs;
452 $ctx->{server_role} = $server_role;
453 $ctx->{hostname} = $hostname;
454 $ctx->{netbiosname} = $netbiosname;
455 $ctx->{swiface} = $swiface;
456 $ctx->{password} = $password;
457 $ctx->{kdc_ipv4} = $kdc_ipv4;
458 $ctx->{kdc_ipv6} = $kdc_ipv6;
459 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
460 if ($functional_level eq "2000") {
461 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
465 # Set smbd log level here.
467 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
468 $ctx->{username} = "Administrator";
469 $ctx->{domain} = $domain;
470 $ctx->{realm} = uc($realm);
471 $ctx->{dnsname} = lc($realm);
472 $ctx->{samsid} = $samsid;
474 $ctx->{functional_level} = $functional_level;
476 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
478 $ctx->{unix_name} = $unix_name;
479 $ctx->{unix_uid} = $>;
480 my @mygid = split(" ", $();
481 $ctx->{unix_gid} = $mygid[0];
482 $ctx->{unix_gids_str} = $);
483 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
485 $ctx->{etcdir} = "$prefix_abs/etc";
486 $ctx->{piddir} = "$prefix_abs/pid";
487 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
488 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
489 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
490 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
491 $ctx->{privatedir} = "$prefix_abs/private";
492 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
493 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
494 $ctx->{lockdir} = "$prefix_abs/lockdir";
495 $ctx->{logdir} = "$prefix_abs/logs";
496 $ctx->{statedir} = "$prefix_abs/statedir";
497 $ctx->{cachedir} = "$prefix_abs/cachedir";
498 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
499 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
500 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
501 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
502 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
503 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
504 if ($ENV{SAMBA_DNS_FAKING}) {
505 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
506 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
508 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
509 $ctx->{use_resolv_wrapper} = 1;
511 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
513 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
515 $ctx->{ipv4} = "127.0.0.$swiface";
516 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
517 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
519 push(@{$ctx->{directories}}, $ctx->{privatedir});
520 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
521 push(@{$ctx->{directories}}, $ctx->{etcdir});
522 push(@{$ctx->{directories}}, $ctx->{piddir});
523 push(@{$ctx->{directories}}, $ctx->{lockdir});
524 push(@{$ctx->{directories}}, $ctx->{logdir});
525 push(@{$ctx->{directories}}, $ctx->{statedir});
526 push(@{$ctx->{directories}}, $ctx->{cachedir});
528 $ctx->{smb_conf_extra_options} = "";
530 my @provision_options = ();
531 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
532 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
533 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
534 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
535 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
536 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
537 if (defined($ctx->{use_resolv_wrapper})) {
538 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
540 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
542 if (defined($ENV{GDB_PROVISION})) {
543 push (@provision_options, "gdb --args");
544 if (!defined($ENV{PYTHON})) {
545 push (@provision_options, "env");
546 push (@provision_options, "python");
549 if (defined($ENV{VALGRIND_PROVISION})) {
550 push (@provision_options, "valgrind");
551 if (!defined($ENV{PYTHON})) {
552 push (@provision_options, "env");
553 push (@provision_options, "python");
556 if (defined($ENV{PYTHON})) {
557 push (@provision_options, $ENV{PYTHON});
559 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
560 push (@provision_options, "domain");
561 push (@provision_options, "provision");
562 push (@provision_options, "--configfile=$ctx->{smb_conf}");
563 push (@provision_options, "--host-name=$ctx->{hostname}");
564 push (@provision_options, "--host-ip=$ctx->{ipv4}");
565 push (@provision_options, "--quiet");
566 push (@provision_options, "--domain=$ctx->{domain}");
567 push (@provision_options, "--realm=$ctx->{realm}");
568 if (defined($ctx->{samsid})) {
569 push (@provision_options, "--domain-sid=$ctx->{samsid}");
571 push (@provision_options, "--adminpass=$ctx->{password}");
572 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
573 push (@provision_options, "--machinepass=machine$ctx->{password}");
574 push (@provision_options, "--root=$ctx->{unix_name}");
575 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
576 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
578 @{$ctx->{provision_options}} = @provision_options;
584 # Step1 creates the basic configuration
586 sub provision_raw_step1($$)
588 my ($self, $ctx) = @_;
590 mkdir($_, 0777) foreach (@{$ctx->{directories}});
593 ## lockdir and piddir must be 0755
595 chmod 0755, $ctx->{lockdir};
596 chmod 0755, $ctx->{piddir};
598 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
599 warn("can't open $ctx->{smb_conf}$?");
603 Samba::prepare_keyblobs($ctx);
604 my $crlfile = "$ctx->{tlsdir}/crl.pem";
605 $crlfile = "" unless -e ${crlfile};
609 netbios name = $ctx->{netbiosname}
610 posix:eadb = $ctx->{statedir}/eadb.tdb
611 workgroup = $ctx->{domain}
612 realm = $ctx->{realm}
613 private dir = $ctx->{privatedir}
614 binddns dir = $ctx->{binddnsdir}
615 pid directory = $ctx->{piddir}
616 ncalrpc dir = $ctx->{ncalrpcdir}
617 lock dir = $ctx->{lockdir}
618 state directory = $ctx->{statedir}
619 cache directory = $ctx->{cachedir}
620 winbindd socket directory = $ctx->{winbindd_socket_dir}
621 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
622 winbind separator = /
623 interfaces = $ctx->{interfaces}
624 tls dh params file = $ctx->{tlsdir}/dhparms.pem
625 tls crlfile = ${crlfile}
626 tls verify peer = no_check
627 panic action = $RealBin/gdb_backtrace \%d
629 server role = $ctx->{server_role}
630 server services = +echo +smb -s3fs
631 dcerpc endpoint servers = +winreg +srvsvc
632 notify:inotify = false
634 ldap server require strong auth = yes
635 #We don't want to pass our self-tests if the PAC code is wrong
636 gensec:require_pac = true
637 log file = $ctx->{logdir}/log.\%m
638 log level = $ctx->{server_loglevel}
642 dns update command = $ctx->{samba_dnsupdate}
643 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
644 gpo update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_gpoupdate -s $ctx->{smb_conf} -H $ctx->{privatedir}/sam.ldb --machine
645 dreplsrv:periodic_startup_interval = 0
646 dsdb:schema update allowed = yes
650 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
652 idmap_ldb:use rfc2307=yes
653 winbind enum users = yes
654 winbind enum groups = yes
656 rpc server port:netlogon = 1026
662 # Begin extra options
663 $ctx->{smb_conf_extra_options}
668 #Default the KDC IP to the server's IP
669 if (not defined($ctx->{kdc_ipv4})) {
670 $ctx->{kdc_ipv4} = $ctx->{ipv4};
672 if (not defined($ctx->{kdc_ipv6})) {
673 $ctx->{kdc_ipv6} = $ctx->{ipv6};
676 Samba::mk_krb5_conf($ctx);
677 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
679 open(PWD, ">$ctx->{nsswrap_passwd}");
680 if ($ctx->{unix_uid} != 0) {
681 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
683 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
684 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
685 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
686 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
687 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
688 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
691 my $uid_rfc2307test = 65533;
693 open(GRP, ">$ctx->{nsswrap_group}");
694 if ($ctx->{unix_gid} != 0) {
695 print GRP "root:x:0:\n";
697 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
698 print GRP "wheel:x:10:
701 nogroup:x:65534:nobody
704 my $gid_rfc2307test = 65532;
706 my $hostname = lc($ctx->{hostname});
707 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
708 if ($hostname eq "localdc") {
709 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
710 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
712 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
713 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
717 if (defined($ctx->{resolv_conf})) {
718 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
719 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
720 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
724 my $configuration = "--configfile=$ctx->{smb_conf}";
726 #Ensure the config file is valid before we start
727 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
728 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
729 system("$testparm -v --suppress-prompt $configuration >&2");
730 warn("Failed to create a valid smb.conf configuration $testparm!");
733 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) {
734 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
739 KRB5_CONFIG => $ctx->{krb5_conf},
740 KRB5_CCACHE => $ctx->{krb5_ccache},
741 MITKDC_CONFIG => $ctx->{mitkdc_conf},
742 PIDDIR => $ctx->{piddir},
743 SERVER => $ctx->{hostname},
744 SERVER_IP => $ctx->{ipv4},
745 SERVER_IPV6 => $ctx->{ipv6},
746 NETBIOSNAME => $ctx->{netbiosname},
747 DOMAIN => $ctx->{domain},
748 USERNAME => $ctx->{username},
749 REALM => $ctx->{realm},
750 SAMSID => $ctx->{samsid},
751 PASSWORD => $ctx->{password},
752 LDAPDIR => $ctx->{ldapdir},
753 LDAP_INSTANCE => $ctx->{ldap_instance},
754 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
755 NCALRPCDIR => $ctx->{ncalrpcdir},
756 LOCKDIR => $ctx->{lockdir},
757 STATEDIR => $ctx->{statedir},
758 CACHEDIR => $ctx->{cachedir},
759 PRIVATEDIR => $ctx->{privatedir},
760 BINDDNSDIR => $ctx->{binddnsdir},
761 SERVERCONFFILE => $ctx->{smb_conf},
762 CONFIGURATION => $configuration,
763 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
764 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
765 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
766 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
767 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
768 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
769 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
770 SAMBA_TEST_LOG_POS => 0,
771 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
772 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
773 LOCAL_PATH => $ctx->{share},
774 UID_RFC2307TEST => $uid_rfc2307test,
775 GID_RFC2307TEST => $gid_rfc2307test,
776 SERVER_ROLE => $ctx->{server_role},
777 RESOLV_CONF => $ctx->{resolv_conf}
780 if (defined($ctx->{use_resolv_wrapper})) {
781 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
783 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
786 if ($ctx->{server_role} eq "domain controller") {
787 $ret->{DOMSID} = $ret->{SAMSID};
794 # Step2 runs the provision script
796 sub provision_raw_step2($$$)
798 my ($self, $ctx, $ret) = @_;
800 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
801 unless (system($provision_cmd) == 0) {
802 warn("Unable to provision: \n$provision_cmd\n");
806 my $testallowed_account = "testallowed";
807 my $samba_tool_cmd = "";
808 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
809 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
810 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
811 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
812 unless (system($samba_tool_cmd) == 0) {
813 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
818 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
819 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
820 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
821 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
823 if ($ctx->{server_role} ne "domain controller") {
824 $base_dn = "DC=$ctx->{netbiosname}";
827 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
828 $testallowed_account = "testallowed account";
829 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
830 print LDIF "dn: $user_dn
832 replace: samAccountName
833 samAccountName: $testallowed_account
838 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
839 print LDIF "dn: $user_dn
841 replace: userPrincipalName
842 userPrincipalName: testallowed upn\@$ctx->{realm}
843 replace: servicePrincipalName
844 servicePrincipalName: host/testallowed
849 $samba_tool_cmd = "";
850 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
851 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
852 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
853 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
854 unless (system($samba_tool_cmd) == 0) {
855 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
859 my $user_dn = "cn=testdenied,cn=users,$base_dn";
860 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
861 print LDIF "dn: $user_dn
863 replace: userPrincipalName
864 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
869 $samba_tool_cmd = "";
870 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
871 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
872 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
873 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
874 unless (system($samba_tool_cmd) == 0) {
875 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
879 # Create to users alice and bob!
880 my $user_account_array = ["alice", "bob", "jane"];
882 foreach my $user_account (@{$user_account_array}) {
883 my $samba_tool_cmd = "";
885 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
886 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
887 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
888 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
889 unless (system($samba_tool_cmd) == 0) {
890 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
896 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
897 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
898 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
900 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
901 my $user_dn = "cn=jane,cn=users,$base_dn";
903 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
904 print LDIF "dn: $user_dn
906 replace: userPrincipalName
907 userPrincipalName: jane.doe\@$ctx->{realm}
915 sub provision($$$$$$$$$$)
917 my ($self, $prefix, $server_role, $hostname,
918 $domain, $realm, $functional_level,
919 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
920 $extra_provision_options) = @_;
922 my $samsid = Samba::random_domain_sid();
924 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
929 $password, $kdc_ipv4, $kdc_ipv6);
931 if (defined($extra_provision_options)) {
932 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
934 push (@{$ctx->{provision_options}}, "--use-ntvfs");
937 $ctx->{share} = "$ctx->{prefix_abs}/share";
938 push(@{$ctx->{directories}}, "$ctx->{share}");
939 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
940 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
942 # precreate directories for printer drivers
943 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
944 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
945 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
948 $msdfs = "yes" if ($server_role eq "domain controller");
949 $ctx->{smb_conf_extra_options} = "
952 server max protocol = SMB2
956 # fruit:copyfile is a global option
959 $extra_smbconf_options
964 posix:sharedelay = 100000
965 posix:oplocktimeout = 3
966 posix:writetimeupdatedelay = 500000
971 posix:sharedelay = 100000
972 posix:oplocktimeout = 3
973 posix:writetimeupdatedelay = 500000
975 force create mode = 777
981 force create mode = 0
982 directory mask = 0777
983 force directory mode = 0
986 path = $ctx->{share}/test1
988 posix:sharedelay = 100000
989 posix:oplocktimeout = 3
990 posix:writetimeupdatedelay = 500000
993 path = $ctx->{share}/test2
995 posix:sharedelay = 100000
996 posix:oplocktimeout = 3
997 posix:writetimeupdatedelay = 500000
1000 path = $ctx->{share}/_ignore_cifs_
1002 ntvfs handler = cifs
1003 cifs:server = $ctx->{netbiosname}
1005 cifs:use-s4u2proxy = yes
1006 # There is no username specified here, instead the client is expected
1007 # to log in with kerberos, and the serverwill use delegated credentials.
1008 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1011 path = $ctx->{share}
1013 ntvfs handler = simple
1016 path = $ctx->{statedir}/sysvol
1020 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1025 ntvfs handler = cifsposix
1028 path = $ctx->{share}
1029 vfs objects = catia fruit streams_xattr acl_xattr
1031 fruit:resource = file
1032 fruit:metadata = netatalk
1033 fruit:locking = netatalk
1034 fruit:encoding = native
1036 $extra_smbconf_shares
1039 if (defined($self->{ldap})) {
1040 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1041 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1043 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1044 $ldap_uri =~ s|/|%2F|g;
1045 $ldap_uri = "ldapi://$ldap_uri";
1046 $ctx->{ldap_uri} = $ldap_uri;
1048 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1051 my $ret = $self->provision_raw_step1($ctx);
1052 unless (defined $ret) {
1056 if (defined($self->{ldap})) {
1057 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1058 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1059 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1060 if ($self->{ldap} eq "openldap") {
1061 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1062 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1064 } elsif ($self->{ldap} eq "fedora-ds") {
1065 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1066 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1067 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1072 return $self->provision_raw_step2($ctx, $ret);
1075 sub provision_s4member($$$$$)
1077 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1078 print "PROVISIONING MEMBER...\n";
1079 my $extra_smb_conf = "
1080 passdb backend = samba_dsdb
1081 winbindd:use external pipes = true
1083 # the source4 smb server doesn't allow signing by default
1084 server signing = enabled
1085 raw NTLMv2 auth = yes
1087 rpc_server:default = external
1088 rpc_server:svcctl = embedded
1089 rpc_server:srvsvc = embedded
1090 rpc_server:eventlog = embedded
1091 rpc_server:ntsvcs = embedded
1092 rpc_server:winreg = embedded
1093 rpc_server:spoolss = embedded
1094 rpc_daemon:spoolssd = embedded
1095 rpc_server:tcpip = no
1098 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1100 my $ret = $self->provision($prefix,
1107 $dcvars->{SERVER_IP},
1108 $dcvars->{SERVER_IPV6},
1109 $extra_smb_conf, "", undef);
1114 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1116 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1117 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1118 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1120 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1122 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1123 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1124 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1125 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1126 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1128 unless (system($cmd) == 0) {
1129 warn("Join failed\n$cmd");
1133 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1134 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1135 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1136 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1137 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1138 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1140 $ret->{DOMSID} = $dcvars->{DOMSID};
1141 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1142 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1143 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1144 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1145 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1146 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1151 sub provision_rpc_proxy($$$)
1153 my ($self, $prefix, $dcvars) = @_;
1154 print "PROVISIONING RPC PROXY...\n";
1156 my $extra_smbconf_options = "
1157 passdb backend = samba_dsdb
1160 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1161 dcerpc endpoint servers = epmapper, remote
1162 dcerpc_remote:interfaces = rpcecho
1165 path = /tmp/_ignore_cifs_to_dc_/_none_
1167 ntvfs handler = cifs
1168 cifs:server = $dcvars->{SERVER}
1170 cifs:use-s4u2proxy = yes
1171 # There is no username specified here, instead the client is expected
1172 # to log in with kerberos, and the serverwill use delegated credentials.
1173 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1177 my $ret = $self->provision($prefix,
1184 $dcvars->{SERVER_IP},
1185 $dcvars->{SERVER_IPV6},
1186 $extra_smbconf_options, "", undef);
1191 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1193 # The joind runs in the context of the rpc_proxy/member for now
1195 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1196 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1197 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1199 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1201 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1202 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1203 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1204 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1205 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1207 unless (system($cmd) == 0) {
1208 warn("Join failed\n$cmd");
1212 # Setting up delegation runs in the context of the DC for now
1214 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1215 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1216 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1217 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1218 $cmd .= " $dcvars->{CONFIGURATION}";
1221 unless (system($cmd) == 0) {
1222 warn("Delegation failed\n$cmd");
1226 # Setting up delegation runs in the context of the DC for now
1228 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1229 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1230 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1231 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1232 $cmd .= " $dcvars->{CONFIGURATION}";
1234 unless (system($cmd) == 0) {
1235 warn("Delegation failed\n$cmd");
1239 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1240 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1241 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1242 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1243 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1244 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1246 $ret->{DOMSID} = $dcvars->{DOMSID};
1247 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1248 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1249 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1250 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1251 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1252 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1257 sub provision_promoted_dc($$$)
1259 my ($self, $prefix, $dcvars) = @_;
1260 print "PROVISIONING PROMOTED DC...\n";
1262 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1263 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1269 $dcvars->{PASSWORD},
1270 $dcvars->{SERVER_IP},
1271 $dcvars->{SERVER_IPV6});
1273 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1275 $ctx->{smb_conf_extra_options} = "
1277 server max protocol = SMB2
1279 ntlm auth = ntlmv2-only
1282 path = $ctx->{statedir}/sysvol
1286 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1291 my $ret = $self->provision_raw_step1($ctx);
1296 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1298 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1299 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1300 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1302 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1304 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1305 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1306 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1307 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1308 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1310 unless (system($cmd) == 0) {
1311 warn("Join failed\n$cmd");
1315 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1317 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1318 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1319 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1320 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1321 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1322 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1324 unless (system($cmd) == 0) {
1325 warn("Join failed\n$cmd");
1329 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1330 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1331 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1332 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1334 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1335 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1336 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1337 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1338 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1339 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1344 sub provision_vampire_dc($$$)
1346 my ($self, $prefix, $dcvars, $fl) = @_;
1347 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1348 my $name = "localvampiredc";
1349 my $extra_conf = "";
1351 if ($fl == "2000") {
1352 $name = "vampire2000dc";
1354 $extra_conf = "drs: immediate link sync = yes
1355 drs: max link sync = 250";
1358 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1359 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1365 $dcvars->{PASSWORD},
1366 $dcvars->{SERVER_IP},
1367 $dcvars->{SERVER_IPV6});
1369 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1371 $ctx->{smb_conf_extra_options} = "
1373 server max protocol = SMB2
1375 ntlm auth = mschapv2-and-ntlmv2-only
1379 path = $ctx->{statedir}/sysvol
1383 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1388 my $ret = $self->provision_raw_step1($ctx);
1393 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1395 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1396 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1397 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1399 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1401 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1402 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1403 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1404 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1405 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1406 $cmd .= " --backend-store=mdb";
1408 unless (system($cmd) == 0) {
1409 warn("Join failed\n$cmd");
1413 if ($fl == "2000") {
1414 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1415 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1416 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1417 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1419 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1420 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1421 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1422 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1424 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1425 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1426 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1427 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1428 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1429 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1430 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1435 sub provision_subdom_dc($$$)
1437 my ($self, $prefix, $dcvars) = @_;
1438 print "PROVISIONING SUBDOMAIN DC...\n";
1440 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1441 my $samsid = undef; # TODO pass the domain sid all the way down
1442 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1445 "sub.samba.example.com",
1448 $dcvars->{PASSWORD},
1451 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1453 $ctx->{smb_conf_extra_options} = "
1455 server max protocol = SMB2
1458 path = $ctx->{statedir}/sysvol
1462 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1467 my $ret = $self->provision_raw_step1($ctx);
1472 Samba::mk_krb5_conf($ctx);
1473 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1475 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1477 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1478 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1479 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1481 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1483 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1484 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1485 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1486 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1487 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1488 $cmd .= " --adminpass=$ret->{PASSWORD}";
1490 unless (system($cmd) == 0) {
1491 warn("Join failed\n$cmd");
1495 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1496 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1497 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1498 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1500 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1501 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1502 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1503 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1504 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1505 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1510 sub provision_ad_dc_ntvfs($$)
1512 my ($self, $prefix) = @_;
1514 # We keep the old 'winbind' name here in server services to
1515 # ensure upgrades which used that name still work with the now
1518 print "PROVISIONING AD DC (NTVFS)...\n";
1519 my $extra_conf_options = "netbios aliases = localDC1-a
1520 server services = +winbind -winbindd
1521 ldap server require strong auth = allow_sasl_over_tls
1522 allow nt4 crypto = yes
1523 raw NTLMv2 auth = yes
1524 lsa over netlogon = yes
1525 rpc server port = 1027
1526 auth event notification = true
1527 dsdb event notification = true
1528 dsdb password event notification = true
1529 dsdb group change notification = true
1530 server schannel = auto
1532 my $ret = $self->provision($prefix,
1533 "domain controller",
1536 "samba.example.com",
1541 $extra_conf_options,
1548 unless($self->add_wins_config("$prefix/private")) {
1549 warn("Unable to add wins configuration");
1552 $ret->{NETBIOSALIAS} = "localdc1-a";
1553 $ret->{DC_SERVER} = $ret->{SERVER};
1554 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1555 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1556 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1557 $ret->{DC_USERNAME} = $ret->{USERNAME};
1558 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1559 $ret->{DC_REALM} = $ret->{REALM};
1564 sub provision_fl2000dc($$)
1566 my ($self, $prefix) = @_;
1568 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1569 my $extra_conf_options = "
1570 spnego:simulate_w2k=yes
1571 ntlmssp_server:force_old_spnego=yes
1573 my $extra_provision_options = undef;
1574 # This environment uses plain text secrets
1575 # i.e. secret attributes are not encrypted on disk.
1576 # This allows testing of the --plaintext-secrets option for
1578 push (@{$extra_provision_options}, "--plaintext-secrets");
1579 my $ret = $self->provision($prefix,
1580 "domain controller",
1583 "samba2000.example.com",
1588 $extra_conf_options,
1590 $extra_provision_options);
1595 unless($self->add_wins_config("$prefix/private")) {
1596 warn("Unable to add wins configuration");
1599 $ret->{DC_SERVER} = $ret->{SERVER};
1600 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1601 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1602 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1603 $ret->{DC_USERNAME} = $ret->{USERNAME};
1604 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1605 $ret->{DC_REALM} = $ret->{REALM};
1610 sub provision_fl2003dc($$$)
1612 my ($self, $prefix, $dcvars) = @_;
1613 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1614 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1616 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1617 my $extra_conf_options = "allow dns updates = nonsecure and secure
1618 dcesrv:header signing = no
1619 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1620 my $ret = $self->provision($prefix,
1621 "domain controller",
1624 "samba2003.example.com",
1629 $extra_conf_options,
1632 unless (defined $ret) {
1636 $ret->{DC_SERVER} = $ret->{SERVER};
1637 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1638 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1639 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1640 $ret->{DC_USERNAME} = $ret->{USERNAME};
1641 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1642 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1643 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1645 my @samba_tool_options;
1646 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1647 push (@samba_tool_options, "domain");
1648 push (@samba_tool_options, "passwordsettings");
1649 push (@samba_tool_options, "set");
1650 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1651 push (@samba_tool_options, "--min-pwd-age=0");
1652 push (@samba_tool_options, "--history-length=1");
1654 my $samba_tool_cmd = join(" ", @samba_tool_options);
1656 unless (system($samba_tool_cmd) == 0) {
1657 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1661 unless($self->add_wins_config("$prefix/private")) {
1662 warn("Unable to add wins configuration");
1669 sub provision_fl2008r2dc($$$)
1671 my ($self, $prefix, $dcvars) = @_;
1673 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1674 my $extra_conf_options = "ldap server require strong auth = no";
1675 my $ret = $self->provision($prefix,
1676 "domain controller",
1679 "samba2008R2.example.com",
1684 $extra_conf_options,
1687 unless (defined $ret) {
1691 unless ($self->add_wins_config("$prefix/private")) {
1692 warn("Unable to add wins configuration");
1695 $ret->{DC_SERVER} = $ret->{SERVER};
1696 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1697 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1698 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1699 $ret->{DC_USERNAME} = $ret->{USERNAME};
1700 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1701 $ret->{DC_REALM} = $ret->{REALM};
1707 sub provision_rodc($$$)
1709 my ($self, $prefix, $dcvars) = @_;
1710 print "PROVISIONING RODC...\n";
1712 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1713 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1719 $dcvars->{PASSWORD},
1720 $dcvars->{SERVER_IP},
1721 $dcvars->{SERVER_IPV6});
1726 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1728 $ctx->{share} = "$ctx->{prefix_abs}/share";
1729 push(@{$ctx->{directories}}, "$ctx->{share}");
1731 $ctx->{smb_conf_extra_options} = "
1733 server max protocol = SMB2
1734 password server = $dcvars->{DC_SERVER}
1737 path = $ctx->{statedir}/sysvol
1741 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1745 path = $ctx->{share}
1747 posix:sharedelay = 10000
1748 posix:oplocktimeout = 3
1749 posix:writetimeupdatedelay = 50000
1753 my $ret = $self->provision_raw_step1($ctx);
1758 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1760 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1761 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1762 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1764 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1766 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1767 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1768 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1769 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1770 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1772 unless (system($cmd) == 0) {
1773 warn("RODC join failed\n$cmd");
1777 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1778 # user password verified on the RODC
1779 my $testallowed_account = "testallowed account";
1780 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1781 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1782 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1783 $cmd .= " --server=$dcvars->{DC_SERVER}";
1785 unless (system($cmd) == 0) {
1786 warn("RODC join failed\n$cmd");
1790 # we overwrite the kdc after the RODC join
1791 # so that use the RODC as kdc and test
1793 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1794 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1795 Samba::mk_krb5_conf($ctx);
1796 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1798 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1799 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1800 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1801 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1803 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1804 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1805 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1806 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1807 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1808 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1813 sub read_config_h($)
1817 open(LF, "<$name") or die("unable to read $name: $!");
1820 next if not (/^#define /);
1821 if (/^#define (.*?)[ \t]+(.*?)$/) {
1825 if (/^#define (.*?)[ \t]+$/) {
1834 sub provision_ad_dc($$$$$$)
1836 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args) = @_;
1838 my $prefix_abs = abs_path($prefix);
1840 my $bindir_abs = abs_path($self->{bindir});
1841 my $lockdir="$prefix_abs/lockdir";
1842 my $conffile="$prefix_abs/etc/smb.conf";
1844 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1845 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1849 if (defined($ENV{CONFIG_H})) {
1850 $config_h = read_config_h($ENV{CONFIG_H});
1853 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1854 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1856 my $extra_smbconf_options = "
1857 server services = -smb +s3fs
1858 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1860 dbwrap_tdb_mutexes:* = yes
1863 ${password_hash_gpg_key_ids}
1866 kernel change notify = no
1871 printcap name = /dev/null
1876 smbd:sharedelay = 100000
1877 smbd:writetimeupdatedelay = 500000
1880 check parent directory delete on close = yes
1882 dcerpc endpoint servers = -winreg -srvsvc
1884 printcap name = /dev/null
1886 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1887 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1890 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1891 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1892 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1893 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1894 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1895 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1896 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1898 print notify backchannel = yes
1900 server schannel = auto
1901 auth event notification = true
1902 dsdb event notification = true
1903 dsdb password event notification = true
1904 dsdb group change notification = true
1908 my $extra_smbconf_shares = "
1912 smb encrypt = required
1916 case sensitive = yes
1924 hide unreadable = yes
1928 kernel share modes = no
1947 my $extra_provision_options = undef;
1948 push (@{$extra_provision_options}, "--backend-store=mdb");
1949 print "PROVISIONING AD DC...\n";
1950 my $ret = $self->provision($prefix,
1951 "domain controller",
1959 $extra_smbconf_options,
1960 $extra_smbconf_shares,
1961 $extra_provision_options);
1962 unless (defined $ret) {
1966 unless($self->add_wins_config("$prefix/private")) {
1967 warn("Unable to add wins configuration");
1971 $ret->{DC_SERVER} = $ret->{SERVER};
1972 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1973 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1974 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1975 $ret->{DC_USERNAME} = $ret->{USERNAME};
1976 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1981 sub provision_chgdcpass($$)
1983 my ($self, $prefix) = @_;
1985 print "PROVISIONING CHGDCPASS...\n";
1986 my $extra_provision_options = undef;
1987 # This environment disallows the use of this password
1988 # (and also removes the default AD complexity checks)
1989 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1990 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1991 my $ret = $self->provision($prefix,
1992 "domain controller",
1995 "chgdcpassword.samba.example.com",
2000 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
2002 $extra_provision_options);
2003 unless (defined $ret) {
2007 unless($self->add_wins_config("$prefix/private")) {
2008 warn("Unable to add wins configuration");
2012 # Remove secrets.tdb from this environment to test that we
2013 # still start up on systems without the new matching
2014 # secrets.tdb records.
2015 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2016 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2020 $ret->{DC_SERVER} = $ret->{SERVER};
2021 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2022 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2023 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2024 $ret->{DC_USERNAME} = $ret->{USERNAME};
2025 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2026 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2031 sub teardown_env_terminate($$)
2033 my ($self, $envvars) = @_;
2036 # This should cause samba to terminate gracefully
2037 close($envvars->{STDIN_PIPE});
2039 $pid = $envvars->{SAMBA_PID};
2043 # This should give it time to write out the gcov data
2044 until ($count > 15) {
2045 if (Samba::cleanup_child($pid, "samba") != 0) {
2052 # After 15 Seconds, work out why this thing is still alive
2053 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2054 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2056 until ($count > 30) {
2057 if (Samba::cleanup_child($pid, "samba") != 0) {
2064 if (kill(0, $pid)) {
2065 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2069 until ($count > 40) {
2070 if (Samba::cleanup_child($pid, "samba") != 0) {
2076 # If it is still around, kill it
2077 if (kill(0, $pid)) {
2078 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2084 sub teardown_env($$)
2086 my ($self, $envvars) = @_;
2087 teardown_env_terminate($self, $envvars);
2089 $self->slapd_stop($envvars) if ($self->{ldap});
2091 print $self->getlog_env($envvars);
2098 my ($self, $envvars) = @_;
2099 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2102 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2104 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2108 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2111 return "" if $out eq $title;
2118 my ($self, $envvars) = @_;
2119 my $samba_pid = $envvars->{SAMBA_PID};
2121 if (not defined($samba_pid)) {
2123 } elsif ($samba_pid > 0) {
2124 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2126 if ($childpid == 0) {
2135 # Declare the environments Samba4 makes available.
2136 # To be set up, they will be called as
2137 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2138 %Samba4::ENV_DEPS = (
2139 # name => [dep_1, dep_2, ...],
2143 ad_dc_no_ntlm => [],
2147 fl2008r2dc => ["ad_dc"],
2148 fl2003dc => ["ad_dc"],
2151 vampire_2000_dc => ["fl2000dc"],
2152 vampire_dc => ["ad_dc_ntvfs"],
2153 promoted_dc => ["ad_dc_ntvfs"],
2154 subdom_dc => ["ad_dc_ntvfs"],
2156 rodc => ["ad_dc_ntvfs"],
2157 rpc_proxy => ["ad_dc_ntvfs"],
2160 s4member_dflt_domain => ["ad_dc_ntvfs"],
2161 s4member => ["ad_dc_ntvfs"],
2163 restoredc => ["backupfromdc"],
2170 my ($self, $path, $dc_vars) = @_;
2172 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2175 if (not defined($self->check_or_start($env, "standard"))) {
2183 sub setup_s4member_dflt_domain
2185 my ($self, $path, $dc_vars) = @_;
2187 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2188 "winbind use default domain = yes");
2191 if (not defined($self->check_or_start($env, "standard"))) {
2201 my ($self, $path, $dc_vars) = @_;
2203 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2206 if (not defined($self->check_or_start($env, "standard"))) {
2213 sub setup_ad_dc_ntvfs
2215 my ($self, $path) = @_;
2217 my $env = $self->provision_ad_dc_ntvfs($path);
2219 if (not defined($self->check_or_start($env, "standard"))) {
2220 warn("Failed to start ad_dc_ntvfs");
2229 my ($self, $path) = @_;
2231 my $env = $self->provision_chgdcpass($path);
2233 if (not defined($self->check_or_start($env, "standard"))) {
2242 my ($self, $path) = @_;
2244 my $env = $self->provision_fl2000dc($path);
2246 if (not defined($self->check_or_start($env, "standard"))) {
2256 my ($self, $path, $dc_vars) = @_;
2258 my $env = $self->provision_fl2003dc($path);
2261 if (not defined($self->check_or_start($env, "standard"))) {
2265 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2270 sub setup_fl2008r2dc
2272 my ($self, $path, $dc_vars) = @_;
2274 my $env = $self->provision_fl2008r2dc($path);
2277 if (not defined($self->check_or_start($env, "standard"))) {
2281 my $upn_array = ["$env->{REALM}.upn"];
2282 my $spn_array = ["$env->{REALM}.spn"];
2284 $self->setup_namespaces($env, $upn_array, $spn_array);
2286 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2292 sub setup_vampire_dc
2294 return setup_generic_vampire_dc(@_, "2008");
2297 sub setup_vampire_2000_dc
2299 return setup_generic_vampire_dc(@_, "2000");
2302 sub setup_generic_vampire_dc
2304 my ($self, $path, $dc_vars, $fl) = @_;
2306 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2309 if (not defined($self->check_or_start($env, "single"))) {
2313 # force replicated DC to update repsTo/repsFrom
2314 # for vampired partitions
2315 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2317 # as 'vampired' dc may add data in its local replica
2318 # we need to synchronize data between DCs
2319 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2321 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2322 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2323 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2325 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2327 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2328 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2329 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2330 $cmd .= " $dc_vars->{CONFIGURATION}";
2331 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2332 # replicate Configuration NC
2333 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2334 unless(system($cmd_repl) == 0) {
2335 warn("Failed to replicate\n$cmd_repl");
2338 # replicate Default NC
2339 $cmd_repl = "$cmd \"$base_dn\"";
2340 unless(system($cmd_repl) == 0) {
2341 warn("Failed to replicate\n$cmd_repl");
2345 # Pull in a full set of changes from the main DC
2346 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2348 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2349 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2350 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2352 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2354 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2355 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2356 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2357 $cmd .= " $dc_vars->{CONFIGURATION}";
2358 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2359 # replicate Configuration NC
2360 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2361 unless(system($cmd_repl) == 0) {
2362 warn("Failed to replicate\n$cmd_repl");
2365 # replicate Default NC
2366 $cmd_repl = "$cmd \"$base_dn\"";
2367 unless(system($cmd_repl) == 0) {
2368 warn("Failed to replicate\n$cmd_repl");
2376 sub setup_promoted_dc
2378 my ($self, $path, $dc_vars) = @_;
2380 my $env = $self->provision_promoted_dc($path, $dc_vars);
2383 if (not defined($self->check_or_start($env, "single"))) {
2387 # force source and replicated DC to update repsTo/repsFrom
2388 # for vampired partitions
2389 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2391 # as 'vampired' dc may add data in its local replica
2392 # we need to synchronize data between DCs
2393 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2394 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2395 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2396 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2397 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2398 $cmd .= " $dc_vars->{CONFIGURATION}";
2399 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2400 # replicate Configuration NC
2401 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2402 unless(system($cmd_repl) == 0) {
2403 warn("Failed to replicate\n$cmd_repl");
2406 # replicate Default NC
2407 $cmd_repl = "$cmd \"$base_dn\"";
2408 unless(system($cmd_repl) == 0) {
2409 warn("Failed to replicate\n$cmd_repl");
2419 my ($self, $path, $dc_vars) = @_;
2421 my $env = $self->provision_subdom_dc($path, $dc_vars);
2424 if (not defined($self->check_or_start($env, "single"))) {
2428 # force replicated DC to update repsTo/repsFrom
2429 # for primary domain partitions
2430 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2432 # as 'subdomain' dc may add data in its local replica
2433 # we need to synchronize data between DCs
2434 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2435 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2436 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2437 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2438 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2439 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2440 $cmd .= " $dc_vars->{CONFIGURATION}";
2441 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2442 # replicate Configuration NC
2443 my $cmd_repl = "$cmd \"$config_dn\"";
2444 unless(system($cmd_repl) == 0) {
2445 warn("Failed to replicate\n$cmd_repl");
2448 # replicate Default NC
2449 $cmd_repl = "$cmd \"$base_dn\"";
2450 unless(system($cmd_repl) == 0) {
2451 warn("Failed to replicate\n$cmd_repl");
2461 my ($self, $path, $dc_vars) = @_;
2463 my $env = $self->provision_rodc($path, $dc_vars);
2469 if (not defined($self->check_or_start($env, "standard"))) {
2473 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2476 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2477 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2478 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2479 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2480 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2481 $cmd .= " $dc_vars->{CONFIGURATION}";
2482 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2483 # replicate Configuration NC
2484 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2485 unless(system($cmd_repl) == 0) {
2486 warn("Failed to replicate\n$cmd_repl");
2489 # replicate Default NC
2490 $cmd_repl = "$cmd \"$base_dn\"";
2491 unless(system($cmd_repl) == 0) {
2492 warn("Failed to replicate\n$cmd_repl");
2501 my ($self, $path) = @_;
2503 # If we didn't build with ADS, pretend this env was never available
2504 if (not $self->{target3}->have_ads()) {
2508 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2509 "addom.samba.example.com", "");
2514 if (not defined($self->check_or_start($env, "single"))) {
2518 my $upn_array = ["$env->{REALM}.upn"];
2519 my $spn_array = ["$env->{REALM}.spn"];
2521 $self->setup_namespaces($env, $upn_array, $spn_array);
2526 sub setup_ad_dc_no_nss
2528 my ($self, $path) = @_;
2530 # If we didn't build with ADS, pretend this env was never available
2531 if (not $self->{target3}->have_ads()) {
2535 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2536 "adnonssdom.samba.example.com", "");
2541 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2542 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2544 if (not defined($self->check_or_start($env, "single"))) {
2548 my $upn_array = ["$env->{REALM}.upn"];
2549 my $spn_array = ["$env->{REALM}.spn"];
2551 $self->setup_namespaces($env, $upn_array, $spn_array);
2556 sub setup_ad_dc_no_ntlm
2558 my ($self, $path) = @_;
2560 # If we didn't build with ADS, pretend this env was never available
2561 if (not $self->{target3}->have_ads()) {
2565 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2566 "adnontlmdom.samba.example.com",
2567 "ntlm auth = disabled");
2572 if (not defined($self->check_or_start($env, "prefork"))) {
2576 my $upn_array = ["$env->{REALM}.upn"];
2577 my $spn_array = ["$env->{REALM}.spn"];
2579 $self->setup_namespaces($env, $upn_array, $spn_array);
2584 # Sets up a DC that's solely used to do a domain backup from. We then use the
2585 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2586 # process will create a Samba DC that will actually start up.
2587 # We don't use the backup-DC for anything else because its domain will conflict
2588 # with the restore DC.
2589 sub setup_backupfromdc
2591 my ($self, $path) = @_;
2593 # If we didn't build with ADS, pretend this env was never available
2594 if (not $self->{target3}->have_ads()) {
2598 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2599 "backupdom.samba.example.com", "");
2604 if (not defined($self->check_or_start($env, "standard"))) {
2608 my $upn_array = ["$env->{REALM}.upn"];
2609 my $spn_array = ["$env->{REALM}.spn"];
2611 $self->setup_namespaces($env, $upn_array, $spn_array);
2616 # Creates a backup of a running testenv DC
2619 # note: dcvars contains the env info for the backup DC testenv
2620 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2622 # get all the env variables we pass in with the samba-tool command
2624 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2625 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2626 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2628 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2630 # Note: use the backupfrom-DC's krb5.conf to do the backup
2631 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2632 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2634 # use samba-tool to create a backup from the 'backupfromdc' DC
2636 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2637 my $server = $dcvars->{DC_SERVER_IP};
2639 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd --server=$server";
2640 $cmd .= " --targetdir=$backupdir -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2642 print "Executing: $cmd\n";
2643 unless(system($cmd) == 0) {
2644 warn("Failed to create backup using: \n$cmd");
2648 # get the name of the backup file created
2649 opendir(DIR, $backupdir);
2650 my @files = grep(/\.tar/, readdir(DIR));
2653 if(scalar @files != 1) {
2654 warn("Backup file not found in directory $backupdir\n");
2657 my $backup_file = "$backupdir/$files[0]";
2658 print "Using backup file $backup_file...\n";
2660 return $backup_file;
2663 # Restores a backup-file to populate a testenv for a new DC
2664 sub restore_backup_file
2666 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2668 # pass the restore command the testenv's smb.conf that we've already
2669 # generated. But move it to a temp-dir first, so that the restore doesn't
2671 my $tmpdir = File::Temp->newdir();
2672 my $tmpconf = "$tmpdir/smb.conf";
2673 my $cmd = "cp $smbconf $tmpconf";
2674 unless(system($cmd) == 0) {
2675 warn("Failed to backup smb.conf using: \n$cmd");
2679 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2680 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2681 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2683 print "Executing: $cmd\n";
2684 unless(system($cmd) == 0) {
2685 warn("Failed to restore backup using: \n$cmd");
2689 print "Restore complete\n";
2693 # sets up the initial directory and returns the new testenv's env info
2694 # (without actually doing a 'domain join')
2695 sub prepare_dc_testenv
2697 my ($self, $prefix, $dcname, $domain, $realm, $password) = @_;
2699 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2709 # the restore uses a slightly different state-dir location to other testenvs
2710 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2711 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2713 # add support for sysvol/netlogon/tmp shares
2714 $ctx->{share} = "$ctx->{prefix_abs}/share";
2715 push(@{$ctx->{directories}}, "$ctx->{share}");
2717 $ctx->{smb_conf_extra_options} = "
2719 server max protocol = SMB2
2722 path = $ctx->{statedir}/sysvol
2726 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2730 path = $ctx->{share}
2732 posix:sharedelay = 10000
2733 posix:oplocktimeout = 3
2734 posix:writetimeupdatedelay = 50000
2738 my $env = $self->provision_raw_step1($ctx);
2740 $env->{DC_SERVER} = $env->{SERVER};
2741 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
2742 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
2743 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
2744 $env->{DC_USERNAME} = $env->{USERNAME};
2745 $env->{DC_PASSWORD} = $env->{PASSWORD};
2751 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2752 # commands. This proves that we can backup an online DC ('backupfromdc') and
2753 # use the backup file to create a valid, working samba DC.
2756 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2757 my ($self, $prefix, $dcvars) = @_;
2758 print "Preparing RESTORE DC...\n";
2760 my $env = $self->prepare_dc_testenv($prefix, "restoredc",
2761 $dcvars->{DOMAIN}, $dcvars->{REALM},
2762 $dcvars->{PASSWORD});
2764 # create a backup of the 'backupfromdc'
2765 my $backupdir = File::Temp->newdir();
2766 my $backup_file = $self->create_backup($env, $dcvars, $backupdir, "online");
2767 unless($backup_file) {
2771 # restore the backup file to populate the restore-DC testenv
2772 my $restore_dir = abs_path($prefix);
2773 my $ret = $self->restore_backup_file($backup_file,
2774 "--newservername=$env->{SERVER}",
2775 $restore_dir, $env->{SERVERCONFFILE});
2776 unless ($ret == 0) {
2780 # start samba for the restored DC
2781 if (not defined($self->check_or_start($env, "standard"))) {
2785 my $upn_array = ["$env->{REALM}.upn"];
2786 my $spn_array = ["$env->{REALM}.spn"];
2788 $self->setup_namespaces($env, $upn_array, $spn_array);
2795 my ($self, $path) = @_;
2798 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",