ctdb-recovery: Remove old code for creating missing databases
[Samba.git] / selftest / target / Samba4.pm
blob3e6692ce529b434f8ecb9a14cfe06a77d5f11dcc
1 #!/usr/bin/perl
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.
9 package Samba4;
11 use strict;
12 use Cwd qw(abs_path);
13 use FindBin qw($RealBin);
14 use POSIX;
15 use SocketWrapper;
16 use target::Samba;
17 use target::Samba3;
18 use Archive::Tar;
19 use File::Path 'make_path';
21 sub new($$$$$) {
22 my ($classname, $bindir, $srcdir, $server_maxtime) = @_;
24 my $self = {
25 vars => {},
26 bindir => $bindir,
27 srcdir => $srcdir,
28 server_maxtime => $server_maxtime,
29 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
31 bless $self;
32 return $self;
35 sub scriptdir_path($$) {
36 my ($self, $path) = @_;
37 return "$self->{srcdir}/source4/scripting/$path";
40 sub check_or_start($$$)
42 my ($self, $env_vars, $process_model) = @_;
43 my $STDIN_READER;
45 my $env_ok = $self->check_env($env_vars);
46 if ($env_ok) {
47 return $env_vars->{SAMBA_PID};
48 } elsif (defined($env_vars->{SAMBA_PID})) {
49 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
50 return undef;
53 # use a pipe for stdin in the child processes. This allows
54 # those processes to monitor the pipe for EOF to ensure they
55 # exit when the test script exits
56 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
58 # build up the command to run samba
59 my @preargs = ();
60 my @optargs = ();
61 if (defined($ENV{SAMBA_OPTIONS})) {
62 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
64 if(defined($ENV{SAMBA_VALGRIND})) {
65 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
68 if (defined($process_model)) {
69 push @optargs, ("-M", $process_model);
71 my $binary = Samba::bindir_path($self, "samba");
72 my @full_cmd = (@preargs, $binary, "-i",
73 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
74 $env_vars->{CONFIGURATION}, @optargs);
76 # the samba process takes some additional env variables (compared to s3)
77 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
78 $samba_envs->{RESOLV_CONF} = $env_vars->{RESOLV_CONF};
79 $samba_envs->{UID_WRAPPER} = "1";
80 if (defined($ENV{MITKRB5})) {
81 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
84 # fork a child process and exec() samba
85 my $daemon_ctx = {
86 NAME => "samba",
87 BINARY_PATH => $binary,
88 FULL_CMD => [ @full_cmd ],
89 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
90 TEE_STDOUT => 1,
91 ENV_VARS => $samba_envs,
93 my $pid = Samba::fork_and_exec($self, $env_vars, $daemon_ctx, $STDIN_READER);
95 $env_vars->{SAMBA_PID} = $pid;
97 # close the parent's read-end of the pipe
98 close($STDIN_READER);
100 if ($self->wait_for_start($env_vars) != 0) {
101 warn("Samba $pid failed to start up");
102 return undef;
105 return $pid;
108 sub wait_for_start($$)
110 my ($self, $testenv_vars) = @_;
111 my $count = 0;
112 my $ret = 0;
114 if (not $self->check_env($testenv_vars)) {
115 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
116 return -1;
119 # This will return quickly when things are up, but be slow if we
120 # need to wait for (eg) SSL init
121 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
123 do {
124 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
125 if ($ret != 0) {
126 sleep(1);
127 } else {
128 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
129 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
130 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
131 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
132 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
133 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
134 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
135 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
136 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
137 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
138 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
140 $count++;
141 } while ($ret != 0 && $count < 20);
142 if ($count == 20) {
143 teardown_env($self, $testenv_vars);
144 warn("nbt not reachable after 20 retries\n");
145 return -1;
148 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
149 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
150 print "waiting for working LDAP and a RID Set to be allocated\n";
151 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
152 my $count = 0;
153 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
155 my $search_dn = $base_dn;
156 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
157 # TODO currently no check for actual rIDAllocationPool
158 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
160 my $max_wait = 60;
162 # Add hosts file for name lookups
163 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
164 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
165 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
166 } else {
167 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
169 $cmd .= "RESOLV_CONF='$testenv_vars->{RESOLV_CONF}' ";
171 $cmd .= "$ldbsearch ";
172 $cmd .= "$testenv_vars->{CONFIGURATION} ";
173 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
174 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
175 $cmd .= "-s base ";
176 $cmd .= "-b '$search_dn' ";
177 while (system("$cmd >/dev/null") != 0) {
178 $count++;
179 if ($count > $max_wait) {
180 teardown_env($self, $testenv_vars);
181 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}");
182 return -1;
184 print "Waiting for working LDAP...\n";
185 sleep(1);
189 my $wbinfo = Samba::bindir_path($self, "wbinfo");
191 $count = 0;
192 do {
193 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
194 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
195 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
196 $cmd .= "$wbinfo -P";
197 $ret = system($cmd);
199 if ($ret != 0) {
200 sleep(1);
202 $count++;
203 } while ($ret != 0 && $count < 20);
204 if ($count == 20) {
205 teardown_env($self, $testenv_vars);
206 warn("winbind not reachable after 20 retries\n");
207 return -1;
210 # Ensure we registered all our names
211 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
212 my $max_wait = 120;
213 print "Waiting for dns_update_cache to be created.\n";
214 $count = 0;
215 while (not -e "$testenv_vars->{PRIVATEDIR}/dns_update_cache") {
216 $count++;
217 if ($count > $max_wait) {
218 teardown_env($self, $testenv_vars);
219 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
220 return -1;
222 print "Waiting for dns_update_cache to be created...\n";
223 sleep(1);
225 print "Waiting for dns_update_cache to be filled.\n";
226 $count = 0;
227 while ((-s "$testenv_vars->{PRIVATEDIR}/dns_update_cache") == 0) {
228 $count++;
229 if ($count > $max_wait) {
230 teardown_env($self, $testenv_vars);
231 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
232 return -1;
234 print "Waiting for dns_update_cache to be filled...\n";
235 sleep(1);
239 print $self->getlog_env($testenv_vars);
241 print "READY ($testenv_vars->{SAMBA_PID})\n";
243 return 0
246 sub write_ldb_file($$$)
248 my ($self, $file, $ldif) = @_;
250 my $ldbadd = Samba::bindir_path($self, "ldbadd");
251 open(LDIF, "|$ldbadd -H $file >/dev/null");
252 print LDIF $ldif;
253 return(close(LDIF));
256 sub add_wins_config($$)
258 my ($self, $privatedir) = @_;
259 my $client_ip = Samba::get_ipv4_addr("client");
261 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
262 dn: name=TORTURE_11,CN=PARTNERS
263 objectClass: wreplPartner
264 name: TORTURE_11
265 address: $client_ip
266 pullInterval: 0
267 pushChangeCount: 0
268 type: 0x3
272 sub setup_dns_hub_internal($$$)
274 my ($self, $hostname, $prefix) = @_;
275 my $STDIN_READER;
277 unless(-d $prefix or make_path($prefix, 0777)) {
278 warn("Unable to create $prefix");
279 return undef;
281 my $prefix_abs = abs_path($prefix);
283 die ("prefix=''") if $prefix_abs eq "";
284 die ("prefix='/'") if $prefix_abs eq "/";
286 unless (system("rm -rf $prefix_abs/*") == 0) {
287 warn("Unable to clean up");
290 my $env = undef;
291 $env->{NETBIOSNAME} = $hostname;
293 $env->{SERVER_IP} = Samba::get_ipv4_addr($hostname);
294 $env->{SERVER_IPV6} = Samba::get_ipv6_addr($hostname);
295 $env->{SOCKET_WRAPPER_DEFAULT_IFACE} = Samba::get_interface($hostname);
296 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
297 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
298 $env->{TESTENV_DIR} = $prefix_abs;
300 open(RESOLV_CONF, ">$env->{RESOLV_CONF}");
301 print RESOLV_CONF "nameserver $env->{SERVER_IP}\n";
302 print RESOLV_CONF "nameserver $env->{SERVER_IPV6}\n";
303 close(RESOLV_CONF);
305 my @preargs = ();
306 my @args = ();
307 if (!defined($ENV{PYTHON})) {
308 push (@preargs, "env");
309 push (@preargs, "python");
310 } else {
311 push (@preargs, $ENV{PYTHON});
313 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
314 push (@args, "$self->{server_maxtime}");
315 push (@args, "$env->{SERVER_IP}");
316 push (@args, Samba::realm_to_ip_mappings());
317 my @full_cmd = (@preargs, $binary, @args);
319 my $daemon_ctx = {
320 NAME => "dnshub",
321 BINARY_PATH => $binary,
322 FULL_CMD => [ @full_cmd ],
323 LOG_FILE => $env->{DNS_HUB_LOG},
324 TEE_STDOUT => 1,
325 PCAP_FILE => "$ENV{SOCKET_WRAPPER_PCAP_DIR}/env-$hostname$.pcap",
326 ENV_VARS => {},
329 # use a pipe for stdin in the child processes. This allows
330 # those processes to monitor the pipe for EOF to ensure they
331 # exit when the test script exits
332 pipe($STDIN_READER, $env->{STDIN_PIPE});
334 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
336 $env->{SAMBA_PID} = $pid;
337 $env->{KRB5_CONFIG} = "$prefix_abs/no_krb5.conf";
339 # close the parent's read-end of the pipe
340 close($STDIN_READER);
342 return $env;
345 sub setup_dns_hub
347 my ($self, $prefix) = @_;
349 my $hostname = "rootdnsforwarder";
351 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
353 $self->{dns_hub_env} = $env;
355 return $env;
358 sub get_dns_hub_env($)
360 my ($self, $prefix) = @_;
362 if (defined($self->{dns_hub_env})) {
363 return $self->{dns_hub_env};
366 die("get_dns_hub_env() not setup 'dns_hub_env'");
367 return undef;
370 # Returns the environmental variables that we pass to samba-tool commands
371 sub get_cmd_env_vars
373 my ($self, $localenv) = @_;
375 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
376 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
377 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
378 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
379 } else {
380 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
382 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
383 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
384 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
386 return $cmd_env;
389 # Sets up a forest trust namespace.
390 # (Note this is different to kernel namespaces, setup by the
391 # USE_NAMESPACES=1 option)
392 sub setup_namespaces($$:$$)
394 my ($self, $localenv, $upn_array, $spn_array) = @_;
396 @{$upn_array} = [] unless defined($upn_array);
397 my $upn_args = "";
398 foreach my $upn (@{$upn_array}) {
399 $upn_args .= " --add-upn-suffix=$upn";
402 @{$spn_array} = [] unless defined($spn_array);
403 my $spn_args = "";
404 foreach my $spn (@{$spn_array}) {
405 $spn_args .= " --add-spn-suffix=$spn";
408 my $samba_tool = Samba::bindir_path($self, "samba-tool");
410 my $cmd_env = $self->get_cmd_env_vars($localenv);
412 my $cmd_config = " $localenv->{CONFIGURATION}";
414 my $namespaces = $cmd_env;
415 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
416 $namespaces .= $cmd_config;
417 unless (system($namespaces) == 0) {
418 warn("Failed to add namespaces \n$namespaces");
419 return;
422 return;
425 sub setup_trust($$$$$)
427 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
429 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
431 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
432 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
433 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
434 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
435 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
437 my $samba_tool = Samba::bindir_path($self, "samba-tool");
439 # setup the trust
440 my $cmd_env = $self->get_cmd_env_vars($localenv);
442 my $cmd_config = " $localenv->{CONFIGURATION}";
443 my $cmd_creds = $cmd_config;
444 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
446 my $create = $cmd_env;
447 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
448 $create .= " $extra_args";
449 $create .= $cmd_creds;
450 unless (system($create) == 0) {
451 warn("Failed to create trust \n$create");
452 return undef;
455 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
456 my $groupadd = $cmd_env;
457 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
458 unless (system($groupadd) == 0) {
459 warn("Failed to create group \n$groupadd");
460 return undef;
462 my $groupmem = $cmd_env;
463 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
464 unless (system($groupmem) == 0) {
465 warn("Failed to add group member \n$groupmem");
466 return undef;
469 return $localenv
472 sub provision_raw_prepare($$$$$$$$$$$$)
474 my ($self, $prefix, $server_role, $hostname,
475 $domain, $realm, $samsid, $functional_level,
476 $password, $kdc_ipv4, $kdc_ipv6) = @_;
477 my $ctx;
478 my $python_cmd = "";
479 if (defined $ENV{PYTHON}) {
480 $python_cmd = $ENV{PYTHON} . " ";
482 $ctx->{python} = $python_cmd;
483 my $netbiosname = uc($hostname);
485 unless(-d $prefix or mkdir($prefix, 0777)) {
486 warn("Unable to create $prefix");
487 return undef;
489 my $prefix_abs = abs_path($prefix);
491 die ("prefix=''") if $prefix_abs eq "";
492 die ("prefix='/'") if $prefix_abs eq "/";
494 unless (system("rm -rf $prefix_abs/*") == 0) {
495 warn("Unable to clean up");
499 my $swiface = Samba::get_interface($hostname);
501 $ctx->{prefix} = $prefix;
502 $ctx->{prefix_abs} = $prefix_abs;
504 $ctx->{server_role} = $server_role;
505 $ctx->{hostname} = $hostname;
506 $ctx->{netbiosname} = $netbiosname;
507 $ctx->{swiface} = $swiface;
508 $ctx->{password} = $password;
509 $ctx->{kdc_ipv4} = $kdc_ipv4;
510 $ctx->{kdc_ipv6} = $kdc_ipv6;
511 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
512 if ($functional_level eq "2000") {
513 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
517 # Set smbd log level here.
519 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
520 $ctx->{username} = "Administrator";
521 $ctx->{domain} = $domain;
522 $ctx->{realm} = uc($realm);
523 $ctx->{dnsname} = lc($realm);
524 $ctx->{samsid} = $samsid;
526 $ctx->{functional_level} = $functional_level;
528 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
529 chomp $unix_name;
530 $ctx->{unix_name} = $unix_name;
531 $ctx->{unix_uid} = $>;
532 my @mygid = split(" ", $();
533 $ctx->{unix_gid} = $mygid[0];
534 $ctx->{unix_gids_str} = $);
535 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
537 $ctx->{etcdir} = "$prefix_abs/etc";
538 $ctx->{piddir} = "$prefix_abs/pid";
539 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
540 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
541 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
542 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
543 $ctx->{privatedir} = "$prefix_abs/private";
544 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
545 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
546 $ctx->{lockdir} = "$prefix_abs/lockdir";
547 $ctx->{logdir} = "$prefix_abs/logs";
548 $ctx->{statedir} = "$prefix_abs/statedir";
549 $ctx->{cachedir} = "$prefix_abs/cachedir";
550 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
551 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
552 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
553 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
554 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
555 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
556 if ($ENV{SAMBA_DNS_FAKING}) {
557 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
558 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
559 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
560 } else {
561 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
562 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
563 $ctx->{use_resolv_wrapper} = 1;
566 my $dns_hub = $self->get_dns_hub_env();
567 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
569 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
571 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
572 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
574 push(@{$ctx->{directories}}, $ctx->{privatedir});
575 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
576 push(@{$ctx->{directories}}, $ctx->{etcdir});
577 push(@{$ctx->{directories}}, $ctx->{piddir});
578 push(@{$ctx->{directories}}, $ctx->{lockdir});
579 push(@{$ctx->{directories}}, $ctx->{logdir});
580 push(@{$ctx->{directories}}, $ctx->{statedir});
581 push(@{$ctx->{directories}}, $ctx->{cachedir});
583 $ctx->{smb_conf_extra_options} = "";
585 my @provision_options = ();
586 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
587 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
588 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
589 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
590 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
591 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
592 if (defined($ctx->{use_resolv_wrapper})) {
593 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
594 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
595 } else {
596 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
598 if (defined($ENV{GDB_PROVISION})) {
599 push (@provision_options, "gdb --args");
600 if (!defined($ENV{PYTHON})) {
601 push (@provision_options, "env");
602 push (@provision_options, "python");
605 if (defined($ENV{VALGRIND_PROVISION})) {
606 push (@provision_options, "valgrind");
607 if (!defined($ENV{PYTHON})) {
608 push (@provision_options, "env");
609 push (@provision_options, "python");
613 my $samba_tool = Samba::bindir_path($self, "samba-tool");
615 push (@provision_options, $samba_tool);
616 push (@provision_options, "domain");
617 push (@provision_options, "provision");
618 push (@provision_options, "--configfile=$ctx->{smb_conf}");
619 push (@provision_options, "--host-name=$ctx->{hostname}");
620 push (@provision_options, "--host-ip=$ctx->{ipv4}");
621 push (@provision_options, "--quiet");
622 push (@provision_options, "--domain=$ctx->{domain}");
623 push (@provision_options, "--realm=$ctx->{realm}");
624 if (defined($ctx->{samsid})) {
625 push (@provision_options, "--domain-sid=$ctx->{samsid}");
627 push (@provision_options, "--adminpass=$ctx->{password}");
628 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
629 push (@provision_options, "--machinepass=machine$ctx->{password}");
630 push (@provision_options, "--root=$ctx->{unix_name}");
631 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
632 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
634 @{$ctx->{provision_options}} = @provision_options;
636 return $ctx;
639 sub has_option
641 my ($self, $keyword, @options_list) = @_;
643 # convert the options-list to a hash-map for easy keyword lookup
644 my %options_dict = map { $_ => 1 } @options_list;
646 return exists $options_dict{$keyword};
650 # Step1 creates the basic configuration
652 sub provision_raw_step1($$)
654 my ($self, $ctx) = @_;
656 mkdir($_, 0777) foreach (@{$ctx->{directories}});
659 ## lockdir and piddir must be 0755
661 chmod 0755, $ctx->{lockdir};
662 chmod 0755, $ctx->{piddir};
664 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
665 warn("can't open $ctx->{smb_conf}$?");
666 return undef;
669 Samba::prepare_keyblobs($ctx);
670 my $crlfile = "$ctx->{tlsdir}/crl.pem";
671 $crlfile = "" unless -e ${crlfile};
673 # work out which file server to use. Default to source3 smbd (s3fs),
674 # unless the source4 NTVFS (smb) file server has been specified
675 my $services = "-smb +s3fs";
676 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
677 $services = "+smb -s3fs";
680 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
682 print CONFFILE "
683 [global]
684 netbios name = $ctx->{netbiosname}
685 posix:eadb = $ctx->{statedir}/eadb.tdb
686 workgroup = $ctx->{domain}
687 realm = $ctx->{realm}
688 private dir = $ctx->{privatedir}
689 binddns dir = $ctx->{binddnsdir}
690 pid directory = $ctx->{piddir}
691 ncalrpc dir = $ctx->{ncalrpcdir}
692 lock dir = $ctx->{lockdir}
693 state directory = $ctx->{statedir}
694 cache directory = $ctx->{cachedir}
695 winbindd socket directory = $ctx->{winbindd_socket_dir}
696 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
697 winbind separator = /
698 interfaces = $interfaces
699 tls dh params file = $ctx->{tlsdir}/dhparms.pem
700 tls crlfile = ${crlfile}
701 tls verify peer = no_check
702 panic action = $RealBin/gdb_backtrace \%d
703 wins support = yes
704 server role = $ctx->{server_role}
705 server services = +echo $services
706 dcerpc endpoint servers = +winreg +srvsvc
707 notify:inotify = false
708 ldb:nosync = true
709 ldap server require strong auth = yes
710 #We don't want to pass our self-tests if the PAC code is wrong
711 gensec:require_pac = true
712 log file = $ctx->{logdir}/log.\%m
713 log level = $ctx->{server_loglevel}
714 lanman auth = Yes
715 ntlm auth = Yes
716 client min protocol = CORE
717 server min protocol = LANMAN1
718 mangled names = yes
719 dns update command = $ctx->{samba_dnsupdate}
720 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
721 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
722 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
723 dreplsrv:periodic_startup_interval = 0
724 dsdb:schema update allowed = yes
726 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
728 idmap_ldb:use rfc2307=yes
729 winbind enum users = yes
730 winbind enum groups = yes
732 rpc server port:netlogon = 1026
733 include system krb5 conf = no
737 print CONFFILE "
739 # Begin extra options
740 $ctx->{smb_conf_extra_options}
741 # End extra options
743 close(CONFFILE);
745 #Default the KDC IP to the server's IP
746 if (not defined($ctx->{kdc_ipv4})) {
747 $ctx->{kdc_ipv4} = $ctx->{ipv4};
749 if (not defined($ctx->{kdc_ipv6})) {
750 $ctx->{kdc_ipv6} = $ctx->{ipv6};
753 Samba::mk_krb5_conf($ctx);
754 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
756 open(PWD, ">$ctx->{nsswrap_passwd}");
757 if ($ctx->{unix_uid} != 0) {
758 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
760 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
761 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
762 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
763 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
764 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
765 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
767 close(PWD);
768 my $uid_rfc2307test = 65533;
770 open(GRP, ">$ctx->{nsswrap_group}");
771 if ($ctx->{unix_gid} != 0) {
772 print GRP "root:x:0:\n";
774 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
775 print GRP "wheel:x:10:
776 users:x:65531:
777 nobody:x:65533:
778 nogroup:x:65534:nobody
780 close(GRP);
781 my $gid_rfc2307test = 65532;
783 my $hostname = lc($ctx->{hostname});
784 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
785 if ($hostname eq "localdc") {
786 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
787 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
788 } else {
789 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
790 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
792 close(HOSTS);
794 my $configuration = "--configfile=$ctx->{smb_conf}";
796 #Ensure the config file is valid before we start
797 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
798 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
799 system("$testparm -v --suppress-prompt $configuration >&2");
800 warn("Failed to create a valid smb.conf configuration $testparm!");
801 return undef;
803 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) {
804 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
805 return undef;
808 # Return the environment variables for the new testenv DC.
809 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
810 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
811 my $ret = {
812 KRB5_CONFIG => $ctx->{krb5_conf},
813 KRB5_CCACHE => $ctx->{krb5_ccache},
814 MITKDC_CONFIG => $ctx->{mitkdc_conf},
815 PIDDIR => $ctx->{piddir},
816 SERVER => $ctx->{hostname},
817 DC_SERVER => $ctx->{hostname},
818 SERVER_IP => $ctx->{ipv4},
819 DC_SERVER_IP => $ctx->{ipv4},
820 SERVER_IPV6 => $ctx->{ipv6},
821 DC_SERVER_IPV6 => $ctx->{ipv6},
822 NETBIOSNAME => $ctx->{netbiosname},
823 DC_NETBIOSNAME => $ctx->{netbiosname},
824 DOMAIN => $ctx->{domain},
825 USERNAME => $ctx->{username},
826 DC_USERNAME => $ctx->{username},
827 REALM => $ctx->{realm},
828 DNSNAME => $ctx->{dnsname},
829 SAMSID => $ctx->{samsid},
830 PASSWORD => $ctx->{password},
831 DC_PASSWORD => $ctx->{password},
832 LDAPDIR => $ctx->{ldapdir},
833 LDAP_INSTANCE => $ctx->{ldap_instance},
834 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
835 NCALRPCDIR => $ctx->{ncalrpcdir},
836 LOCKDIR => $ctx->{lockdir},
837 STATEDIR => $ctx->{statedir},
838 CACHEDIR => $ctx->{cachedir},
839 PRIVATEDIR => $ctx->{privatedir},
840 BINDDNSDIR => $ctx->{binddnsdir},
841 SERVERCONFFILE => $ctx->{smb_conf},
842 TESTENV_DIR => $ctx->{prefix_abs},
843 CONFIGURATION => $configuration,
844 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
845 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
846 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
847 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
848 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
849 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
850 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
851 SAMBA_TEST_LOG_POS => 0,
852 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
853 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
854 LOCAL_PATH => $ctx->{share},
855 UID_RFC2307TEST => $uid_rfc2307test,
856 GID_RFC2307TEST => $gid_rfc2307test,
857 SERVER_ROLE => $ctx->{server_role},
858 RESOLV_CONF => $ctx->{resolv_conf}
861 if (defined($ctx->{use_resolv_wrapper})) {
862 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
863 } else {
864 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
867 if ($ctx->{server_role} eq "domain controller") {
868 $ret->{DOMSID} = $ret->{SAMSID};
871 return $ret;
875 # Step2 runs the provision script
877 sub provision_raw_step2($$$)
879 my ($self, $ctx, $ret) = @_;
881 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
882 unless (system($provision_cmd) == 0) {
883 warn("Unable to provision: \n$provision_cmd\n");
884 return undef;
887 my $testallowed_account = "testallowed";
888 my $samba_tool_cmd = "";
889 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
890 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
891 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
892 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
893 unless (system($samba_tool_cmd) == 0) {
894 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
895 return undef;
898 my $ldbmodify = "";
899 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
900 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
901 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
902 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
903 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
905 if ($ctx->{server_role} ne "domain controller") {
906 $base_dn = "DC=$ctx->{netbiosname}";
909 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
910 $testallowed_account = "testallowed account";
911 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
912 print LDIF "dn: $user_dn
913 changetype: modify
914 replace: samAccountName
915 samAccountName: $testallowed_account
918 close(LDIF);
920 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
921 print LDIF "dn: $user_dn
922 changetype: modify
923 replace: userPrincipalName
924 userPrincipalName: testallowed upn\@$ctx->{realm}
925 replace: servicePrincipalName
926 servicePrincipalName: host/testallowed
929 close(LDIF);
931 $samba_tool_cmd = "";
932 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
933 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
934 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
935 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
936 unless (system($samba_tool_cmd) == 0) {
937 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
938 return undef;
941 my $user_dn = "cn=testdenied,cn=users,$base_dn";
942 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
943 print LDIF "dn: $user_dn
944 changetype: modify
945 replace: userPrincipalName
946 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
949 close(LDIF);
951 $samba_tool_cmd = "";
952 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
953 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
954 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
955 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
956 unless (system($samba_tool_cmd) == 0) {
957 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
958 return undef;
961 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
962 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
963 print LDIF "dn: $user_dn
964 changetype: modify
965 replace: userPrincipalName
966 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
967 replace: servicePrincipalName
968 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
971 close(LDIF);
973 $samba_tool_cmd = "";
974 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
975 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
976 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
977 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
978 unless (system($samba_tool_cmd) == 0) {
979 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
980 return undef;
983 # Create to users alice and bob!
984 my $user_account_array = ["alice", "bob", "jane"];
986 foreach my $user_account (@{$user_account_array}) {
987 my $samba_tool_cmd = "";
989 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
990 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
991 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
992 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
993 unless (system($samba_tool_cmd) == 0) {
994 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
995 return undef;
999 my $ldbmodify = "";
1000 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1001 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1002 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1003 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1004 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1005 my $user_dn = "cn=jane,cn=users,$base_dn";
1007 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1008 print LDIF "dn: $user_dn
1009 changetype: modify
1010 replace: userPrincipalName
1011 userPrincipalName: jane.doe\@$ctx->{realm}
1014 close(LDIF);
1016 return $ret;
1019 sub provision($$$$$$$$$$)
1021 my ($self, $prefix, $server_role, $hostname,
1022 $domain, $realm, $functional_level,
1023 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
1024 $extra_provision_options) = @_;
1026 my $samsid = Samba::random_domain_sid();
1028 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1029 $hostname,
1030 $domain, $realm,
1031 $samsid,
1032 $functional_level,
1033 $password, $kdc_ipv4, $kdc_ipv6);
1035 if (defined($extra_provision_options)) {
1036 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
1039 $ctx->{share} = "$ctx->{prefix_abs}/share";
1040 push(@{$ctx->{directories}}, "$ctx->{share}");
1041 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1042 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1044 # precreate directories for printer drivers
1045 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1046 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1047 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1049 my $msdfs = "no";
1050 $msdfs = "yes" if ($server_role eq "domain controller");
1051 $ctx->{smb_conf_extra_options} = "
1053 max xmit = 32K
1054 server max protocol = SMB2
1055 host msdfs = $msdfs
1056 lanman auth = yes
1058 # fruit:copyfile is a global option
1059 fruit:copyfile = yes
1061 $extra_smbconf_options
1063 [tmp]
1064 path = $ctx->{share}
1065 read only = no
1066 posix:sharedelay = 100000
1067 posix:oplocktimeout = 3
1068 posix:writetimeupdatedelay = 500000
1070 [xcopy_share]
1071 path = $ctx->{share}
1072 read only = no
1073 posix:sharedelay = 100000
1074 posix:oplocktimeout = 3
1075 posix:writetimeupdatedelay = 500000
1076 create mask = 777
1077 force create mode = 777
1079 [posix_share]
1080 path = $ctx->{share}
1081 read only = no
1082 create mask = 0777
1083 force create mode = 0
1084 directory mask = 0777
1085 force directory mode = 0
1087 [test1]
1088 path = $ctx->{share}/test1
1089 read only = no
1090 posix:sharedelay = 100000
1091 posix:oplocktimeout = 3
1092 posix:writetimeupdatedelay = 500000
1094 [test2]
1095 path = $ctx->{share}/test2
1096 read only = no
1097 posix:sharedelay = 100000
1098 posix:oplocktimeout = 3
1099 posix:writetimeupdatedelay = 500000
1101 [cifs]
1102 path = $ctx->{share}/_ignore_cifs_
1103 read only = no
1104 ntvfs handler = cifs
1105 cifs:server = $ctx->{netbiosname}
1106 cifs:share = tmp
1107 cifs:use-s4u2proxy = yes
1108 # There is no username specified here, instead the client is expected
1109 # to log in with kerberos, and the serverwill use delegated credentials.
1110 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1112 [simple]
1113 path = $ctx->{share}
1114 read only = no
1115 ntvfs handler = simple
1117 [sysvol]
1118 path = $ctx->{statedir}/sysvol
1119 read only = no
1121 [netlogon]
1122 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1123 read only = no
1125 [cifsposix]
1126 copy = simple
1127 ntvfs handler = cifsposix
1129 [vfs_fruit]
1130 path = $ctx->{share}
1131 vfs objects = catia fruit streams_xattr acl_xattr
1132 ea support = yes
1133 fruit:resource = file
1134 fruit:metadata = netatalk
1135 fruit:locking = netatalk
1136 fruit:encoding = native
1138 [xattr]
1139 path = $ctx->{share}
1140 # This can be used for testing real fs xattr stuff
1141 vfs objects = streams_xattr acl_xattr
1143 $extra_smbconf_shares
1146 my $ret = $self->provision_raw_step1($ctx);
1147 unless (defined $ret) {
1148 return undef;
1151 return $self->provision_raw_step2($ctx, $ret);
1154 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1155 # original DC) in the testenv. $SERVER is always the joined DC that we are
1156 # actually running the test against
1157 sub set_pdc_env_vars
1159 my ($self, $env, $dcvars) = @_;
1161 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1162 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1163 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1164 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1165 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1166 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1167 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1170 sub provision_s4member($$$$$)
1172 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1173 print "PROVISIONING MEMBER...\n";
1174 my $extra_smb_conf = "
1175 passdb backend = samba_dsdb
1176 winbindd:use external pipes = true
1178 # the source4 smb server doesn't allow signing by default
1179 server signing = enabled
1180 raw NTLMv2 auth = yes
1182 rpc_server:default = external
1183 rpc_server:svcctl = embedded
1184 rpc_server:srvsvc = embedded
1185 rpc_server:eventlog = embedded
1186 rpc_server:ntsvcs = embedded
1187 rpc_server:winreg = embedded
1188 rpc_server:spoolss = embedded
1189 rpc_daemon:spoolssd = embedded
1190 rpc_server:tcpip = no
1192 if ($more_conf) {
1193 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1195 my $extra_provision_options = ["--use-ntvfs"];
1196 my $ret = $self->provision($prefix,
1197 "member server",
1198 $hostname,
1199 $dcvars->{DOMAIN},
1200 $dcvars->{REALM},
1201 "2008",
1202 "locMEMpass3",
1203 $dcvars->{SERVER_IP},
1204 $dcvars->{SERVER_IPV6},
1205 $extra_smb_conf, "",
1206 $extra_provision_options);
1207 unless ($ret) {
1208 return undef;
1211 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1212 my $cmd = $self->get_cmd_env_vars($ret);
1213 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1214 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1215 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1217 unless (system($cmd) == 0) {
1218 warn("Join failed\n$cmd");
1219 return undef;
1222 $ret->{DOMSID} = $dcvars->{DOMSID};
1223 $self->set_pdc_env_vars($ret, $dcvars);
1225 return $ret;
1228 sub provision_rpc_proxy($$$)
1230 my ($self, $prefix, $dcvars) = @_;
1231 print "PROVISIONING RPC PROXY...\n";
1233 my $extra_smbconf_options = "
1234 passdb backend = samba_dsdb
1236 # rpc_proxy
1237 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1238 dcerpc endpoint servers = epmapper, remote
1239 dcerpc_remote:interfaces = rpcecho
1240 dcerpc_remote:allow_anonymous_fallback = yes
1242 [cifs_to_dc]
1243 path = /tmp/_ignore_cifs_to_dc_/_none_
1244 read only = no
1245 ntvfs handler = cifs
1246 cifs:server = $dcvars->{SERVER}
1247 cifs:share = cifs
1248 cifs:use-s4u2proxy = yes
1249 # There is no username specified here, instead the client is expected
1250 # to log in with kerberos, and the serverwill use delegated credentials.
1251 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1255 my $extra_provision_options = ["--use-ntvfs"];
1256 my $ret = $self->provision($prefix,
1257 "member server",
1258 "localrpcproxy",
1259 $dcvars->{DOMAIN},
1260 $dcvars->{REALM},
1261 "2008",
1262 "locRPCproxypass4",
1263 $dcvars->{SERVER_IP},
1264 $dcvars->{SERVER_IPV6},
1265 $extra_smbconf_options, "",
1266 $extra_provision_options);
1267 unless ($ret) {
1268 return undef;
1271 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1273 # The joind runs in the context of the rpc_proxy/member for now
1274 my $cmd = $self->get_cmd_env_vars($ret);
1275 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1276 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1277 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1279 unless (system($cmd) == 0) {
1280 warn("Join failed\n$cmd");
1281 return undef;
1284 # Setting up delegation runs in the context of the DC for now
1285 $cmd = "";
1286 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1287 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1288 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1289 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1290 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1291 $cmd .= " $dcvars->{CONFIGURATION}";
1292 print $cmd;
1294 unless (system($cmd) == 0) {
1295 warn("Delegation failed\n$cmd");
1296 return undef;
1299 # Setting up delegation runs in the context of the DC for now
1300 $cmd = "";
1301 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1302 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1303 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1304 $cmd .= "RESOLV_CONF=\"$dcvars->{RESOLV_CONF}\" ";
1305 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1306 $cmd .= " $dcvars->{CONFIGURATION}";
1308 unless (system($cmd) == 0) {
1309 warn("Delegation failed\n$cmd");
1310 return undef;
1313 $ret->{DOMSID} = $dcvars->{DOMSID};
1314 $self->set_pdc_env_vars($ret, $dcvars);
1316 return $ret;
1319 sub provision_promoted_dc($$$)
1321 my ($self, $prefix, $dcvars) = @_;
1322 print "PROVISIONING PROMOTED DC...\n";
1324 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1325 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1326 "promotedvdc",
1327 $dcvars->{DOMAIN},
1328 $dcvars->{REALM},
1329 $dcvars->{SAMSID},
1330 "2008",
1331 $dcvars->{PASSWORD},
1332 $dcvars->{SERVER_IP},
1333 $dcvars->{SERVER_IPV6});
1335 $ctx->{smb_conf_extra_options} = "
1336 max xmit = 32K
1337 server max protocol = SMB2
1339 ntlm auth = ntlmv2-only
1341 [sysvol]
1342 path = $ctx->{statedir}/sysvol
1343 read only = yes
1345 [netlogon]
1346 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1347 read only = no
1351 my $ret = $self->provision_raw_step1($ctx);
1352 unless ($ret) {
1353 return undef;
1356 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1357 my $cmd = $self->get_cmd_env_vars($ret);
1358 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1359 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1360 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1362 unless (system($cmd) == 0) {
1363 warn("Join failed\n$cmd");
1364 return undef;
1367 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1368 my $cmd = $self->get_cmd_env_vars($ret);
1369 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1370 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1371 $cmd .= " --machinepass=machine$ret->{PASSWORD} --dns-backend=BIND9_DLZ";
1373 unless (system($cmd) == 0) {
1374 warn("Join failed\n$cmd");
1375 return undef;
1378 $self->set_pdc_env_vars($ret, $dcvars);
1380 return $ret;
1383 sub provision_vampire_dc($$$)
1385 my ($self, $prefix, $dcvars, $fl) = @_;
1386 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1387 my $name = "localvampiredc";
1388 my $extra_conf = "";
1390 if ($fl == "2000") {
1391 $name = "vampire2000dc";
1392 } else {
1393 $extra_conf = "drs: immediate link sync = yes
1394 drs: max link sync = 250";
1397 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1398 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1399 $name,
1400 $dcvars->{DOMAIN},
1401 $dcvars->{REALM},
1402 $dcvars->{DOMSID},
1403 $fl,
1404 $dcvars->{PASSWORD},
1405 $dcvars->{SERVER_IP},
1406 $dcvars->{SERVER_IPV6});
1408 $ctx->{smb_conf_extra_options} = "
1409 max xmit = 32K
1410 server max protocol = SMB2
1412 ntlm auth = mschapv2-and-ntlmv2-only
1413 $extra_conf
1415 [sysvol]
1416 path = $ctx->{statedir}/sysvol
1417 read only = yes
1419 [netlogon]
1420 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1421 read only = no
1425 my $ret = $self->provision_raw_step1($ctx);
1426 unless ($ret) {
1427 return undef;
1430 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1431 my $cmd = $self->get_cmd_env_vars($ret);
1432 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1433 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1434 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1435 $cmd .= " --backend-store=mdb";
1437 unless (system($cmd) == 0) {
1438 warn("Join failed\n$cmd");
1439 return undef;
1442 $self->set_pdc_env_vars($ret, $dcvars);
1443 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1445 return $ret;
1448 sub provision_ad_dc_ntvfs($$$)
1450 my ($self, $prefix, $extra_provision_options) = @_;
1452 # We keep the old 'winbind' name here in server services to
1453 # ensure upgrades which used that name still work with the now
1454 # alias.
1456 print "PROVISIONING AD DC (NTVFS)...\n";
1457 my $extra_conf_options = "netbios aliases = localDC1-a
1458 server services = +winbind -winbindd
1459 ldap server require strong auth = allow_sasl_over_tls
1460 allow nt4 crypto = yes
1461 raw NTLMv2 auth = yes
1462 lsa over netlogon = yes
1463 rpc server port = 1027
1464 auth event notification = true
1465 dsdb event notification = true
1466 dsdb password event notification = true
1467 dsdb group change notification = true
1468 server schannel = auto
1470 push (@{$extra_provision_options}, "--use-ntvfs");
1471 my $ret = $self->provision($prefix,
1472 "domain controller",
1473 "localdc",
1474 "SAMBADOMAIN",
1475 "samba.example.com",
1476 "2008",
1477 "locDCpass1",
1478 undef,
1479 undef,
1480 $extra_conf_options,
1482 $extra_provision_options);
1483 unless ($ret) {
1484 return undef;
1487 unless($self->add_wins_config("$prefix/private")) {
1488 warn("Unable to add wins configuration");
1489 return undef;
1491 $ret->{NETBIOSALIAS} = "localdc1-a";
1492 $ret->{DC_REALM} = $ret->{REALM};
1494 return $ret;
1497 sub provision_fl2000dc($$)
1499 my ($self, $prefix) = @_;
1501 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1502 my $extra_conf_options = "
1503 spnego:simulate_w2k=yes
1504 ntlmssp_server:force_old_spnego=yes
1506 my $extra_provision_options = ["--base-schema=2008_R2"];
1507 # This environment uses plain text secrets
1508 # i.e. secret attributes are not encrypted on disk.
1509 # This allows testing of the --plaintext-secrets option for
1510 # provision
1511 push (@{$extra_provision_options}, "--plaintext-secrets");
1512 my $ret = $self->provision($prefix,
1513 "domain controller",
1514 "dc5",
1515 "SAMBA2000",
1516 "samba2000.example.com",
1517 "2000",
1518 "locDCpass5",
1519 undef,
1520 undef,
1521 $extra_conf_options,
1523 $extra_provision_options);
1524 unless ($ret) {
1525 return undef;
1528 unless($self->add_wins_config("$prefix/private")) {
1529 warn("Unable to add wins configuration");
1530 return undef;
1532 $ret->{DC_REALM} = $ret->{REALM};
1534 return $ret;
1537 sub provision_fl2003dc($$$)
1539 my ($self, $prefix, $dcvars) = @_;
1540 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1541 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1543 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1544 my $extra_conf_options = "allow dns updates = nonsecure and secure
1545 dcesrv:header signing = no
1546 dcesrv:max auth states = 0
1547 dns forwarder = $ip_addr1 $ip_addr2";
1548 my $extra_provision_options = ["--base-schema=2008_R2"];
1549 my $ret = $self->provision($prefix,
1550 "domain controller",
1551 "dc6",
1552 "SAMBA2003",
1553 "samba2003.example.com",
1554 "2003",
1555 "locDCpass6",
1556 undef,
1557 undef,
1558 $extra_conf_options,
1560 $extra_provision_options);
1561 unless (defined $ret) {
1562 return undef;
1565 $ret->{DNS_FORWARDER1} = $ip_addr1;
1566 $ret->{DNS_FORWARDER2} = $ip_addr2;
1568 my @samba_tool_options;
1569 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1570 push (@samba_tool_options, "domain");
1571 push (@samba_tool_options, "passwordsettings");
1572 push (@samba_tool_options, "set");
1573 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1574 push (@samba_tool_options, "--min-pwd-age=0");
1575 push (@samba_tool_options, "--history-length=1");
1577 my $samba_tool_cmd = join(" ", @samba_tool_options);
1579 unless (system($samba_tool_cmd) == 0) {
1580 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1581 return undef;
1584 unless($self->add_wins_config("$prefix/private")) {
1585 warn("Unable to add wins configuration");
1586 return undef;
1589 return $ret;
1592 sub provision_fl2008r2dc($$$)
1594 my ($self, $prefix, $dcvars) = @_;
1596 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1597 my $extra_conf_options = "ldap server require strong auth = no";
1598 my $extra_provision_options = ["--base-schema=2008_R2"];
1599 my $ret = $self->provision($prefix,
1600 "domain controller",
1601 "dc7",
1602 "SAMBA2008R2",
1603 "samba2008R2.example.com",
1604 "2008_R2",
1605 "locDCpass7",
1606 undef,
1607 undef,
1608 $extra_conf_options,
1610 $extra_provision_options);
1611 unless (defined $ret) {
1612 return undef;
1615 unless ($self->add_wins_config("$prefix/private")) {
1616 warn("Unable to add wins configuration");
1617 return undef;
1619 $ret->{DC_REALM} = $ret->{REALM};
1621 return $ret;
1625 sub provision_rodc($$$)
1627 my ($self, $prefix, $dcvars) = @_;
1628 print "PROVISIONING RODC...\n";
1630 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1631 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1632 "rodc",
1633 $dcvars->{DOMAIN},
1634 $dcvars->{REALM},
1635 $dcvars->{DOMSID},
1636 "2008",
1637 $dcvars->{PASSWORD},
1638 $dcvars->{SERVER_IP},
1639 $dcvars->{SERVER_IPV6});
1640 unless ($ctx) {
1641 return undef;
1644 $ctx->{share} = "$ctx->{prefix_abs}/share";
1645 push(@{$ctx->{directories}}, "$ctx->{share}");
1647 $ctx->{smb_conf_extra_options} = "
1648 max xmit = 32K
1649 server max protocol = SMB2
1650 password server = $dcvars->{DC_SERVER}
1652 [sysvol]
1653 path = $ctx->{statedir}/sysvol
1654 read only = yes
1656 [netlogon]
1657 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1658 read only = yes
1660 [tmp]
1661 path = $ctx->{share}
1662 read only = no
1663 posix:sharedelay = 10000
1664 posix:oplocktimeout = 3
1665 posix:writetimeupdatedelay = 50000
1669 my $ret = $self->provision_raw_step1($ctx);
1670 unless ($ret) {
1671 return undef;
1674 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1675 my $cmd = $self->get_cmd_env_vars($ret);
1676 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1677 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1678 $cmd .= " --server=$dcvars->{DC_SERVER}";
1680 unless (system($cmd) == 0) {
1681 warn("RODC join failed\n$cmd");
1682 return undef;
1685 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1686 # user password verified on the RODC
1687 my $testallowed_account = "testallowed account";
1688 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1689 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1690 $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1691 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1692 $cmd .= " --server=$dcvars->{DC_SERVER}";
1694 unless (system($cmd) == 0) {
1695 warn("RODC join failed\n$cmd");
1696 return undef;
1699 # we overwrite the kdc after the RODC join
1700 # so that use the RODC as kdc and test
1701 # the proxy code
1702 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1703 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1704 Samba::mk_krb5_conf($ctx);
1705 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1707 $self->set_pdc_env_vars($ret, $dcvars);
1709 return $ret;
1712 sub read_config_h($)
1714 my ($name) = @_;
1715 my %ret = {};
1716 open(LF, "<$name") or die("unable to read $name: $!");
1717 while (<LF>) {
1718 chomp;
1719 next if not (/^#define /);
1720 if (/^#define (.*?)[ \t]+(.*?)$/) {
1721 $ret{$1} = $2;
1722 next;
1724 if (/^#define (.*?)[ \t]+$/) {
1725 $ret{$1} = 1;;
1726 next;
1729 close(LF);
1730 return \%ret;
1733 sub provision_ad_dc($$$$$$)
1735 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1736 $extra_provision_options) = @_;
1738 my $prefix_abs = abs_path($prefix);
1740 my $bindir_abs = abs_path($self->{bindir});
1741 my $lockdir="$prefix_abs/lockdir";
1742 my $conffile="$prefix_abs/etc/smb.conf";
1744 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1745 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1747 my $config_h = {};
1749 if (defined($ENV{CONFIG_H})) {
1750 $config_h = read_config_h($ENV{CONFIG_H});
1753 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1754 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1756 my $extra_smbconf_options = "
1757 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1759 dbwrap_tdb_mutexes:* = yes
1760 ${require_mutexes}
1762 ${password_hash_gpg_key_ids}
1764 kernel oplocks = no
1765 kernel change notify = no
1766 smb2 leases = no
1768 logging = file
1769 printing = bsd
1770 printcap name = /dev/null
1772 max protocol = SMB3
1773 read only = no
1775 smbd:sharedelay = 100000
1776 smbd:writetimeupdatedelay = 500000
1777 create mask = 755
1778 dos filemode = yes
1779 check parent directory delete on close = yes
1781 dcerpc endpoint servers = -winreg -srvsvc
1783 printcap name = /dev/null
1785 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1786 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1788 printing = vlp
1789 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1790 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1791 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1792 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1793 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1794 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1795 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1796 lpq cache time = 0
1797 print notify backchannel = yes
1799 server schannel = auto
1800 auth event notification = true
1801 dsdb event notification = true
1802 dsdb password event notification = true
1803 dsdb group change notification = true
1804 $smbconf_args
1807 my $extra_smbconf_shares = "
1809 [tmpenc]
1810 copy = tmp
1811 smb encrypt = required
1813 [tmpcase]
1814 copy = tmp
1815 case sensitive = yes
1817 [tmpguest]
1818 copy = tmp
1819 guest ok = yes
1821 [hideunread]
1822 copy = tmp
1823 hide unreadable = yes
1825 [durable]
1826 copy = tmp
1827 kernel share modes = no
1828 kernel oplocks = no
1829 posix locking = no
1831 [print\$]
1832 copy = tmp
1834 [print1]
1835 copy = tmp
1836 printable = yes
1838 [print2]
1839 copy = print1
1840 [print3]
1841 copy = print1
1842 [print4]
1843 copy = print1
1844 guest ok = yes
1845 [lp]
1846 copy = print1
1849 push (@{$extra_provision_options}, "--backend-store=mdb");
1850 print "PROVISIONING AD DC...\n";
1851 my $ret = $self->provision($prefix,
1852 "domain controller",
1853 $hostname,
1854 $domain,
1855 $realm,
1856 "2008",
1857 "locDCpass1",
1858 undef,
1859 undef,
1860 $extra_smbconf_options,
1861 $extra_smbconf_shares,
1862 $extra_provision_options);
1863 unless (defined $ret) {
1864 return undef;
1867 unless($self->add_wins_config("$prefix/private")) {
1868 warn("Unable to add wins configuration");
1869 return undef;
1872 return $ret;
1875 sub provision_chgdcpass($$)
1877 my ($self, $prefix) = @_;
1879 print "PROVISIONING CHGDCPASS...\n";
1880 # This environment disallows the use of this password
1881 # (and also removes the default AD complexity checks)
1882 my $unacceptable_password = "Paßßword-widk3Dsle32jxdBdskldsk55klASKQ";
1883 my $extra_smb_conf = "
1884 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
1885 allow dcerpc auth level connect:lsarpc = yes
1886 dcesrv:max auth states = 8
1888 my $extra_provision_options = ["--dns-backend=BIND9_DLZ"];
1889 my $ret = $self->provision($prefix,
1890 "domain controller",
1891 "chgdcpass",
1892 "CHDCDOMAIN",
1893 "chgdcpassword.samba.example.com",
1894 "2008",
1895 "chgDCpass1",
1896 undef,
1897 undef,
1898 $extra_smb_conf,
1900 $extra_provision_options);
1901 unless (defined $ret) {
1902 return undef;
1905 unless($self->add_wins_config("$prefix/private")) {
1906 warn("Unable to add wins configuration");
1907 return undef;
1910 # Remove secrets.tdb from this environment to test that we
1911 # still start up on systems without the new matching
1912 # secrets.tdb records.
1913 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1914 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1915 return undef;
1918 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1920 return $ret;
1923 sub teardown_env_terminate($$)
1925 my ($self, $envvars) = @_;
1926 my $pid;
1928 # This should cause samba to terminate gracefully
1929 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
1930 my $cmd = "";
1931 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
1932 my $ret = system($cmd);
1933 if ($ret != 0) {
1934 warn "'$cmd' failed with '$ret'\n";
1937 # This should cause samba to terminate gracefully
1938 close($envvars->{STDIN_PIPE});
1940 $pid = $envvars->{SAMBA_PID};
1941 my $count = 0;
1942 my $childpid;
1944 # This should give it time to write out the gcov data
1945 until ($count > 15) {
1946 if (Samba::cleanup_child($pid, "samba") != 0) {
1947 return;
1949 sleep(1);
1950 $count++;
1953 # After 15 Seconds, work out why this thing is still alive
1954 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
1955 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
1957 until ($count > 30) {
1958 if (Samba::cleanup_child($pid, "samba") != 0) {
1959 return;
1961 sleep(1);
1962 $count++;
1965 if (kill(0, $pid)) {
1966 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
1967 kill "TERM", $pid;
1970 until ($count > 40) {
1971 if (Samba::cleanup_child($pid, "samba") != 0) {
1972 return;
1974 sleep(1);
1975 $count++;
1977 # If it is still around, kill it
1978 if (kill(0, $pid)) {
1979 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
1980 kill 9, $pid;
1982 return;
1985 sub teardown_env($$)
1987 my ($self, $envvars) = @_;
1988 teardown_env_terminate($self, $envvars);
1990 print $self->getlog_env($envvars);
1992 return;
1995 sub getlog_env($$)
1997 my ($self, $envvars) = @_;
1998 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
1999 my $out = $title;
2001 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2003 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2004 while (<LOG>) {
2005 $out .= $_;
2007 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2008 close(LOG);
2010 return "" if $out eq $title;
2012 return $out;
2015 sub check_env($$)
2017 my ($self, $envvars) = @_;
2018 my $samba_pid = $envvars->{SAMBA_PID};
2020 if (not defined($samba_pid)) {
2021 return 0;
2022 } elsif ($samba_pid > 0) {
2023 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2025 if ($childpid == 0) {
2026 return 1;
2028 return 0;
2029 } else {
2030 return 1;
2034 # Declare the environments Samba4 makes available.
2035 # To be set up, they will be called as
2036 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2037 # The interdependencies between the testenvs are declared below. Some testenvs
2038 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2039 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2040 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2041 %Samba4::ENV_DEPS = (
2042 # name => [dep_1, dep_2, ...],
2043 dns_hub => [],
2044 ad_dc_ntvfs => ["dns_hub"],
2045 ad_dc => ["dns_hub"],
2046 ad_dc_no_nss => ["dns_hub"],
2047 ad_dc_no_ntlm => ["dns_hub"],
2049 fl2008r2dc => ["ad_dc"],
2050 fl2003dc => ["ad_dc"],
2051 fl2000dc => ["dns_hub"],
2053 vampire_2000_dc => ["fl2000dc"],
2054 vampire_dc => ["ad_dc_ntvfs"],
2055 promoted_dc => ["ad_dc_ntvfs"],
2057 rodc => ["ad_dc_ntvfs"],
2058 rpc_proxy => ["ad_dc_ntvfs"],
2059 chgdcpass => ["dns_hub"],
2061 s4member_dflt_domain => ["ad_dc_ntvfs"],
2062 s4member => ["ad_dc_ntvfs"],
2064 # envs that test the server process model
2065 proclimitdc => ["dns_hub"],
2066 preforkrestartdc => ["dns_hub"],
2068 # backup/restore testenvs
2069 backupfromdc => ["dns_hub"],
2070 customdc => ["dns_hub"],
2071 restoredc => ["backupfromdc"],
2072 renamedc => ["backupfromdc"],
2073 offlinebackupdc => ["backupfromdc"],
2074 labdc => ["backupfromdc"],
2076 # aliases in order to split autbuild tasks
2077 fl2008dc => ["ad_dc"],
2078 ad_dc_default => ["ad_dc"],
2079 ad_dc_slowtests => ["ad_dc"],
2080 ad_dc_backup => ["ad_dc"],
2082 schema_dc => ["dns_hub"],
2083 schema_pair_dc => ["schema_dc"],
2085 none => [],
2088 %Samba4::ENV_DEPS_POST = (
2089 schema_dc => ["schema_pair_dc"],
2092 sub return_alias_env
2094 my ($self, $path, $env) = @_;
2096 # just an alias
2097 return $env;
2100 sub setup_fl2008dc
2102 my ($self, $path) = @_;
2104 my $extra_args = ["--base-schema=2008_R2"];
2105 my $env = $self->provision_ad_dc_ntvfs($path, $extra_args);
2106 if (defined $env) {
2107 if (not defined($self->check_or_start($env, "standard"))) {
2108 warn("Failed to start fl2008dc");
2109 return undef;
2112 return $env;
2115 sub setup_ad_dc_default
2117 my ($self, $path, $dep_env) = @_;
2118 return $self->return_alias_env($path, $dep_env)
2121 sub setup_ad_dc_slowtests
2123 my ($self, $path, $dep_env) = @_;
2124 return $self->return_alias_env($path, $dep_env)
2127 sub setup_ad_dc_backup
2129 my ($self, $path, $dep_env) = @_;
2130 return $self->return_alias_env($path, $dep_env)
2133 sub setup_s4member
2135 my ($self, $path, $dc_vars) = @_;
2137 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2139 if (defined $env) {
2140 if (not defined($self->check_or_start($env, "standard"))) {
2141 return undef;
2145 return $env;
2148 sub setup_s4member_dflt_domain
2150 my ($self, $path, $dc_vars) = @_;
2152 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2153 "winbind use default domain = yes");
2155 if (defined $env) {
2156 if (not defined($self->check_or_start($env, "standard"))) {
2157 return undef;
2161 return $env;
2164 sub setup_rpc_proxy
2166 my ($self, $path, $dc_vars) = @_;
2168 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2170 if (defined $env) {
2171 if (not defined($self->check_or_start($env, "standard"))) {
2172 return undef;
2175 return $env;
2178 sub setup_ad_dc_ntvfs
2180 my ($self, $path) = @_;
2182 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2183 if (defined $env) {
2184 if (not defined($self->check_or_start($env, "standard"))) {
2185 warn("Failed to start ad_dc_ntvfs");
2186 return undef;
2189 return $env;
2192 sub setup_chgdcpass
2194 my ($self, $path) = @_;
2196 my $env = $self->provision_chgdcpass($path);
2197 if (defined $env) {
2198 if (not defined($self->check_or_start($env, "standard"))) {
2199 return undef;
2202 return $env;
2205 sub setup_fl2000dc
2207 my ($self, $path) = @_;
2209 my $env = $self->provision_fl2000dc($path);
2210 if (defined $env) {
2211 if (not defined($self->check_or_start($env, "standard"))) {
2212 return undef;
2216 return $env;
2219 sub setup_fl2003dc
2221 my ($self, $path, $dc_vars) = @_;
2223 my $env = $self->provision_fl2003dc($path);
2225 if (defined $env) {
2226 if (not defined($self->check_or_start($env, "standard"))) {
2227 return undef;
2230 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2232 return $env;
2235 sub setup_fl2008r2dc
2237 my ($self, $path, $dc_vars) = @_;
2239 my $env = $self->provision_fl2008r2dc($path);
2241 if (defined $env) {
2242 if (not defined($self->check_or_start($env, "standard"))) {
2243 return undef;
2246 my $upn_array = ["$env->{REALM}.upn"];
2247 my $spn_array = ["$env->{REALM}.spn"];
2249 $self->setup_namespaces($env, $upn_array, $spn_array);
2251 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2254 return $env;
2257 sub setup_vampire_dc
2259 return setup_generic_vampire_dc(@_, "2008");
2262 sub setup_vampire_2000_dc
2264 return setup_generic_vampire_dc(@_, "2000");
2267 sub setup_generic_vampire_dc
2269 my ($self, $path, $dc_vars, $fl) = @_;
2271 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2273 if (defined $env) {
2274 if (not defined($self->check_or_start($env, "single"))) {
2275 return undef;
2278 # force replicated DC to update repsTo/repsFrom
2279 # for vampired partitions
2280 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2282 # as 'vampired' dc may add data in its local replica
2283 # we need to synchronize data between DCs
2284 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2285 my $cmd = $self->get_cmd_env_vars($env);
2286 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2287 $cmd .= " $dc_vars->{CONFIGURATION}";
2288 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2289 # replicate Configuration NC
2290 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2291 unless(system($cmd_repl) == 0) {
2292 warn("Failed to replicate\n$cmd_repl");
2293 return undef;
2295 # replicate Default NC
2296 $cmd_repl = "$cmd \"$base_dn\"";
2297 unless(system($cmd_repl) == 0) {
2298 warn("Failed to replicate\n$cmd_repl");
2299 return undef;
2302 # Pull in a full set of changes from the main DC
2303 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2304 $cmd = $self->get_cmd_env_vars($env);
2305 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2306 $cmd .= " $dc_vars->{CONFIGURATION}";
2307 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2308 # replicate Configuration NC
2309 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2310 unless(system($cmd_repl) == 0) {
2311 warn("Failed to replicate\n$cmd_repl");
2312 return undef;
2314 # replicate Default NC
2315 $cmd_repl = "$cmd \"$base_dn\"";
2316 unless(system($cmd_repl) == 0) {
2317 warn("Failed to replicate\n$cmd_repl");
2318 return undef;
2322 return $env;
2325 sub setup_promoted_dc
2327 my ($self, $path, $dc_vars) = @_;
2329 my $env = $self->provision_promoted_dc($path, $dc_vars);
2331 if (defined $env) {
2332 if (not defined($self->check_or_start($env, "single"))) {
2333 return undef;
2336 # force source and replicated DC to update repsTo/repsFrom
2337 # for vampired partitions
2338 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2339 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2340 # as 'vampired' dc may add data in its local replica
2341 # we need to synchronize data between DCs
2342 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2343 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2344 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2345 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2346 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2347 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2348 $cmd .= " $dc_vars->{CONFIGURATION}";
2349 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2350 # replicate Configuration NC
2351 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2352 unless(system($cmd_repl) == 0) {
2353 warn("Failed to replicate\n$cmd_repl");
2354 return undef;
2356 # replicate Default NC
2357 $cmd_repl = "$cmd \"$base_dn\"";
2358 unless(system($cmd_repl) == 0) {
2359 warn("Failed to replicate\n$cmd_repl");
2360 return undef;
2364 return $env;
2367 sub setup_rodc
2369 my ($self, $path, $dc_vars) = @_;
2371 my $env = $self->provision_rodc($path, $dc_vars);
2373 unless ($env) {
2374 return undef;
2377 if (not defined($self->check_or_start($env, "standard"))) {
2378 return undef;
2381 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2382 my $cmd = "";
2384 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2385 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2386 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2387 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2388 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2389 $cmd .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2390 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2391 $cmd .= " $dc_vars->{CONFIGURATION}";
2392 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2393 # replicate Configuration NC
2394 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2395 unless(system($cmd_repl) == 0) {
2396 warn("Failed to replicate\n$cmd_repl");
2397 return undef;
2399 # replicate Default NC
2400 $cmd_repl = "$cmd \"$base_dn\"";
2401 unless(system($cmd_repl) == 0) {
2402 warn("Failed to replicate\n$cmd_repl");
2403 return undef;
2406 return $env;
2409 sub setup_ad_dc
2411 my ($self, $path) = @_;
2413 # If we didn't build with ADS, pretend this env was never available
2414 if (not $self->{target3}->have_ads()) {
2415 return "UNKNOWN";
2418 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2419 "addom.samba.example.com", "", undef);
2420 unless ($env) {
2421 return undef;
2424 if (not defined($self->check_or_start($env, "prefork"))) {
2425 return undef;
2428 my $upn_array = ["$env->{REALM}.upn"];
2429 my $spn_array = ["$env->{REALM}.spn"];
2431 $self->setup_namespaces($env, $upn_array, $spn_array);
2433 return $env;
2436 sub setup_ad_dc_no_nss
2438 my ($self, $path) = @_;
2440 # If we didn't build with ADS, pretend this env was never available
2441 if (not $self->{target3}->have_ads()) {
2442 return "UNKNOWN";
2445 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2446 "adnonssdom.samba.example.com", "", undef);
2447 unless ($env) {
2448 return undef;
2451 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2452 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2454 if (not defined($self->check_or_start($env, "single"))) {
2455 return undef;
2458 my $upn_array = ["$env->{REALM}.upn"];
2459 my $spn_array = ["$env->{REALM}.spn"];
2461 $self->setup_namespaces($env, $upn_array, $spn_array);
2463 return $env;
2466 sub setup_ad_dc_no_ntlm
2468 my ($self, $path) = @_;
2470 # If we didn't build with ADS, pretend this env was never available
2471 if (not $self->{target3}->have_ads()) {
2472 return "UNKNOWN";
2475 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2476 "adnontlmdom.samba.example.com",
2477 "ntlm auth = disabled", undef);
2478 unless ($env) {
2479 return undef;
2482 if (not defined($self->check_or_start($env, "prefork"))) {
2483 return undef;
2486 my $upn_array = ["$env->{REALM}.upn"];
2487 my $spn_array = ["$env->{REALM}.spn"];
2489 $self->setup_namespaces($env, $upn_array, $spn_array);
2491 return $env;
2495 # AD DC test environment used solely to test pre-fork process restarts.
2496 # As processes get killed off and restarted it should not be used for other
2497 sub setup_preforkrestartdc
2499 my ($self, $path) = @_;
2501 # If we didn't build with ADS, pretend this env was never available
2502 if (not $self->{target3}->have_ads()) {
2503 return "UNKNOWN";
2506 # note DC name must be <= 15 chars so we use 'prockill' instead of
2507 # 'preforkrestart'
2508 my $env = $self->provision_ad_dc(
2509 $path,
2510 "prockilldc",
2511 "PROCKILLDOMAIN",
2512 "prockilldom.samba.example.com",
2513 "prefork backoff increment = 5\nprefork maximum backoff=10");
2514 unless ($env) {
2515 return undef;
2518 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2519 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2521 if (not defined($self->check_or_start($env, "prefork"))) {
2522 return undef;
2525 my $upn_array = ["$env->{REALM}.upn"];
2526 my $spn_array = ["$env->{REALM}.spn"];
2528 $self->setup_namespaces($env, $upn_array, $spn_array);
2530 return $env;
2534 # ad_dc test environment used solely to test standard process model connection
2535 # process limits. As the limit is set artificially low it should not be used
2536 # for other tests.
2537 sub setup_proclimitdc
2539 my ($self, $path) = @_;
2541 # If we didn't build with ADS, pretend this env was never available
2542 if (not $self->{target3}->have_ads()) {
2543 return "UNKNOWN";
2546 my $env = $self->provision_ad_dc(
2547 $path,
2548 "proclimitdc",
2549 "PROCLIMITDOM",
2550 "proclimit.samba.example.com",
2551 "max smbd processes = 20");
2552 unless ($env) {
2553 return undef;
2556 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2557 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2559 if (not defined($self->check_or_start($env, "standard"))) {
2560 return undef;
2563 my $upn_array = ["$env->{REALM}.upn"];
2564 my $spn_array = ["$env->{REALM}.spn"];
2566 $self->setup_namespaces($env, $upn_array, $spn_array);
2568 return $env;
2571 # Used to test a live upgrade of the schema on a 2 DC network.
2572 sub setup_schema_dc
2574 my ($self, $path) = @_;
2576 # provision the PDC using an older base schema
2577 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2579 my $env = $self->provision_ad_dc($path, "liveupgrade1dc", "SCHEMADOMAIN",
2580 "schema.samba.example.com",
2581 "drs: max link sync = 2",
2582 $provision_args);
2583 unless ($env) {
2584 return undef;
2587 if (not defined($self->check_or_start($env, "prefork"))) {
2588 return undef;
2591 my $upn_array = ["$env->{REALM}.upn"];
2592 my $spn_array = ["$env->{REALM}.spn"];
2594 $self->setup_namespaces($env, $upn_array, $spn_array);
2596 return $env;
2599 # the second DC in the live schema upgrade pair
2600 sub setup_schema_pair_dc
2602 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2603 my ($self, $prefix, $dcvars) = @_;
2604 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2606 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2607 $dcvars->{DOMAIN},
2608 $dcvars->{REALM},
2609 $dcvars->{PASSWORD},
2610 "");
2612 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2613 my $cmd_vars = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2614 $cmd_vars .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2615 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2616 $cmd_vars .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2617 } else {
2618 $cmd_vars .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2620 $cmd_vars .= "KRB5_CONFIG=\"$env->{KRB5_CONFIG}\" ";
2621 $cmd_vars .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2622 $cmd_vars .= "RESOLV_CONF=\"$env->{RESOLV_CONF}\" ";
2624 my $join_cmd = $cmd_vars;
2625 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2626 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2627 $join_cmd .= " --backend-store=mdb";
2629 my $upgrade_cmd = $cmd_vars;
2630 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2631 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2633 my $repl_cmd = $cmd_vars;
2634 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2635 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2636 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2638 unless (system($join_cmd) == 0) {
2639 warn("Join failed\n$join_cmd");
2640 return undef;
2643 $env->{DC_SERVER} = $dcvars->{SERVER};
2644 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2645 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2646 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2648 # start samba for the new DC
2649 if (not defined($self->check_or_start($env, "standard"))) {
2650 return undef;
2653 unless (system($upgrade_cmd) == 0) {
2654 warn("Schema upgrade failed\n$upgrade_cmd");
2655 return undef;
2658 unless (system($repl_cmd) == 0) {
2659 warn("Post-update schema replication failed\n$repl_cmd");
2660 return undef;
2663 return $env;
2666 # Sets up a DC that's solely used to do a domain backup from. We then use the
2667 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2668 # process will create a Samba DC that will actually start up.
2669 # We don't use the backup-DC for anything else because its domain will conflict
2670 # with the restore DC.
2671 sub setup_backupfromdc
2673 my ($self, $path) = @_;
2675 # If we didn't build with ADS, pretend this env was never available
2676 if (not $self->{target3}->have_ads()) {
2677 return "UNKNOWN";
2680 my $provision_args = ["--site=Backup-Site"];
2682 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2683 "backupdom.samba.example.com",
2684 "samba kcc command = /bin/true",
2685 $provision_args);
2686 unless ($env) {
2687 return undef;
2690 if (not defined($self->check_or_start($env))) {
2691 return undef;
2694 my $upn_array = ["$env->{REALM}.upn"];
2695 my $spn_array = ["$env->{REALM}.spn"];
2697 $self->setup_namespaces($env, $upn_array, $spn_array);
2699 return $env;
2702 # returns the server/user-auth params needed to run an online backup cmd
2703 sub get_backup_server_args
2705 # dcvars contains the env info for the backup DC testenv
2706 my ($self, $dcvars) = @_;
2707 my $server = $dcvars->{DC_SERVER_IP};
2708 my $server_args = "--server=$server ";
2709 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2710 $server_args .= " $dcvars->{CONFIGURATION}";
2712 return $server_args;
2715 # Creates a backup of a running testenv DC
2716 sub create_backup
2718 # note: dcvars contains the env info for the backup DC testenv
2719 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2721 # get all the env variables we pass in with the samba-tool command
2722 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2723 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2724 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2725 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2726 } else {
2727 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2729 # Note: use the backupfrom-DC's krb5.conf to do the backup
2730 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2731 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2733 # use samba-tool to create a backup from the 'backupfromdc' DC
2734 my $cmd = "";
2735 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2737 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2738 $cmd .= " --targetdir=$backupdir";
2740 print "Executing: $cmd\n";
2741 unless(system($cmd) == 0) {
2742 warn("Failed to create backup using: \n$cmd");
2743 return undef;
2746 # get the name of the backup file created
2747 opendir(DIR, $backupdir);
2748 my @files = grep(/\.tar/, readdir(DIR));
2749 closedir(DIR);
2751 if(scalar @files != 1) {
2752 warn("Backup file not found in directory $backupdir\n");
2753 return undef;
2755 my $backup_file = "$backupdir/$files[0]";
2756 print "Using backup file $backup_file...\n";
2758 return $backup_file;
2761 # Restores a backup-file to populate a testenv for a new DC
2762 sub restore_backup_file
2764 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2766 # pass the restore command the testenv's smb.conf that we've already
2767 # generated. But move it to a temp-dir first, so that the restore doesn't
2768 # overwrite it
2769 my $tmpdir = File::Temp->newdir();
2770 my $tmpconf = "$tmpdir/smb.conf";
2771 my $cmd = "cp $smbconf $tmpconf";
2772 unless(system($cmd) == 0) {
2773 warn("Failed to backup smb.conf using: \n$cmd");
2774 return -1;
2777 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2778 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2779 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2781 print "Executing: $cmd\n";
2782 unless(system($cmd) == 0) {
2783 warn("Failed to restore backup using: \n$cmd");
2784 return -1;
2787 print "Restore complete\n";
2788 return 0
2791 # sets up the initial directory and returns the new testenv's env info
2792 # (without actually doing a 'domain join')
2793 sub prepare_dc_testenv
2795 my ($self, $prefix, $dcname, $domain, $realm,
2796 $password, $conf_options) = @_;
2798 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2799 $dcname,
2800 $domain,
2801 $realm,
2802 undef,
2803 "2008",
2804 $password,
2805 undef,
2806 undef);
2808 # the restore uses a slightly different state-dir location to other testenvs
2809 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2810 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2812 # add support for sysvol/netlogon/tmp shares
2813 $ctx->{share} = "$ctx->{prefix_abs}/share";
2814 push(@{$ctx->{directories}}, "$ctx->{share}");
2815 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
2817 $ctx->{smb_conf_extra_options} = "
2818 $conf_options
2819 max xmit = 32K
2820 server max protocol = SMB2
2821 samba kcc command = /bin/true
2822 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
2824 [sysvol]
2825 path = $ctx->{statedir}/sysvol
2826 read only = no
2828 [netlogon]
2829 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2830 read only = no
2832 [tmp]
2833 path = $ctx->{share}
2834 read only = no
2835 posix:sharedelay = 10000
2836 posix:oplocktimeout = 3
2837 posix:writetimeupdatedelay = 50000
2839 [test1]
2840 path = $ctx->{share}/test1
2841 read only = no
2842 posix:sharedelay = 100000
2843 posix:oplocktimeout = 3
2844 posix:writetimeupdatedelay = 500000
2847 my $env = $self->provision_raw_step1($ctx);
2849 return ($env, $ctx);
2853 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2854 # commands. This proves that we can backup an online DC ('backupfromdc') and
2855 # use the backup file to create a valid, working samba DC.
2856 sub setup_restoredc
2858 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2859 my ($self, $prefix, $dcvars) = @_;
2860 print "Preparing RESTORE DC...\n";
2862 # we arbitrarily designate the restored DC as having SMBv1 disabled
2863 my $extra_conf = "
2864 server min protocol = SMB2
2865 client min protocol = SMB2
2866 prefork children = 1";
2868 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2869 $dcvars->{DOMAIN},
2870 $dcvars->{REALM},
2871 $dcvars->{PASSWORD},
2872 $extra_conf);
2874 # create a backup of the 'backupfromdc'
2875 my $backupdir = File::Temp->newdir();
2876 my $server_args = $self->get_backup_server_args($dcvars);
2877 my $backup_args = "online $server_args";
2878 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2879 $backup_args);
2880 unless($backup_file) {
2881 return undef;
2884 # restore the backup file to populate the restore-DC testenv
2885 my $restore_dir = abs_path($prefix);
2886 my $ret = $self->restore_backup_file($backup_file,
2887 "--newservername=$env->{SERVER}",
2888 $restore_dir, $env->{SERVERCONFFILE});
2889 unless ($ret == 0) {
2890 return undef;
2893 # start samba for the restored DC
2894 if (not defined($self->check_or_start($env))) {
2895 return undef;
2898 return $env;
2901 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2902 # restore commands. This proves that we can backup and rename an online DC
2903 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2904 sub setup_renamedc
2906 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2907 my ($self, $prefix, $dcvars) = @_;
2908 print "Preparing RENAME DC...\n";
2909 my $extra_conf = "prefork children = 1";
2911 my $realm = "renamedom.samba.example.com";
2912 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
2913 "RENAMEDOMAIN", $realm,
2914 $dcvars->{PASSWORD}, $extra_conf);
2916 # create a backup of the 'backupfromdc' which renames the domain
2917 my $backupdir = File::Temp->newdir();
2918 my $server_args = $self->get_backup_server_args($dcvars);
2919 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2920 $backup_args .= " --backend-store=tdb";
2921 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2922 $backup_args);
2923 unless($backup_file) {
2924 return undef;
2927 # restore the backup file to populate the rename-DC testenv
2928 my $restore_dir = abs_path($prefix);
2929 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2930 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2931 $restore_dir, $env->{SERVERCONFFILE});
2932 unless ($ret == 0) {
2933 return undef;
2936 # start samba for the restored DC
2937 if (not defined($self->check_or_start($env))) {
2938 return undef;
2941 my $upn_array = ["$env->{REALM}.upn"];
2942 my $spn_array = ["$env->{REALM}.spn"];
2944 $self->setup_namespaces($env, $upn_array, $spn_array);
2946 return $env;
2949 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
2950 # restore commands. This proves that we do an offline backup of a local DC
2951 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2952 sub setup_offlinebackupdc
2954 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2955 my ($self, $prefix, $dcvars) = @_;
2956 print "Preparing OFFLINE BACKUP DC...\n";
2957 my $extra_conf = "prefork children = 1";
2959 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
2960 $dcvars->{DOMAIN},
2961 $dcvars->{REALM},
2962 $dcvars->{PASSWORD}, $extra_conf);
2964 # create an offline backup of the 'backupfromdc' target
2965 my $backupdir = File::Temp->newdir();
2966 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
2967 my $backup_file = $self->create_backup($env, $dcvars,
2968 $backupdir, $cmd);
2970 unless($backup_file) {
2971 return undef;
2974 # restore the backup file to populate the rename-DC testenv
2975 my $restore_dir = abs_path($prefix);
2976 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2977 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2978 $restore_dir, $env->{SERVERCONFFILE});
2979 unless ($ret == 0) {
2980 return undef;
2983 # re-create the testenv's krb5.conf (the restore may have overwritten it)
2984 Samba::mk_krb5_conf($ctx);
2986 # start samba for the restored DC
2987 if (not defined($self->check_or_start($env))) {
2988 return undef;
2991 return $env;
2994 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
2995 # restore commands, using the --no-secrets option. This proves that we can
2996 # create a realistic lab environment from an online DC ('backupfromdc').
2997 sub setup_labdc
2999 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3000 my ($self, $prefix, $dcvars) = @_;
3001 print "Preparing LAB-DOMAIN DC...\n";
3002 my $extra_conf = "prefork children = 1";
3004 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3005 "LABDOMAIN",
3006 "labdom.samba.example.com",
3007 $dcvars->{PASSWORD}, $extra_conf);
3009 # create a backup of the 'backupfromdc' which renames the domain and uses
3010 # the --no-secrets option to scrub any sensitive info
3011 my $backupdir = File::Temp->newdir();
3012 my $server_args = $self->get_backup_server_args($dcvars);
3013 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3014 $backup_args .= " --no-secrets --backend-store=mdb";
3015 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3016 $backup_args);
3017 unless($backup_file) {
3018 return undef;
3021 # restore the backup file to populate the lab-DC testenv
3022 my $restore_dir = abs_path($prefix);
3023 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3024 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3025 $restore_dir, $env->{SERVERCONFFILE});
3026 unless ($ret == 0) {
3027 return undef;
3030 # because we don't include any secrets in the backup, we need to reset the
3031 # admin user's password back to what the testenv expects
3032 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3033 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3034 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3035 $cmd .= " $env->{CONFIGURATION}";
3037 unless(system($cmd) == 0) {
3038 warn("Failed to reset admin's password: \n$cmd");
3039 return undef;
3042 # start samba for the restored DC
3043 if (not defined($self->check_or_start($env))) {
3044 return undef;
3047 my $upn_array = ["$env->{REALM}.upn"];
3048 my $spn_array = ["$env->{REALM}.spn"];
3050 $self->setup_namespaces($env, $upn_array, $spn_array);
3052 return $env;
3055 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3056 sub get_backup_domain_realm
3058 my ($self, $backup_file) = @_;
3060 print "Determining REALM/DOMAIN values in backup...\n";
3062 # The backup will have the correct domain/realm values in the smb.conf.
3063 # So we can work out the env variables the testenv should use based on
3064 # that. Let's start by extracting the smb.conf
3065 my $tar = Archive::Tar->new($backup_file);
3066 my $tmpdir = File::Temp->newdir();
3067 my $smbconf = "$tmpdir/smb.conf";
3069 # note that the filepaths within the tar-file differ slightly for online
3070 # and offline backups
3071 if ($tar->contains_file("etc/smb.conf")) {
3072 $tar->extract_file("etc/smb.conf", $smbconf);
3073 } elsif ($tar->contains_file("./etc/smb.conf")) {
3074 $tar->extract_file("./etc/smb.conf", $smbconf);
3075 } else {
3076 warn("Could not find smb.conf in $backup_file");
3077 return undef, undef;
3080 # make sure we don't try to create locks/sockets in the default install
3081 # location (i.e. /usr/local/samba/)
3082 my $options = "--option=\"private dir = $tmpdir\"";
3083 $options .= " --option=\"lock dir = $tmpdir\"";
3085 # now use testparm to read the values we're interested in
3086 my $testparm = Samba::bindir_path($self, "testparm");
3087 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3088 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3089 chomp $realm;
3090 chomp $domain;
3091 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3093 return ($domain, $realm);
3096 # This spins up a custom testenv that can be based on any backup-file you want.
3097 # This is just intended for manual testing (rather than automated test-cases)
3098 sub setup_customdc
3100 my ($self, $prefix) = @_;
3101 print "Preparing CUSTOM RESTORE DC...\n";
3102 my $dc_name = "customdc";
3103 my $password = "locDCpass1";
3104 my $backup_file = $ENV{'BACKUP_FILE'};
3106 # user must specify a backup file to restore via an ENV variable, i.e.
3107 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3108 if (not defined($backup_file)) {
3109 warn("Please specify BACKUP_FILE");
3110 return undef;
3113 # work out the correct domain/realm env values from the backup-file
3114 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3115 if ($domain eq '' or $realm eq '') {
3116 warn("Could not determine domain or realm");
3117 return undef;
3120 # create a placeholder directory and smb.conf, as well as the env vars.
3121 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3122 $domain, $realm, $password, "");
3124 # restore the specified backup file to populate the testenv
3125 my $restore_dir = abs_path($prefix);
3126 my $ret = $self->restore_backup_file($backup_file,
3127 "--newservername=$env->{SERVER}",
3128 $restore_dir, $env->{SERVERCONFFILE});
3129 unless ($ret == 0) {
3130 return undef;
3133 # Change the admin password to the testenv default, just in case it's
3134 # different, or in case this was a --no-secrets backup
3135 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3136 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3137 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3138 $cmd .= " $env->{CONFIGURATION}";
3140 unless(system($cmd) == 0) {
3141 warn("Failed to reset admin's password: \n$cmd");
3142 return undef;
3145 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3146 # if the backup-file was an offline backup)
3147 Samba::mk_krb5_conf($ctx);
3149 # start samba for the restored DC
3150 if (not defined($self->check_or_start($env))) {
3151 return undef;
3154 # if this was a backup-rename, then we may need to setup namespaces
3155 my $upn_array = ["$env->{REALM}.upn"];
3156 my $spn_array = ["$env->{REALM}.spn"];
3158 $self->setup_namespaces($env, $upn_array, $spn_array);
3160 return $env;
3163 sub setup_none
3165 my ($self, $path) = @_;
3167 my $ret = {
3168 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
3169 SAMBA_PID => -1,