selftest: Remove duplicate setup of $base_dn and $ldbmodify
[Samba.git] / selftest / target / Samba4.pm
blob8bd489ea6a5526fdaa6aa7cc9615f0b6d3130eb2
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 warnings;
13 use Cwd qw(abs_path);
14 use FindBin qw($RealBin);
15 use POSIX;
16 use SocketWrapper;
17 use target::Samba;
18 use target::Samba3;
19 use Archive::Tar;
21 sub new($$$$$) {
22 my ($classname, $SambaCtx, $bindir, $srcdir, $server_maxtime) = @_;
24 my $self = {
25 vars => {},
26 SambaCtx => $SambaCtx,
27 bindir => $bindir,
28 srcdir => $srcdir,
29 server_maxtime => $server_maxtime,
30 target3 => new Samba3($SambaCtx, $bindir, $srcdir, $server_maxtime)
32 bless $self;
33 return $self;
36 sub scriptdir_path($$) {
37 my ($self, $path) = @_;
38 return "$self->{srcdir}/source4/scripting/$path";
41 sub check_or_start($$$)
43 my ($self, $env_vars, $process_model) = @_;
44 my $STDIN_READER;
46 my $env_ok = $self->check_env($env_vars);
47 if ($env_ok) {
48 return $env_vars->{SAMBA_PID};
49 } elsif (defined($env_vars->{SAMBA_PID})) {
50 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
51 return undef;
54 # use a pipe for stdin in the child processes. This allows
55 # those processes to monitor the pipe for EOF to ensure they
56 # exit when the test script exits
57 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
59 # build up the command to run samba
60 my @preargs = ();
61 my @optargs = ();
62 if (defined($ENV{SAMBA_OPTIONS})) {
63 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
65 if(defined($ENV{SAMBA_VALGRIND})) {
66 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
69 if (defined($process_model)) {
70 push @optargs, ("-M", $process_model);
72 my $binary = Samba::bindir_path($self, "samba");
73 my @full_cmd = (@preargs, $binary, "-i",
74 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
75 $env_vars->{CONFIGURATION}, @optargs);
77 # the samba process takes some additional env variables (compared to s3)
78 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
79 if (defined($ENV{MITKRB5})) {
80 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
83 # fork a child process and exec() samba
84 my $daemon_ctx = {
85 NAME => "samba",
86 BINARY_PATH => $binary,
87 FULL_CMD => [ @full_cmd ],
88 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
89 TEE_STDOUT => 1,
90 PCAP_FILE => "env-$ENV{ENVNAME}-samba",
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 = $self->get_cmd_env_vars($testenv_vars);
165 $cmd .= "$ldbsearch ";
166 $cmd .= "$testenv_vars->{CONFIGURATION} ";
167 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
168 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
169 $cmd .= "-s base ";
170 $cmd .= "-b '$search_dn' ";
171 while (system("$cmd >/dev/null") != 0) {
172 $count++;
173 if ($count > $max_wait) {
174 teardown_env($self, $testenv_vars);
175 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}");
176 return -1;
178 print "Waiting for working LDAP...\n";
179 sleep(1);
183 my $wbinfo = Samba::bindir_path($self, "wbinfo");
185 $count = 0;
186 do {
187 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
188 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
189 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
190 $cmd .= "$wbinfo -P";
191 $ret = system($cmd);
193 if ($ret != 0) {
194 sleep(1);
196 $count++;
197 } while ($ret != 0 && $count < 20);
198 if ($count == 20) {
199 teardown_env($self, $testenv_vars);
200 warn("winbind not reachable after 20 retries\n");
201 return -1;
204 # Ensure we registered all our names
205 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
206 my $max_wait = 120;
207 print "Waiting for dns_update_cache to be created.\n";
208 $count = 0;
209 while (not -e "$testenv_vars->{PRIVATEDIR}/dns_update_cache") {
210 $count++;
211 if ($count > $max_wait) {
212 teardown_env($self, $testenv_vars);
213 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
214 return -1;
216 print "Waiting for dns_update_cache to be created...\n";
217 sleep(1);
219 print "Waiting for dns_update_cache to be filled.\n";
220 $count = 0;
221 while ((-s "$testenv_vars->{PRIVATEDIR}/dns_update_cache") == 0) {
222 $count++;
223 if ($count > $max_wait) {
224 teardown_env($self, $testenv_vars);
225 warn("Timed out ($max_wait sec) waiting for dns_update_cache PID $testenv_vars->{SAMBA_PID}");
226 return -1;
228 print "Waiting for dns_update_cache to be filled...\n";
229 sleep(1);
233 print $self->getlog_env($testenv_vars);
235 print "READY ($testenv_vars->{SAMBA_PID})\n";
237 return 0
240 sub write_ldb_file($$$)
242 my ($self, $file, $ldif) = @_;
244 my $ldbadd = Samba::bindir_path($self, "ldbadd");
245 open(LDIF, "|$ldbadd -H $file >/dev/null");
246 print LDIF $ldif;
247 return(close(LDIF));
250 sub add_wins_config($$)
252 my ($self, $privatedir) = @_;
253 my $client_ip = Samba::get_ipv4_addr("client");
255 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
256 dn: name=TORTURE_11,CN=PARTNERS
257 objectClass: wreplPartner
258 name: TORTURE_11
259 address: $client_ip
260 pullInterval: 0
261 pushChangeCount: 0
262 type: 0x3
266 sub setup_dns_hub_internal($$$)
268 my ($self, $hostname, $prefix) = @_;
269 my $STDIN_READER;
271 unless(-d $prefix or mkdir($prefix, 0777)) {
272 warn("Unable to create $prefix");
273 return undef;
275 my $prefix_abs = abs_path($prefix);
277 die ("prefix=''") if $prefix_abs eq "";
278 die ("prefix='/'") if $prefix_abs eq "/";
280 unless (system("rm -rf $prefix_abs/*") == 0) {
281 warn("Unable to clean up");
284 my $env = undef;
285 $env->{NETBIOSNAME} = $hostname;
287 $env->{SERVER_IP} = Samba::get_ipv4_addr($hostname);
288 $env->{SERVER_IPV6} = Samba::get_ipv6_addr($hostname);
289 $env->{SOCKET_WRAPPER_DEFAULT_IFACE} = Samba::get_interface($hostname);
290 $env->{DNS_HUB_LOG} = "$prefix_abs/dns_hub.log";
291 $env->{RESOLV_CONF} = "$prefix_abs/resolv.conf";
292 $env->{TESTENV_DIR} = $prefix_abs;
294 my $ctx = undef;
295 $ctx->{resolv_conf} = $env->{RESOLV_CONF};
296 $ctx->{dns_ipv4} = $env->{SERVER_IP};
297 $ctx->{dns_ipv6} = $env->{SERVER_IPV6};
298 Samba::mk_resolv_conf($ctx);
300 my @preargs = ();
301 my @args = ();
302 if (!defined($ENV{PYTHON})) {
303 push (@preargs, "env");
304 push (@preargs, "python");
305 } else {
306 push (@preargs, $ENV{PYTHON});
308 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
309 push (@args, "$self->{server_maxtime}");
310 push (@args, "$env->{SERVER_IP},$env->{SERVER_IPV6}");
311 push (@args, Samba::realm_to_ip_mappings());
312 my @full_cmd = (@preargs, $binary, @args);
314 my $daemon_ctx = {
315 NAME => "dnshub",
316 BINARY_PATH => $binary,
317 FULL_CMD => [ @full_cmd ],
318 LOG_FILE => $env->{DNS_HUB_LOG},
319 TEE_STDOUT => 1,
320 PCAP_FILE => "env-$ENV{ENVNAME}-dns_hub",
321 ENV_VARS => {},
324 # use a pipe for stdin in the child processes. This allows
325 # those processes to monitor the pipe for EOF to ensure they
326 # exit when the test script exits
327 pipe($STDIN_READER, $env->{STDIN_PIPE});
329 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
331 $env->{SAMBA_PID} = $pid;
332 $env->{KRB5_CONFIG} = "$prefix_abs/no_krb5.conf";
334 # close the parent's read-end of the pipe
335 close($STDIN_READER);
337 return $env;
340 sub setup_dns_hub
342 my ($self, $prefix) = @_;
344 my $hostname = "rootdnsforwarder";
346 unless(-d $prefix or mkdir($prefix, 0777)) {
347 warn("Unable to create $prefix");
348 return undef;
350 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
352 $self->{dns_hub_env} = $env;
354 return $env;
357 sub get_dns_hub_env($)
359 my ($self, $prefix) = @_;
361 if (defined($self->{dns_hub_env})) {
362 return $self->{dns_hub_env};
365 die("get_dns_hub_env() not setup 'dns_hub_env'");
366 return undef;
369 sub return_env_value
371 my ($env, $overwrite, $key) = @_;
373 if (defined($overwrite) and defined($overwrite->{$key})) {
374 return $overwrite->{$key};
377 if (defined($env->{$key})) {
378 return $env->{$key};
381 return undef;
384 # Returns the environmental variables that we pass to samba-tool commands
385 sub get_cmd_env_vars
387 my ($self, $givenenv, $overwrite) = @_;
389 my @keys = (
390 "NSS_WRAPPER_HOSTS",
391 "SOCKET_WRAPPER_DEFAULT_IFACE",
392 "RESOLV_CONF",
393 "RESOLV_WRAPPER_CONF",
394 "RESOLV_WRAPPER_HOSTS",
395 "GNUTLS_FORCE_FIPS_MODE",
396 "OPENSSL_FORCE_FIPS_MODE",
397 "KRB5_CONFIG",
398 "KRB5_CCACHE",
399 "GNUPGHOME",
402 my $localenv = undef;
403 foreach my $key (@keys) {
404 my $v = return_env_value($givenenv, $overwrite, $key);
405 $localenv->{$key} = $v if defined($v);
408 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
409 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
410 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
411 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
412 } else {
413 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
415 if (defined($localenv->{GNUTLS_FORCE_FIPS_MODE})) {
416 $cmd_env .= "GNUTLS_FORCE_FIPS_MODE=$localenv->{GNUTLS_FORCE_FIPS_MODE} ";
418 if (defined($localenv->{OPENSSL_FORCE_FIPS_MODE})) {
419 $cmd_env .= "OPENSSL_FORCE_FIPS_MODE=$localenv->{OPENSSL_FORCE_FIPS_MODE} ";
421 $cmd_env .= "KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
422 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
423 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
424 $cmd_env .= "GNUPGHOME=\"$localenv->{GNUPGHOME}\" ";
426 return $cmd_env;
429 # Sets up a forest trust namespace.
430 # (Note this is different to kernel namespaces, setup by the
431 # USE_NAMESPACES=1 option)
432 sub setup_namespaces
434 my ($self, $localenv, $upn_array, $spn_array) = @_;
436 @{$upn_array} = [] unless defined($upn_array);
437 my $upn_args = "";
438 foreach my $upn (@{$upn_array}) {
439 $upn_args .= " --add-upn-suffix=$upn";
442 @{$spn_array} = [] unless defined($spn_array);
443 my $spn_args = "";
444 foreach my $spn (@{$spn_array}) {
445 $spn_args .= " --add-spn-suffix=$spn";
448 my $samba_tool = Samba::bindir_path($self, "samba-tool");
450 my $cmd_env = $self->get_cmd_env_vars($localenv);
452 my $cmd_config = " $localenv->{CONFIGURATION}";
454 my $namespaces = $cmd_env;
455 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
456 $namespaces .= $cmd_config;
457 unless (system($namespaces) == 0) {
458 warn("Failed to add namespaces \n$namespaces");
459 return;
462 return;
465 sub setup_trust($$$$$)
467 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
469 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
471 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
472 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
473 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
474 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
475 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
477 my $samba_tool = Samba::bindir_path($self, "samba-tool");
479 # setup the trust
480 my $cmd_env = $self->get_cmd_env_vars($localenv);
482 my $cmd_config = " $localenv->{CONFIGURATION}";
483 my $cmd_creds = $cmd_config;
484 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
486 my $create = $cmd_env;
487 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
488 $create .= " $extra_args";
489 $create .= $cmd_creds;
490 unless (system($create) == 0) {
491 warn("Failed to create trust \n$create");
492 return undef;
495 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
496 my $groupadd = $cmd_env;
497 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
498 unless (system($groupadd) == 0) {
499 warn("Failed to create group \n$groupadd");
500 return undef;
502 my $groupmem = $cmd_env;
503 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
504 unless (system($groupmem) == 0) {
505 warn("Failed to add group member \n$groupmem");
506 return undef;
509 return $localenv
512 sub provision_raw_prepare($$$$$$$$$$$$$$)
514 my ($self,
515 $prefix,
516 $server_role,
517 $hostname,
518 $domain,
519 $realm,
520 $samsid,
521 $functional_level,
522 $password,
523 $kdc_ipv4,
524 $kdc_ipv6,
525 $force_fips_mode,
526 $extra_provision_options) = @_;
527 my $ctx;
528 my $python_cmd = "";
529 if (defined $ENV{PYTHON}) {
530 $python_cmd = $ENV{PYTHON} . " ";
532 $ctx->{python} = $python_cmd;
533 my $netbiosname = uc($hostname);
535 unless(-d $prefix or mkdir($prefix, 0777)) {
536 warn("Unable to create $prefix");
537 return undef;
539 my $prefix_abs = abs_path($prefix);
541 die ("prefix=''") if $prefix_abs eq "";
542 die ("prefix='/'") if $prefix_abs eq "/";
544 unless (system("rm -rf $prefix_abs/*") == 0) {
545 warn("Unable to clean up");
549 my $swiface = Samba::get_interface($hostname);
551 $ctx->{prefix} = $prefix;
552 $ctx->{prefix_abs} = $prefix_abs;
554 $ctx->{server_role} = $server_role;
555 $ctx->{hostname} = $hostname;
556 $ctx->{netbiosname} = $netbiosname;
557 $ctx->{swiface} = $swiface;
558 $ctx->{password} = $password;
559 $ctx->{kdc_ipv4} = $kdc_ipv4;
560 $ctx->{kdc_ipv6} = $kdc_ipv6;
561 $ctx->{force_fips_mode} = $force_fips_mode;
562 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
563 if ($functional_level eq "2000") {
564 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc";
568 # Set smbd log level here.
570 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
571 $ctx->{username} = "Administrator";
572 $ctx->{domain} = $domain;
573 $ctx->{realm} = uc($realm);
574 $ctx->{dnsname} = lc($realm);
575 $ctx->{samsid} = $samsid;
577 $ctx->{functional_level} = $functional_level;
579 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
580 chomp $unix_name;
581 $ctx->{unix_name} = $unix_name;
582 $ctx->{unix_uid} = $>;
583 my @mygid = split(" ", $();
584 $ctx->{unix_gid} = $mygid[0];
585 $ctx->{unix_gids_str} = $);
586 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
588 $ctx->{etcdir} = "$prefix_abs/etc";
589 $ctx->{piddir} = "$prefix_abs/pid";
590 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
591 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
592 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
593 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
594 $ctx->{gnupghome} = "$prefix_abs/gnupg";
595 $ctx->{privatedir} = "$prefix_abs/private";
596 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
597 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
598 $ctx->{lockdir} = "$prefix_abs/lockdir";
599 $ctx->{logdir} = "$prefix_abs/logs";
600 $ctx->{statedir} = "$prefix_abs/statedir";
601 $ctx->{cachedir} = "$prefix_abs/cachedir";
602 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
603 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
604 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
605 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
606 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
607 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
608 if ($ENV{SAMBA_DNS_FAKING}) {
609 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
610 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
611 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
612 } else {
613 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
614 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
615 $ctx->{use_resolv_wrapper} = 1;
618 my $dns_hub = $self->get_dns_hub_env();
619 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
621 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
623 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
624 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
626 push(@{$ctx->{directories}}, $ctx->{privatedir});
627 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
628 push(@{$ctx->{directories}}, $ctx->{etcdir});
629 push(@{$ctx->{directories}}, $ctx->{piddir});
630 push(@{$ctx->{directories}}, $ctx->{lockdir});
631 push(@{$ctx->{directories}}, $ctx->{logdir});
632 push(@{$ctx->{directories}}, $ctx->{statedir});
633 push(@{$ctx->{directories}}, $ctx->{cachedir});
635 $ctx->{smb_conf_extra_options} = "";
637 my @provision_options = ();
638 push (@provision_options, "GNUPGHOME=\"$ctx->{gnupghome}\"");
639 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
640 push (@provision_options, "KRB5CCNAME=\"$ctx->{krb5_ccache}\"");
641 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
642 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
643 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
644 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
645 if (defined($ctx->{use_resolv_wrapper})) {
646 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
647 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
648 } else {
649 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
651 if (defined($ctx->{force_fips_mode})) {
652 push (@provision_options, "GNUTLS_FORCE_FIPS_MODE=1");
653 push (@provision_options, "OPENSSL_FORCE_FIPS_MODE=1");
656 if (defined($ENV{GDB_PROVISION})) {
657 push (@provision_options, "gdb --args");
658 if (!defined($ENV{PYTHON})) {
659 push (@provision_options, "env");
660 push (@provision_options, "python");
663 if (defined($ENV{VALGRIND_PROVISION})) {
664 push (@provision_options, "valgrind");
665 if (!defined($ENV{PYTHON})) {
666 push (@provision_options, "env");
667 push (@provision_options, "python");
671 my $samba_tool = Samba::bindir_path($self, "samba-tool");
673 push (@provision_options, $samba_tool);
674 push (@provision_options, "domain");
675 push (@provision_options, "provision");
676 push (@provision_options, "--configfile=$ctx->{smb_conf}");
677 push (@provision_options, "--host-name=$ctx->{hostname}");
678 push (@provision_options, "--host-ip=$ctx->{ipv4}");
679 push (@provision_options, "--quiet");
680 push (@provision_options, "--domain=$ctx->{domain}");
681 push (@provision_options, "--realm=$ctx->{realm}");
682 if (defined($ctx->{samsid})) {
683 push (@provision_options, "--domain-sid=$ctx->{samsid}");
685 push (@provision_options, "--adminpass=$ctx->{password}");
686 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
687 push (@provision_options, "--machinepass=machine$ctx->{password}");
688 push (@provision_options, "--root=$ctx->{unix_name}");
689 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
690 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
692 @{$ctx->{provision_options}} = @provision_options;
694 if (defined($extra_provision_options)) {
695 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
698 return $ctx;
701 sub has_option
703 my ($self, $keyword, @options_list) = @_;
705 # convert the options-list to a hash-map for easy keyword lookup
706 my %options_dict = map { $_ => 1 } @options_list;
708 return exists $options_dict{$keyword};
712 # Step1 creates the basic configuration
714 sub provision_raw_step1($$)
716 my ($self, $ctx) = @_;
718 mkdir($_, 0777) foreach (@{$ctx->{directories}});
721 ## lockdir and piddir must be 0755
723 chmod 0755, $ctx->{lockdir};
724 chmod 0755, $ctx->{piddir};
726 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
727 warn("can't open $ctx->{smb_conf}$?");
728 return undef;
731 Samba::copy_gnupg_home($ctx);
732 Samba::prepare_keyblobs($ctx);
733 my $crlfile = "$ctx->{tlsdir}/crl.pem";
734 $crlfile = "" unless -e ${crlfile};
736 # work out which file server to use. Default to source3 smbd (s3fs),
737 # unless the source4 NTVFS (smb) file server has been specified
738 my $services = "-smb +s3fs";
739 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
740 $services = "+smb -s3fs";
743 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
745 print CONFFILE "
746 [global]
747 netbios name = $ctx->{netbiosname}
748 posix:eadb = $ctx->{statedir}/eadb.tdb
749 workgroup = $ctx->{domain}
750 realm = $ctx->{realm}
751 private dir = $ctx->{privatedir}
752 binddns dir = $ctx->{binddnsdir}
753 pid directory = $ctx->{piddir}
754 ncalrpc dir = $ctx->{ncalrpcdir}
755 lock dir = $ctx->{lockdir}
756 state directory = $ctx->{statedir}
757 cache directory = $ctx->{cachedir}
758 winbindd socket directory = $ctx->{winbindd_socket_dir}
759 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
760 winbind separator = /
761 interfaces = $interfaces
762 tls dh params file = $ctx->{tlsdir}/dhparms.pem
763 tls crlfile = ${crlfile}
764 tls verify peer = no_check
765 panic action = $RealBin/gdb_backtrace \%d
766 wins support = yes
767 server role = $ctx->{server_role}
768 server services = +echo $services
769 dcerpc endpoint servers = +winreg +srvsvc
770 notify:inotify = false
771 ldb:nosync = true
772 ldap server require strong auth = yes
773 #We don't want to pass our self-tests if the PAC code is wrong
774 gensec:require_pac = true
775 log file = $ctx->{logdir}/log.\%m
776 log level = $ctx->{server_loglevel}
777 lanman auth = Yes
778 ntlm auth = Yes
779 client min protocol = SMB2_02
780 server min protocol = SMB2_02
781 mangled names = yes
782 dns update command = $ctx->{samba_dnsupdate}
783 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
784 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
785 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
786 dreplsrv:periodic_startup_interval = 0
787 dsdb:schema update allowed = yes
789 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
791 idmap_ldb:use rfc2307=yes
792 winbind enum users = yes
793 winbind enum groups = yes
795 rpc server port:netlogon = 1026
796 include system krb5 conf = no
800 print CONFFILE "
802 # Begin extra options
803 $ctx->{smb_conf_extra_options}
804 # End extra options
806 close(CONFFILE);
808 #Default the KDC IP to the server's IP
809 if (not defined($ctx->{kdc_ipv4})) {
810 $ctx->{kdc_ipv4} = $ctx->{ipv4};
812 if (not defined($ctx->{kdc_ipv6})) {
813 $ctx->{kdc_ipv6} = $ctx->{ipv6};
816 Samba::mk_krb5_conf($ctx);
817 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
819 open(PWD, ">$ctx->{nsswrap_passwd}");
820 if ($ctx->{unix_uid} != 0) {
821 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
823 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
824 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
825 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
826 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
827 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
828 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
830 close(PWD);
831 my $uid_rfc2307test = 65533;
833 open(GRP, ">$ctx->{nsswrap_group}");
834 if ($ctx->{unix_gid} != 0) {
835 print GRP "root:x:0:\n";
837 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
838 print GRP "wheel:x:10:
839 users:x:65531:
840 nobody:x:65533:
841 nogroup:x:65534:nobody
843 close(GRP);
844 my $gid_rfc2307test = 65532;
846 my $hostname = lc($ctx->{hostname});
847 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
848 if ($hostname eq "localdc") {
849 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
850 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
851 } else {
852 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
853 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
855 close(HOSTS);
857 my $configuration = "--configfile=$ctx->{smb_conf}";
859 #Ensure the config file is valid before we start
860 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
861 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
862 system("$testparm -v --suppress-prompt $configuration >&2");
863 warn("Failed to create a valid smb.conf configuration $testparm!");
864 return undef;
866 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) {
867 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
868 return undef;
871 # Return the environment variables for the new testenv DC.
872 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
873 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
874 my $ret = {
875 GNUPGHOME => $ctx->{gnupghome},
876 KRB5_CONFIG => $ctx->{krb5_conf},
877 KRB5_CCACHE => $ctx->{krb5_ccache},
878 MITKDC_CONFIG => $ctx->{mitkdc_conf},
879 PIDDIR => $ctx->{piddir},
880 SERVER => $ctx->{hostname},
881 DC_SERVER => $ctx->{hostname},
882 SERVER_IP => $ctx->{ipv4},
883 DC_SERVER_IP => $ctx->{ipv4},
884 SERVER_IPV6 => $ctx->{ipv6},
885 DC_SERVER_IPV6 => $ctx->{ipv6},
886 NETBIOSNAME => $ctx->{netbiosname},
887 DC_NETBIOSNAME => $ctx->{netbiosname},
888 DOMAIN => $ctx->{domain},
889 USERNAME => $ctx->{username},
890 DC_USERNAME => $ctx->{username},
891 REALM => $ctx->{realm},
892 DNSNAME => $ctx->{dnsname},
893 SAMSID => $ctx->{samsid},
894 PASSWORD => $ctx->{password},
895 DC_PASSWORD => $ctx->{password},
896 LDAPDIR => $ctx->{ldapdir},
897 LDAP_INSTANCE => $ctx->{ldap_instance},
898 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
899 NCALRPCDIR => $ctx->{ncalrpcdir},
900 LOCKDIR => $ctx->{lockdir},
901 STATEDIR => $ctx->{statedir},
902 CACHEDIR => $ctx->{cachedir},
903 PRIVATEDIR => $ctx->{privatedir},
904 BINDDNSDIR => $ctx->{binddnsdir},
905 SERVERCONFFILE => $ctx->{smb_conf},
906 TESTENV_DIR => $ctx->{prefix_abs},
907 CONFIGURATION => $configuration,
908 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
909 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
910 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
911 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
912 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
913 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
914 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
915 SAMBA_TEST_LOG_POS => 0,
916 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
917 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
918 LOCAL_PATH => $ctx->{share},
919 UID_RFC2307TEST => $uid_rfc2307test,
920 GID_RFC2307TEST => $gid_rfc2307test,
921 SERVER_ROLE => $ctx->{server_role},
922 RESOLV_CONF => $ctx->{resolv_conf},
925 if (defined($ctx->{use_resolv_wrapper})) {
926 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
927 } else {
928 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
930 if (defined($ctx->{force_fips_mode})) {
931 $ret->{GNUTLS_FORCE_FIPS_MODE} = "1",
932 $ret->{OPENSSL_FORCE_FIPS_MODE} = "1",
935 if ($ctx->{server_role} eq "domain controller") {
936 $ret->{DOMSID} = $ret->{SAMSID};
939 return $ret;
943 # Step2 runs the provision script
945 sub provision_raw_step2($$$)
947 my ($self, $ctx, $ret) = @_;
949 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
950 unless (system($provision_cmd) == 0) {
951 warn("Unable to provision: \n$provision_cmd\n");
952 return undef;
955 my $cmd_env = $self->get_cmd_env_vars($ret);
957 my $testallowed_account = "testallowed";
958 my $samba_tool_cmd = ${cmd_env};
959 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
960 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
961 unless (system($samba_tool_cmd) == 0) {
962 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
963 return undef;
966 my $srv_account = "srv_account";
967 $samba_tool_cmd = ${cmd_env};
968 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
969 . " user create --configfile=$ctx->{smb_conf} $srv_account $ctx->{password}";
970 unless (system($samba_tool_cmd) == 0) {
971 warn("Unable to add $srv_account user: \n$samba_tool_cmd\n");
972 return undef;
975 $samba_tool_cmd = ${cmd_env};
976 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
977 . " spn add HOST/$srv_account --configfile=$ctx->{smb_conf} $srv_account";
978 unless (system($samba_tool_cmd) == 0) {
979 warn("Unable to add spn for $srv_account: \n$samba_tool_cmd\n");
980 return undef;
983 my $ldbmodify = ${cmd_env};
984 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
985 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
986 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
988 if ($ctx->{server_role} ne "domain controller") {
989 $base_dn = "DC=$ctx->{netbiosname}";
992 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
993 $testallowed_account = "testallowed account";
994 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
995 print LDIF "dn: $user_dn
996 changetype: modify
997 replace: samAccountName
998 samAccountName: $testallowed_account
1001 close(LDIF);
1003 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1004 print LDIF "dn: $user_dn
1005 changetype: modify
1006 replace: userPrincipalName
1007 userPrincipalName: testallowed upn\@$ctx->{realm}
1008 replace: servicePrincipalName
1009 servicePrincipalName: host/testallowed
1012 close(LDIF);
1014 $samba_tool_cmd = ${cmd_env};
1015 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1016 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1017 unless (system($samba_tool_cmd) == 0) {
1018 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1019 return undef;
1022 $user_dn = "cn=testdenied,cn=users,$base_dn";
1023 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1024 print LDIF "dn: $user_dn
1025 changetype: modify
1026 replace: userPrincipalName
1027 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1030 close(LDIF);
1032 $samba_tool_cmd = ${cmd_env};
1033 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1034 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1035 unless (system($samba_tool_cmd) == 0) {
1036 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1037 return undef;
1040 $user_dn = "cn=testupnspn,cn=users,$base_dn";
1041 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1042 print LDIF "dn: $user_dn
1043 changetype: modify
1044 replace: userPrincipalName
1045 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1046 replace: servicePrincipalName
1047 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1050 close(LDIF);
1052 $samba_tool_cmd = ${cmd_env};
1053 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1054 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1055 unless (system($samba_tool_cmd) == 0) {
1056 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1057 return undef;
1060 # Create to users alice and bob!
1061 my $user_account_array = ["alice", "bob", "jane", "joe"];
1063 foreach my $user_account (@{$user_account_array}) {
1064 my $samba_tool_cmd = ${cmd_env};
1066 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1067 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1068 unless (system($samba_tool_cmd) == 0) {
1069 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1070 return undef;
1074 my $group_array = ["Samba Users"];
1076 foreach my $group (@{$group_array}) {
1077 my $samba_tool_cmd = ${cmd_env};
1079 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1080 . " group add --configfile=$ctx->{smb_conf} \"$group\"";
1081 unless (system($samba_tool_cmd) == 0) {
1082 warn("Unable to create group: $group\n$samba_tool_cmd\n");
1083 return undef;
1087 # Add user joe to group "Samba Users"
1088 my $group = "Samba Users";
1089 my $user_account = "joe";
1091 $samba_tool_cmd = ${cmd_env};
1092 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1093 . " group addmembers --configfile=$ctx->{smb_conf} \"$group\" $user_account";
1094 unless (system($samba_tool_cmd) == 0) {
1095 warn("Unable to add " . $user_account . "to group group : $group\n$samba_tool_cmd\n");
1096 return undef;
1099 $group = "Samba Users";
1100 $user_account = "joe";
1102 $samba_tool_cmd = ${cmd_env};
1103 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1104 . " user setprimarygroup --configfile=$ctx->{smb_conf} $user_account \"$group\"";
1105 unless (system($samba_tool_cmd) == 0) {
1106 warn("Unable to set primary group of user: $user_account\n$samba_tool_cmd\n");
1107 return undef;
1110 # Change the userPrincipalName for jane
1111 $user_dn = "cn=jane,cn=users,$base_dn";
1113 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
1114 print LDIF "dn: $user_dn
1115 changetype: modify
1116 replace: userPrincipalName
1117 userPrincipalName: jane.doe\@$ctx->{realm}
1120 close(LDIF);
1122 return $ret;
1125 sub provision($$$$$$$$$$$)
1127 my ($self,
1128 $prefix,
1129 $server_role,
1130 $hostname,
1131 $domain,
1132 $realm,
1133 $functional_level,
1134 $password,
1135 $kdc_ipv4,
1136 $kdc_ipv6,
1137 $force_fips_mode,
1138 $extra_smbconf_options,
1139 $extra_smbconf_shares,
1140 $extra_provision_options) = @_;
1142 my $samsid = Samba::random_domain_sid();
1144 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1145 $hostname,
1146 $domain, $realm,
1147 $samsid,
1148 $functional_level,
1149 $password,
1150 $kdc_ipv4,
1151 $kdc_ipv6,
1152 $force_fips_mode,
1153 $extra_provision_options);
1155 $ctx->{share} = "$ctx->{prefix_abs}/share";
1156 push(@{$ctx->{directories}}, "$ctx->{share}");
1157 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1158 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1160 # precreate directories for printer drivers
1161 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1162 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1163 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1165 my $msdfs = "no";
1166 $msdfs = "yes" if ($server_role eq "domain controller");
1167 $ctx->{smb_conf_extra_options} = "
1169 max xmit = 32K
1170 server max protocol = SMB2
1171 host msdfs = $msdfs
1172 lanman auth = yes
1174 # fruit:copyfile is a global option
1175 fruit:copyfile = yes
1177 $extra_smbconf_options
1179 [tmp]
1180 path = $ctx->{share}
1181 read only = no
1182 posix:sharedelay = 100000
1183 posix:oplocktimeout = 3
1184 posix:writetimeupdatedelay = 500000
1186 [xcopy_share]
1187 path = $ctx->{share}
1188 read only = no
1189 posix:sharedelay = 100000
1190 posix:oplocktimeout = 3
1191 posix:writetimeupdatedelay = 500000
1192 create mask = 777
1193 force create mode = 777
1195 [posix_share]
1196 path = $ctx->{share}
1197 read only = no
1198 create mask = 0777
1199 force create mode = 0
1200 directory mask = 0777
1201 force directory mode = 0
1203 [test1]
1204 path = $ctx->{share}/test1
1205 read only = no
1206 posix:sharedelay = 100000
1207 posix:oplocktimeout = 3
1208 posix:writetimeupdatedelay = 500000
1210 [test2]
1211 path = $ctx->{share}/test2
1212 read only = no
1213 posix:sharedelay = 100000
1214 posix:oplocktimeout = 3
1215 posix:writetimeupdatedelay = 500000
1217 [cifs]
1218 path = $ctx->{share}/_ignore_cifs_
1219 read only = no
1220 ntvfs handler = cifs
1221 cifs:server = $ctx->{netbiosname}
1222 cifs:share = tmp
1223 cifs:use-s4u2proxy = yes
1224 # There is no username specified here, instead the client is expected
1225 # to log in with kerberos, and the serverwill use delegated credentials.
1226 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1228 [simple]
1229 path = $ctx->{share}
1230 read only = no
1231 ntvfs handler = simple
1233 [sysvol]
1234 path = $ctx->{statedir}/sysvol
1235 read only = no
1237 [netlogon]
1238 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1239 read only = no
1241 [cifsposix]
1242 copy = simple
1243 ntvfs handler = cifsposix
1245 [vfs_fruit]
1246 path = $ctx->{share}
1247 vfs objects = catia fruit streams_xattr acl_xattr
1248 ea support = yes
1249 fruit:resource = file
1250 fruit:metadata = netatalk
1251 fruit:locking = netatalk
1252 fruit:encoding = native
1254 [xattr]
1255 path = $ctx->{share}
1256 # This can be used for testing real fs xattr stuff
1257 vfs objects = streams_xattr acl_xattr
1259 $extra_smbconf_shares
1262 my $ret = $self->provision_raw_step1($ctx);
1263 unless (defined $ret) {
1264 return undef;
1267 return $self->provision_raw_step2($ctx, $ret);
1270 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1271 # original DC) in the testenv. $SERVER is always the joined DC that we are
1272 # actually running the test against
1273 sub set_pdc_env_vars
1275 my ($self, $env, $dcvars) = @_;
1277 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1278 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1279 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1280 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1281 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1282 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1283 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1286 sub provision_s4member($$$$$)
1288 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1289 print "PROVISIONING MEMBER...\n";
1290 my $extra_smb_conf = "
1291 passdb backend = samba_dsdb
1292 winbindd:use external pipes = true
1294 # the source4 smb server doesn't allow signing by default
1295 server signing = enabled
1296 raw NTLMv2 auth = yes
1298 rpc_server:default = external
1299 rpc_server:svcctl = embedded
1300 rpc_server:srvsvc = embedded
1301 rpc_server:eventlog = embedded
1302 rpc_server:ntsvcs = embedded
1303 rpc_server:winreg = embedded
1304 rpc_server:spoolss = embedded
1305 rpc_daemon:spoolssd = embedded
1306 rpc_server:tcpip = no
1307 # override the new SMB2 only default
1308 client min protocol = CORE
1309 server min protocol = LANMAN1
1311 if ($more_conf) {
1312 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1314 my $extra_provision_options = ["--use-ntvfs"];
1315 my $ret = $self->provision($prefix,
1316 "member server",
1317 $hostname,
1318 $dcvars->{DOMAIN},
1319 $dcvars->{REALM},
1320 "2008",
1321 "locMEMpass3",
1322 $dcvars->{SERVER_IP},
1323 $dcvars->{SERVER_IPV6},
1324 undef,
1325 $extra_smb_conf, "",
1326 $extra_provision_options);
1327 unless ($ret) {
1328 return undef;
1331 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1332 my $cmd = $self->get_cmd_env_vars($ret);
1333 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1334 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1335 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1337 unless (system($cmd) == 0) {
1338 warn("Join failed\n$cmd");
1339 return undef;
1342 $ret->{DOMSID} = $dcvars->{DOMSID};
1343 $self->set_pdc_env_vars($ret, $dcvars);
1345 return $ret;
1348 sub provision_rpc_proxy($$$)
1350 my ($self, $prefix, $dcvars) = @_;
1351 print "PROVISIONING RPC PROXY...\n";
1353 my $extra_smbconf_options = "
1354 passdb backend = samba_dsdb
1356 # rpc_proxy
1357 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1358 dcerpc endpoint servers = epmapper, remote
1359 dcerpc_remote:interfaces = rpcecho
1360 dcerpc_remote:allow_anonymous_fallback = yes
1361 # override the new SMB2 only default
1362 client min protocol = CORE
1363 server min protocol = LANMAN1
1364 [cifs_to_dc]
1365 path = /tmp/_ignore_cifs_to_dc_/_none_
1366 read only = no
1367 ntvfs handler = cifs
1368 cifs:server = $dcvars->{SERVER}
1369 cifs:share = cifs
1370 cifs:use-s4u2proxy = yes
1371 # There is no username specified here, instead the client is expected
1372 # to log in with kerberos, and the serverwill use delegated credentials.
1373 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1377 my $extra_provision_options = ["--use-ntvfs"];
1378 my $ret = $self->provision($prefix,
1379 "member server",
1380 "localrpcproxy",
1381 $dcvars->{DOMAIN},
1382 $dcvars->{REALM},
1383 "2008",
1384 "locRPCproxypass4",
1385 $dcvars->{SERVER_IP},
1386 $dcvars->{SERVER_IPV6},
1387 undef,
1388 $extra_smbconf_options, "",
1389 $extra_provision_options);
1390 unless ($ret) {
1391 return undef;
1394 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1396 # The joind runs in the context of the rpc_proxy/member for now
1397 my $cmd = $self->get_cmd_env_vars($ret);
1398 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1399 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1400 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1402 unless (system($cmd) == 0) {
1403 warn("Join failed\n$cmd");
1404 return undef;
1407 # Prepare a context of the DC, but using the local CCACHE.
1408 my $overwrite = undef;
1409 $overwrite->{KRB5_CCACHE} = $ret->{KRB5_CCACHE};
1410 my $dc_cmd_env = $self->get_cmd_env_vars($dcvars, $overwrite);
1412 # Setting up delegation runs in the context of the DC for now
1413 $cmd = $dc_cmd_env;
1414 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1415 $cmd .= " $dcvars->{CONFIGURATION}";
1416 print $cmd;
1418 unless (system($cmd) == 0) {
1419 warn("Delegation failed\n$cmd");
1420 return undef;
1423 # Setting up delegation runs in the context of the DC for now
1424 $cmd = $dc_cmd_env;
1425 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1426 $cmd .= " $dcvars->{CONFIGURATION}";
1428 unless (system($cmd) == 0) {
1429 warn("Delegation failed\n$cmd");
1430 return undef;
1433 $ret->{DOMSID} = $dcvars->{DOMSID};
1434 $self->set_pdc_env_vars($ret, $dcvars);
1436 return $ret;
1439 sub provision_promoted_dc($$$)
1441 my ($self, $prefix, $dcvars) = @_;
1442 print "PROVISIONING PROMOTED DC...\n";
1444 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1445 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1446 "promotedvdc",
1447 $dcvars->{DOMAIN},
1448 $dcvars->{REALM},
1449 $dcvars->{SAMSID},
1450 "2008",
1451 $dcvars->{PASSWORD},
1452 $dcvars->{SERVER_IP},
1453 $dcvars->{SERVER_IPV6});
1455 $ctx->{smb_conf_extra_options} = "
1456 max xmit = 32K
1457 server max protocol = SMB2
1459 ntlm auth = ntlmv2-only
1461 [sysvol]
1462 path = $ctx->{statedir}/sysvol
1463 read only = yes
1465 [netlogon]
1466 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1467 read only = no
1471 my $ret = $self->provision_raw_step1($ctx);
1472 unless ($ret) {
1473 return undef;
1476 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1477 my $cmd = $self->get_cmd_env_vars($ret);
1478 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1479 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1480 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1482 unless (system($cmd) == 0) {
1483 warn("Join failed\n$cmd");
1484 return undef;
1487 $samba_tool = Samba::bindir_path($self, "samba-tool");
1488 $cmd = $self->get_cmd_env_vars($ret);
1489 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1490 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1491 $cmd .= " --machinepass=machine$ret->{PASSWORD} --dns-backend=BIND9_DLZ";
1493 unless (system($cmd) == 0) {
1494 warn("Join failed\n$cmd");
1495 return undef;
1498 $self->set_pdc_env_vars($ret, $dcvars);
1500 return $ret;
1503 sub provision_vampire_dc($$$)
1505 my ($self, $prefix, $dcvars, $fl) = @_;
1506 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1507 my $name = "localvampiredc";
1508 my $extra_conf = "";
1510 if ($fl == "2000") {
1511 $name = "vampire2000dc";
1512 } else {
1513 $extra_conf = "drs: immediate link sync = yes
1514 drs: max link sync = 250";
1517 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1518 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1519 $name,
1520 $dcvars->{DOMAIN},
1521 $dcvars->{REALM},
1522 $dcvars->{DOMSID},
1523 $fl,
1524 $dcvars->{PASSWORD},
1525 $dcvars->{SERVER_IP},
1526 $dcvars->{SERVER_IPV6});
1528 $ctx->{smb_conf_extra_options} = "
1529 max xmit = 32K
1530 server max protocol = SMB2
1532 ntlm auth = mschapv2-and-ntlmv2-only
1533 $extra_conf
1535 [sysvol]
1536 path = $ctx->{statedir}/sysvol
1537 read only = yes
1539 [netlogon]
1540 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1541 read only = no
1545 my $ret = $self->provision_raw_step1($ctx);
1546 unless ($ret) {
1547 return undef;
1550 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1551 my $cmd = $self->get_cmd_env_vars($ret);
1552 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1553 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1554 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1555 $cmd .= " --backend-store=mdb";
1557 unless (system($cmd) == 0) {
1558 warn("Join failed\n$cmd");
1559 return undef;
1562 $self->set_pdc_env_vars($ret, $dcvars);
1563 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1565 return $ret;
1568 sub provision_ad_dc_ntvfs($$$)
1570 my ($self, $prefix, $extra_provision_options) = @_;
1572 # We keep the old 'winbind' name here in server services to
1573 # ensure upgrades which used that name still work with the now
1574 # alias.
1576 print "PROVISIONING AD DC (NTVFS)...\n";
1577 my $extra_conf_options = "netbios aliases = localDC1-a
1578 server services = +winbind -winbindd
1579 ldap server require strong auth = allow_sasl_over_tls
1580 allow nt4 crypto = yes
1581 raw NTLMv2 auth = yes
1582 lsa over netlogon = yes
1583 rpc server port = 1027
1584 auth event notification = true
1585 dsdb event notification = true
1586 dsdb password event notification = true
1587 dsdb group change notification = true
1588 server schannel = auto
1589 # override the new SMB2 only default
1590 client min protocol = CORE
1591 server min protocol = LANMAN1
1593 push (@{$extra_provision_options}, "--use-ntvfs");
1594 my $ret = $self->provision($prefix,
1595 "domain controller",
1596 "localdc",
1597 "SAMBADOMAIN",
1598 "samba.example.com",
1599 "2008",
1600 "locDCpass1",
1601 undef,
1602 undef,
1603 undef,
1604 $extra_conf_options,
1606 $extra_provision_options);
1607 unless ($ret) {
1608 return undef;
1611 unless($self->add_wins_config("$prefix/private")) {
1612 warn("Unable to add wins configuration");
1613 return undef;
1615 $ret->{NETBIOSALIAS} = "localdc1-a";
1616 $ret->{DC_REALM} = $ret->{REALM};
1618 return $ret;
1621 sub provision_fl2000dc($$)
1623 my ($self, $prefix) = @_;
1625 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1626 my $extra_conf_options = "
1627 spnego:simulate_w2k=yes
1628 ntlmssp_server:force_old_spnego=yes
1630 my $extra_provision_options = ["--base-schema=2008_R2"];
1631 # This environment uses plain text secrets
1632 # i.e. secret attributes are not encrypted on disk.
1633 # This allows testing of the --plaintext-secrets option for
1634 # provision
1635 push (@{$extra_provision_options}, "--plaintext-secrets");
1636 my $ret = $self->provision($prefix,
1637 "domain controller",
1638 "dc5",
1639 "SAMBA2000",
1640 "samba2000.example.com",
1641 "2000",
1642 "locDCpass5",
1643 undef,
1644 undef,
1645 undef,
1646 $extra_conf_options,
1648 $extra_provision_options);
1649 unless ($ret) {
1650 return undef;
1653 unless($self->add_wins_config("$prefix/private")) {
1654 warn("Unable to add wins configuration");
1655 return undef;
1657 $ret->{DC_REALM} = $ret->{REALM};
1659 return $ret;
1662 sub provision_fl2003dc($$$)
1664 my ($self, $prefix, $dcvars) = @_;
1665 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1666 my $ip_addr2 = Samba::get_ipv4_addr("fakednsforwarder2");
1668 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1669 my $extra_conf_options = "allow dns updates = nonsecure and secure
1670 dcesrv:header signing = no
1671 dcesrv:max auth states = 0
1672 dns forwarder = $ip_addr1 $ip_addr2";
1673 my $extra_provision_options = ["--base-schema=2008_R2"];
1674 my $ret = $self->provision($prefix,
1675 "domain controller",
1676 "dc6",
1677 "SAMBA2003",
1678 "samba2003.example.com",
1679 "2003",
1680 "locDCpass6",
1681 undef,
1682 undef,
1683 undef,
1684 $extra_conf_options,
1686 $extra_provision_options);
1687 unless (defined $ret) {
1688 return undef;
1691 $ret->{DNS_FORWARDER1} = $ip_addr1;
1692 $ret->{DNS_FORWARDER2} = $ip_addr2;
1694 my @samba_tool_options;
1695 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1696 push (@samba_tool_options, "domain");
1697 push (@samba_tool_options, "passwordsettings");
1698 push (@samba_tool_options, "set");
1699 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1700 push (@samba_tool_options, "--min-pwd-age=0");
1701 push (@samba_tool_options, "--history-length=1");
1703 my $samba_tool_cmd = join(" ", @samba_tool_options);
1705 unless (system($samba_tool_cmd) == 0) {
1706 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1707 return undef;
1710 unless($self->add_wins_config("$prefix/private")) {
1711 warn("Unable to add wins configuration");
1712 return undef;
1715 return $ret;
1718 sub provision_fl2008r2dc($$$)
1720 my ($self, $prefix, $dcvars) = @_;
1722 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1723 my $extra_conf_options = "
1724 ldap server require strong auth = no
1725 # delay by 10 seconds, 10^7 usecs
1726 ldap_server:delay_expire_disconnect = 10000
1728 my $extra_provision_options = ["--base-schema=2008_R2"];
1729 my $ret = $self->provision($prefix,
1730 "domain controller",
1731 "dc7",
1732 "SAMBA2008R2",
1733 "samba2008R2.example.com",
1734 "2008_R2",
1735 "locDCpass7",
1736 undef,
1737 undef,
1738 undef,
1739 $extra_conf_options,
1741 $extra_provision_options);
1742 unless (defined $ret) {
1743 return undef;
1746 unless ($self->add_wins_config("$prefix/private")) {
1747 warn("Unable to add wins configuration");
1748 return undef;
1750 $ret->{DC_REALM} = $ret->{REALM};
1752 return $ret;
1756 sub provision_rodc($$$)
1758 my ($self, $prefix, $dcvars) = @_;
1759 print "PROVISIONING RODC...\n";
1761 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1762 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1763 "rodc",
1764 $dcvars->{DOMAIN},
1765 $dcvars->{REALM},
1766 $dcvars->{DOMSID},
1767 "2008",
1768 $dcvars->{PASSWORD},
1769 $dcvars->{SERVER_IP},
1770 $dcvars->{SERVER_IPV6});
1771 unless ($ctx) {
1772 return undef;
1775 $ctx->{share} = "$ctx->{prefix_abs}/share";
1776 push(@{$ctx->{directories}}, "$ctx->{share}");
1778 $ctx->{smb_conf_extra_options} = "
1779 max xmit = 32K
1780 server max protocol = SMB2
1781 password server = $dcvars->{DC_SERVER}
1783 [sysvol]
1784 path = $ctx->{statedir}/sysvol
1785 read only = yes
1787 [netlogon]
1788 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1789 read only = yes
1791 [tmp]
1792 path = $ctx->{share}
1793 read only = no
1794 posix:sharedelay = 10000
1795 posix:oplocktimeout = 3
1796 posix:writetimeupdatedelay = 50000
1800 my $ret = $self->provision_raw_step1($ctx);
1801 unless ($ret) {
1802 return undef;
1805 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1806 my $cmd = $self->get_cmd_env_vars($ret);
1807 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1808 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1809 $cmd .= " --server=$dcvars->{DC_SERVER}";
1811 unless (system($cmd) == 0) {
1812 warn("RODC join failed\n$cmd");
1813 return undef;
1816 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1817 # user password verified on the RODC
1818 my $testallowed_account = "testallowed account";
1819 $cmd = $self->get_cmd_env_vars($ret);
1820 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1821 $cmd .= " --server=$dcvars->{DC_SERVER}";
1823 unless (system($cmd) == 0) {
1824 warn("RODC join failed\n$cmd");
1825 return undef;
1828 # we overwrite the kdc after the RODC join
1829 # so that use the RODC as kdc and test
1830 # the proxy code
1831 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1832 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1833 Samba::mk_krb5_conf($ctx);
1834 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1836 $self->set_pdc_env_vars($ret, $dcvars);
1838 return $ret;
1841 sub read_config_h($)
1843 my ($name) = @_;
1844 my %ret;
1845 open(LF, "<$name") or die("unable to read $name: $!");
1846 while (<LF>) {
1847 chomp;
1848 next if not (/^#define /);
1849 if (/^#define (.*?)[ \t]+(.*?)$/) {
1850 $ret{$1} = $2;
1851 next;
1853 if (/^#define (.*?)[ \t]+$/) {
1854 $ret{$1} = 1;;
1855 next;
1858 close(LF);
1859 return \%ret;
1862 sub provision_ad_dc($$$$$$$)
1864 my ($self,
1865 $prefix,
1866 $hostname,
1867 $domain,
1868 $realm,
1869 $force_fips_mode,
1870 $smbconf_args,
1871 $extra_provision_options) = @_;
1873 my $prefix_abs = abs_path($prefix);
1875 my $bindir_abs = abs_path($self->{bindir});
1876 my $lockdir="$prefix_abs/lockdir";
1877 my $conffile="$prefix_abs/etc/smb.conf";
1879 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1880 if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} // '' eq "1") {
1881 $require_mutexes = "";
1884 my $config_h = {};
1886 if (defined($ENV{CONFIG_H})) {
1887 $config_h = read_config_h($ENV{CONFIG_H});
1890 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1891 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1893 my $extra_smbconf_options = "
1894 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1896 dbwrap_tdb_mutexes:* = yes
1897 ${require_mutexes}
1899 ${password_hash_gpg_key_ids}
1901 kernel oplocks = no
1902 kernel change notify = no
1903 smb2 leases = no
1905 logging = file
1906 printing = bsd
1907 printcap name = /dev/null
1909 max protocol = SMB3
1910 read only = no
1912 smbd:sharedelay = 100000
1913 smbd:writetimeupdatedelay = 500000
1914 create mask = 755
1915 dos filemode = yes
1916 check parent directory delete on close = yes
1918 dcerpc endpoint servers = -winreg -srvsvc
1920 printcap name = /dev/null
1922 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1923 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1925 printing = vlp
1926 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1927 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1928 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1929 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1930 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1931 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1932 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1933 lpq cache time = 0
1934 print notify backchannel = yes
1936 server schannel = auto
1937 auth event notification = true
1938 dsdb event notification = true
1939 dsdb password event notification = true
1940 dsdb group change notification = true
1941 $smbconf_args
1944 my $extra_smbconf_shares = "
1946 [tmpenc]
1947 copy = tmp
1948 smb encrypt = required
1950 [tmpcase]
1951 copy = tmp
1952 case sensitive = yes
1954 [tmpguest]
1955 copy = tmp
1956 guest ok = yes
1958 [hideunread]
1959 copy = tmp
1960 hide unreadable = yes
1962 [durable]
1963 copy = tmp
1964 kernel share modes = no
1965 kernel oplocks = no
1966 posix locking = no
1968 [print\$]
1969 copy = tmp
1971 [print1]
1972 copy = tmp
1973 printable = yes
1975 [print2]
1976 copy = print1
1977 [print3]
1978 copy = print1
1979 [print4]
1980 copy = print1
1981 guest ok = yes
1982 [lp]
1983 copy = print1
1986 push (@{$extra_provision_options}, "--backend-store=mdb");
1987 print "PROVISIONING AD DC...\n";
1988 my $ret = $self->provision($prefix,
1989 "domain controller",
1990 $hostname,
1991 $domain,
1992 $realm,
1993 "2008",
1994 "locDCpass1",
1995 undef,
1996 undef,
1997 $force_fips_mode,
1998 $extra_smbconf_options,
1999 $extra_smbconf_shares,
2000 $extra_provision_options);
2001 unless (defined $ret) {
2002 return undef;
2005 unless($self->add_wins_config("$prefix/private")) {
2006 warn("Unable to add wins configuration");
2007 return undef;
2010 return $ret;
2013 sub provision_chgdcpass($$)
2015 my ($self, $prefix) = @_;
2017 print "PROVISIONING CHGDCPASS...\n";
2018 # This environment disallows the use of this password
2019 # (and also removes the default AD complexity checks)
2020 my $unacceptable_password = "Paßßword-widk3Dsle32jxdBdskldsk55klASKQ";
2021 my $extra_smb_conf = "
2022 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
2023 allow dcerpc auth level connect:lsarpc = yes
2024 dcesrv:max auth states = 8
2026 my $extra_provision_options = ["--dns-backend=BIND9_DLZ"];
2027 my $ret = $self->provision($prefix,
2028 "domain controller",
2029 "chgdcpass",
2030 "CHDCDOMAIN",
2031 "chgdcpassword.samba.example.com",
2032 "2008",
2033 "chgDCpass1",
2034 undef,
2035 undef,
2036 undef,
2037 $extra_smb_conf,
2039 $extra_provision_options);
2040 unless (defined $ret) {
2041 return undef;
2044 unless($self->add_wins_config("$prefix/private")) {
2045 warn("Unable to add wins configuration");
2046 return undef;
2049 # Remove secrets.tdb from this environment to test that we
2050 # still start up on systems without the new matching
2051 # secrets.tdb records.
2052 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2053 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2054 return undef;
2057 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2059 return $ret;
2062 sub teardown_env_terminate($$)
2064 my ($self, $envvars) = @_;
2065 my $pid;
2067 # This should cause samba to terminate gracefully
2068 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2069 my $cmd = "";
2070 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2071 my $ret = system($cmd);
2072 if ($ret != 0) {
2073 warn "'$cmd' failed with '$ret'\n";
2076 # This should cause samba to terminate gracefully
2077 close($envvars->{STDIN_PIPE});
2079 $pid = $envvars->{SAMBA_PID};
2080 my $count = 0;
2081 my $childpid;
2083 # This should give it time to write out the gcov data
2084 until ($count > 15) {
2085 if (Samba::cleanup_child($pid, "samba") != 0) {
2086 return;
2088 sleep(1);
2089 $count++;
2092 # After 15 Seconds, work out why this thing is still alive
2093 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2094 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2096 until ($count > 30) {
2097 if (Samba::cleanup_child($pid, "samba") != 0) {
2098 return;
2100 sleep(1);
2101 $count++;
2104 if (kill(0, $pid)) {
2105 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2106 kill "TERM", $pid;
2109 until ($count > 40) {
2110 if (Samba::cleanup_child($pid, "samba") != 0) {
2111 return;
2113 sleep(1);
2114 $count++;
2116 # If it is still around, kill it
2117 if (kill(0, $pid)) {
2118 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2119 kill 9, $pid;
2121 return;
2124 sub teardown_env($$)
2126 my ($self, $envvars) = @_;
2127 teardown_env_terminate($self, $envvars);
2129 print $self->getlog_env($envvars);
2131 return;
2134 sub getlog_env($$)
2136 my ($self, $envvars) = @_;
2137 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2138 my $out = $title;
2140 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2142 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2143 while (<LOG>) {
2144 $out .= $_;
2146 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2147 close(LOG);
2149 return "" if $out eq $title;
2151 return $out;
2154 sub check_env($$)
2156 my ($self, $envvars) = @_;
2157 my $samba_pid = $envvars->{SAMBA_PID};
2159 if (not defined($samba_pid)) {
2160 return 0;
2161 } elsif ($samba_pid > 0) {
2162 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2164 if ($childpid == 0) {
2165 return 1;
2167 return 0;
2168 } else {
2169 return 1;
2173 # Declare the environments Samba4 makes available.
2174 # To be set up, they will be called as
2175 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2176 # The interdependencies between the testenvs are declared below. Some testenvs
2177 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2178 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2179 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2180 %Samba4::ENV_DEPS = (
2181 # name => [dep_1, dep_2, ...],
2182 dns_hub => [],
2183 ad_dc_ntvfs => ["dns_hub"],
2184 ad_dc_fips => ["dns_hub"],
2185 ad_dc => ["dns_hub"],
2186 ad_dc_smb1 => ["dns_hub"],
2187 ad_dc_smb1_done => ["ad_dc_smb1"],
2188 ad_dc_no_nss => ["dns_hub"],
2189 ad_dc_no_ntlm => ["dns_hub"],
2191 fl2008r2dc => ["ad_dc"],
2192 fl2003dc => ["ad_dc"],
2193 fl2000dc => ["dns_hub"],
2195 vampire_2000_dc => ["fl2000dc"],
2196 vampire_dc => ["ad_dc_ntvfs"],
2197 promoted_dc => ["ad_dc_ntvfs"],
2199 rodc => ["ad_dc_ntvfs"],
2200 rpc_proxy => ["ad_dc_ntvfs"],
2201 chgdcpass => ["dns_hub"],
2203 s4member_dflt_domain => ["ad_dc_ntvfs"],
2204 s4member => ["ad_dc_ntvfs"],
2206 # envs that test the server process model
2207 proclimitdc => ["dns_hub"],
2208 preforkrestartdc => ["dns_hub"],
2210 # backup/restore testenvs
2211 backupfromdc => ["dns_hub"],
2212 customdc => ["dns_hub"],
2213 restoredc => ["backupfromdc"],
2214 renamedc => ["backupfromdc"],
2215 offlinebackupdc => ["backupfromdc"],
2216 labdc => ["backupfromdc"],
2218 # aliases in order to split autbuild tasks
2219 fl2008dc => ["ad_dc"],
2220 ad_dc_default => ["ad_dc"],
2221 ad_dc_default_smb1 => ["ad_dc_smb1"],
2222 ad_dc_default_smb1_done => ["ad_dc_default_smb1"],
2223 ad_dc_slowtests => ["ad_dc"],
2224 ad_dc_backup => ["ad_dc"],
2226 schema_dc => ["dns_hub"],
2227 schema_pair_dc => ["schema_dc"],
2229 none => [],
2232 %Samba4::ENV_DEPS_POST = (
2233 schema_dc => ["schema_pair_dc"],
2236 sub return_alias_env
2238 my ($self, $path, $env) = @_;
2240 # just an alias
2241 return $env;
2244 sub setup_fl2008dc
2246 my ($self, $path) = @_;
2248 my $extra_args = ["--base-schema=2008_R2"];
2249 my $env = $self->provision_ad_dc_ntvfs($path, $extra_args);
2250 if (defined $env) {
2251 if (not defined($self->check_or_start($env, "standard"))) {
2252 warn("Failed to start fl2008dc");
2253 return undef;
2256 return $env;
2259 sub setup_ad_dc_default
2261 my ($self, $path, $dep_env) = @_;
2262 return $self->return_alias_env($path, $dep_env)
2265 sub setup_ad_dc_default_smb1
2267 my ($self, $path, $dep_env) = @_;
2268 return $self->return_alias_env($path, $dep_env)
2271 sub setup_ad_dc_default_smb1_done
2273 my ($self, $path, $dep_env) = @_;
2274 return $self->return_alias_env($path, $dep_env)
2277 sub setup_ad_dc_slowtests
2279 my ($self, $path, $dep_env) = @_;
2280 return $self->return_alias_env($path, $dep_env)
2283 sub setup_ad_dc_backup
2285 my ($self, $path, $dep_env) = @_;
2286 return $self->return_alias_env($path, $dep_env)
2289 sub setup_s4member
2291 my ($self, $path, $dc_vars) = @_;
2293 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2295 if (defined $env) {
2296 if (not defined($self->check_or_start($env, "standard"))) {
2297 return undef;
2301 return $env;
2304 sub setup_s4member_dflt_domain
2306 my ($self, $path, $dc_vars) = @_;
2308 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2309 "winbind use default domain = yes");
2311 if (defined $env) {
2312 if (not defined($self->check_or_start($env, "standard"))) {
2313 return undef;
2317 return $env;
2320 sub setup_rpc_proxy
2322 my ($self, $path, $dc_vars) = @_;
2324 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2326 if (defined $env) {
2327 if (not defined($self->check_or_start($env, "standard"))) {
2328 return undef;
2331 return $env;
2334 sub setup_ad_dc_ntvfs
2336 my ($self, $path) = @_;
2338 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2339 if (defined $env) {
2340 if (not defined($self->check_or_start($env, "standard"))) {
2341 warn("Failed to start ad_dc_ntvfs");
2342 return undef;
2345 return $env;
2348 sub setup_chgdcpass
2350 my ($self, $path) = @_;
2352 my $env = $self->provision_chgdcpass($path);
2353 if (defined $env) {
2354 if (not defined($self->check_or_start($env, "standard"))) {
2355 return undef;
2358 return $env;
2361 sub setup_fl2000dc
2363 my ($self, $path) = @_;
2365 my $env = $self->provision_fl2000dc($path);
2366 if (defined $env) {
2367 if (not defined($self->check_or_start($env, "standard"))) {
2368 return undef;
2372 return $env;
2375 sub setup_fl2003dc
2377 my ($self, $path, $dc_vars) = @_;
2379 my $env = $self->provision_fl2003dc($path);
2381 if (defined $env) {
2382 if (not defined($self->check_or_start($env, "standard"))) {
2383 return undef;
2386 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2388 return $env;
2391 sub setup_fl2008r2dc
2393 my ($self, $path, $dc_vars) = @_;
2395 my $env = $self->provision_fl2008r2dc($path);
2397 if (defined $env) {
2398 if (not defined($self->check_or_start($env, "standard"))) {
2399 return undef;
2402 my $upn_array = ["$env->{REALM}.upn"];
2403 my $spn_array = ["$env->{REALM}.spn"];
2405 $self->setup_namespaces($env, $upn_array, $spn_array);
2407 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2410 return $env;
2413 sub setup_vampire_dc
2415 return setup_generic_vampire_dc(@_, "2008");
2418 sub setup_vampire_2000_dc
2420 return setup_generic_vampire_dc(@_, "2000");
2423 sub setup_generic_vampire_dc
2425 my ($self, $path, $dc_vars, $fl) = @_;
2427 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2429 if (defined $env) {
2430 if (not defined($self->check_or_start($env, "single"))) {
2431 return undef;
2434 # force replicated DC to update repsTo/repsFrom
2435 # for vampired partitions
2436 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2438 # as 'vampired' dc may add data in its local replica
2439 # we need to synchronize data between DCs
2440 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2441 my $cmd = $self->get_cmd_env_vars($env);
2442 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2443 $cmd .= " $dc_vars->{CONFIGURATION}";
2444 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2445 # replicate Configuration NC
2446 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2447 unless(system($cmd_repl) == 0) {
2448 warn("Failed to replicate\n$cmd_repl");
2449 return undef;
2451 # replicate Default NC
2452 $cmd_repl = "$cmd \"$base_dn\"";
2453 unless(system($cmd_repl) == 0) {
2454 warn("Failed to replicate\n$cmd_repl");
2455 return undef;
2458 # Pull in a full set of changes from the main DC
2459 $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2460 $cmd = $self->get_cmd_env_vars($env);
2461 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2462 $cmd .= " $dc_vars->{CONFIGURATION}";
2463 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2464 # replicate Configuration NC
2465 $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2466 unless(system($cmd_repl) == 0) {
2467 warn("Failed to replicate\n$cmd_repl");
2468 return undef;
2470 # replicate Default NC
2471 $cmd_repl = "$cmd \"$base_dn\"";
2472 unless(system($cmd_repl) == 0) {
2473 warn("Failed to replicate\n$cmd_repl");
2474 return undef;
2478 return $env;
2481 sub setup_promoted_dc
2483 my ($self, $path, $dc_vars) = @_;
2485 my $env = $self->provision_promoted_dc($path, $dc_vars);
2487 if (defined $env) {
2488 if (not defined($self->check_or_start($env, "single"))) {
2489 return undef;
2492 # force source and replicated DC to update repsTo/repsFrom
2493 # for vampired partitions
2494 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2495 my $cmd = $self->get_cmd_env_vars($env);
2496 # as 'vampired' dc may add data in its local replica
2497 # we need to synchronize data between DCs
2498 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2499 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2500 $cmd .= " $dc_vars->{CONFIGURATION}";
2501 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2502 # replicate Configuration NC
2503 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2504 unless(system($cmd_repl) == 0) {
2505 warn("Failed to replicate\n$cmd_repl");
2506 return undef;
2508 # replicate Default NC
2509 $cmd_repl = "$cmd \"$base_dn\"";
2510 unless(system($cmd_repl) == 0) {
2511 warn("Failed to replicate\n$cmd_repl");
2512 return undef;
2516 return $env;
2519 sub setup_rodc
2521 my ($self, $path, $dc_vars) = @_;
2523 my $env = $self->provision_rodc($path, $dc_vars);
2525 unless ($env) {
2526 return undef;
2529 if (not defined($self->check_or_start($env, "standard"))) {
2530 return undef;
2533 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2534 my $cmd = $self->get_cmd_env_vars($env);
2536 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2537 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2538 $cmd .= " $dc_vars->{CONFIGURATION}";
2539 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2540 # replicate Configuration NC
2541 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2542 unless(system($cmd_repl) == 0) {
2543 warn("Failed to replicate\n$cmd_repl");
2544 return undef;
2546 # replicate Default NC
2547 $cmd_repl = "$cmd \"$base_dn\"";
2548 unless(system($cmd_repl) == 0) {
2549 warn("Failed to replicate\n$cmd_repl");
2550 return undef;
2553 return $env;
2556 sub _setup_ad_dc
2558 my ($self, $path, $conf_opts, $server, $dom) = @_;
2560 # If we didn't build with ADS, pretend this env was never available
2561 if (not $self->{target3}->have_ads()) {
2562 return "UNKNOWN";
2565 if (!defined($conf_opts)) {
2566 $conf_opts = "";
2568 if (!defined($server)) {
2569 $server = "addc";
2571 if (!defined($dom)) {
2572 $dom = "addom.samba.example.com";
2574 my $env = $self->provision_ad_dc($path, $server, "ADDOMAIN",
2575 $dom,
2576 undef,
2577 $conf_opts,
2578 undef);
2579 unless ($env) {
2580 return undef;
2583 if (not defined($self->check_or_start($env, "prefork"))) {
2584 return undef;
2587 my $upn_array = ["$env->{REALM}.upn"];
2588 my $spn_array = ["$env->{REALM}.spn"];
2590 $self->setup_namespaces($env, $upn_array, $spn_array);
2592 return $env;
2595 sub setup_ad_dc
2597 my ($self, $path) = @_;
2598 return _setup_ad_dc($self, $path, undef, undef, undef);
2601 sub setup_ad_dc_smb1
2603 my ($self, $path) = @_;
2604 my $conf_opts = "
2605 [global]
2606 client min protocol = CORE
2607 server min protocol = LANMAN1
2609 return _setup_ad_dc($self, $path, $conf_opts, "addcsmb1", "addom2.samba.example.com");
2612 sub setup_ad_dc_smb1_done
2614 my ($self, $path, $dep_env) = @_;
2615 return $self->return_alias_env($path, $dep_env);
2618 sub setup_ad_dc_no_nss
2620 my ($self, $path) = @_;
2622 # If we didn't build with ADS, pretend this env was never available
2623 if (not $self->{target3}->have_ads()) {
2624 return "UNKNOWN";
2627 my $env = $self->provision_ad_dc($path,
2628 "addc_no_nss",
2629 "ADNONSSDOMAIN",
2630 "adnonssdom.samba.example.com",
2631 undef,
2633 undef);
2634 unless ($env) {
2635 return undef;
2638 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2639 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2641 if (not defined($self->check_or_start($env, "single"))) {
2642 return undef;
2645 my $upn_array = ["$env->{REALM}.upn"];
2646 my $spn_array = ["$env->{REALM}.spn"];
2648 $self->setup_namespaces($env, $upn_array, $spn_array);
2650 return $env;
2653 sub setup_ad_dc_no_ntlm
2655 my ($self, $path) = @_;
2657 # If we didn't build with ADS, pretend this env was never available
2658 if (not $self->{target3}->have_ads()) {
2659 return "UNKNOWN";
2662 my $env = $self->provision_ad_dc($path,
2663 "addc_no_ntlm",
2664 "ADNONTLMDOMAIN",
2665 "adnontlmdom.samba.example.com",
2666 undef,
2667 "ntlm auth = disabled",
2668 undef);
2669 unless ($env) {
2670 return undef;
2673 if (not defined($self->check_or_start($env, "prefork"))) {
2674 return undef;
2677 my $upn_array = ["$env->{REALM}.upn"];
2678 my $spn_array = ["$env->{REALM}.spn"];
2680 $self->setup_namespaces($env, $upn_array, $spn_array);
2682 return $env;
2685 sub setup_ad_dc_fips
2687 my ($self, $path) = @_;
2689 # If we didn't build with ADS, pretend this env was never available
2690 if (not $self->{target3}->have_ads()) {
2691 return "UNKNOWN";
2694 my $env = $self->provision_ad_dc($path,
2695 "fipsdc",
2696 "FIPSDOMAIN",
2697 "fips.samba.example.com",
2700 undef);
2701 unless ($env) {
2702 return undef;
2705 if (not defined($self->check_or_start($env, "prefork"))) {
2706 return undef;
2709 my $upn_array = ["$env->{REALM}.upn"];
2710 my $spn_array = ["$env->{REALM}.spn"];
2712 $self->setup_namespaces($env, $upn_array, $spn_array);
2714 return $env;
2718 # AD DC test environment used solely to test pre-fork process restarts.
2719 # As processes get killed off and restarted it should not be used for other
2720 sub setup_preforkrestartdc
2722 my ($self, $path) = @_;
2724 # If we didn't build with ADS, pretend this env was never available
2725 if (not $self->{target3}->have_ads()) {
2726 return "UNKNOWN";
2729 # note DC name must be <= 15 chars so we use 'prockill' instead of
2730 # 'preforkrestart'
2731 my $env = $self->provision_ad_dc($path,
2732 "prockilldc",
2733 "PROCKILLDOMAIN",
2734 "prockilldom.samba.example.com",
2735 undef,
2736 "prefork backoff increment = 5\nprefork maximum backoff=10",
2737 undef);
2738 unless ($env) {
2739 return undef;
2742 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2743 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2745 if (not defined($self->check_or_start($env, "prefork"))) {
2746 return undef;
2749 my $upn_array = ["$env->{REALM}.upn"];
2750 my $spn_array = ["$env->{REALM}.spn"];
2752 $self->setup_namespaces($env, $upn_array, $spn_array);
2754 return $env;
2758 # ad_dc test environment used solely to test standard process model connection
2759 # process limits. As the limit is set artificially low it should not be used
2760 # for other tests.
2761 sub setup_proclimitdc
2763 my ($self, $path) = @_;
2765 # If we didn't build with ADS, pretend this env was never available
2766 if (not $self->{target3}->have_ads()) {
2767 return "UNKNOWN";
2770 my $env = $self->provision_ad_dc($path,
2771 "proclimitdc",
2772 "PROCLIMITDOM",
2773 "proclimit.samba.example.com",
2774 undef,
2775 "max smbd processes = 20",
2776 undef);
2777 unless ($env) {
2778 return undef;
2781 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2782 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2784 if (not defined($self->check_or_start($env, "standard"))) {
2785 return undef;
2788 my $upn_array = ["$env->{REALM}.upn"];
2789 my $spn_array = ["$env->{REALM}.spn"];
2791 $self->setup_namespaces($env, $upn_array, $spn_array);
2793 return $env;
2796 # Used to test a live upgrade of the schema on a 2 DC network.
2797 sub setup_schema_dc
2799 my ($self, $path) = @_;
2801 # provision the PDC using an older base schema
2802 my $provision_args = ["--base-schema=2008_R2", "--backend-store=mdb"];
2804 my $env = $self->provision_ad_dc($path,
2805 "liveupgrade1dc",
2806 "SCHEMADOMAIN",
2807 "schema.samba.example.com",
2808 undef,
2809 "drs: max link sync = 2",
2810 $provision_args);
2811 unless ($env) {
2812 return undef;
2815 if (not defined($self->check_or_start($env, "prefork"))) {
2816 return undef;
2819 my $upn_array = ["$env->{REALM}.upn"];
2820 my $spn_array = ["$env->{REALM}.spn"];
2822 $self->setup_namespaces($env, $upn_array, $spn_array);
2824 return $env;
2827 # the second DC in the live schema upgrade pair
2828 sub setup_schema_pair_dc
2830 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
2831 my ($self, $prefix, $dcvars) = @_;
2832 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
2834 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
2835 $dcvars->{DOMAIN},
2836 $dcvars->{REALM},
2837 $dcvars->{PASSWORD},
2838 "");
2840 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2841 my $cmd_vars = $self->get_cmd_env_vars($env);
2843 my $join_cmd = $cmd_vars;
2844 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
2845 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
2846 $join_cmd .= " --backend-store=mdb";
2848 my $upgrade_cmd = $cmd_vars;
2849 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
2850 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
2852 my $repl_cmd = $cmd_vars;
2853 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
2854 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
2855 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2857 unless (system($join_cmd) == 0) {
2858 warn("Join failed\n$join_cmd");
2859 return undef;
2862 $env->{DC_SERVER} = $dcvars->{SERVER};
2863 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
2864 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
2865 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
2867 # start samba for the new DC
2868 if (not defined($self->check_or_start($env, "standard"))) {
2869 return undef;
2872 unless (system($upgrade_cmd) == 0) {
2873 warn("Schema upgrade failed\n$upgrade_cmd");
2874 return undef;
2877 unless (system($repl_cmd) == 0) {
2878 warn("Post-update schema replication failed\n$repl_cmd");
2879 return undef;
2882 return $env;
2885 # Sets up a DC that's solely used to do a domain backup from. We then use the
2886 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2887 # process will create a Samba DC that will actually start up.
2888 # We don't use the backup-DC for anything else because its domain will conflict
2889 # with the restore DC.
2890 sub setup_backupfromdc
2892 my ($self, $path) = @_;
2894 # If we didn't build with ADS, pretend this env was never available
2895 if (not $self->{target3}->have_ads()) {
2896 return "UNKNOWN";
2899 my $provision_args = ["--site=Backup-Site"];
2901 my $env = $self->provision_ad_dc($path,
2902 "backupfromdc",
2903 "BACKUPDOMAIN",
2904 "backupdom.samba.example.com",
2905 undef,
2906 "samba kcc command = /bin/true",
2907 $provision_args);
2908 unless ($env) {
2909 return undef;
2912 if (not defined($self->check_or_start($env))) {
2913 return undef;
2916 my $upn_array = ["$env->{REALM}.upn"];
2917 my $spn_array = ["$env->{REALM}.spn"];
2919 $self->setup_namespaces($env, $upn_array, $spn_array);
2921 # Set up a dangling forward link to an expunged object
2923 # We need this to ensure that the "samba-tool domain backup rename"
2924 # that is part of the creation of the labdc environment can
2925 # cope with this situation on the source DC.
2927 if (not $self->write_ldb_file("$env->{PRIVATEDIR}/sam.ldb", "
2928 dn: ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
2929 objectclass: organizationalUnit
2932 dn: cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
2933 objectclass: msExchConfigurationContainer
2936 dn: cn=linkfrom,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
2937 objectclass: msExchConfigurationContainer
2938 addressBookRoots: cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
2941 ")) {
2942 return undef;
2944 my $ldbdel = Samba::bindir_path($self, "ldbdel");
2945 my $cmd = "$ldbdel -H $env->{PRIVATEDIR}/sam.ldb cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com";
2947 unless(system($cmd) == 0) {
2948 warn("Failed to delete link target: \n$cmd");
2949 return undef;
2952 # Expunge will ensure that linkto is totally wiped from the DB
2953 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2954 $cmd = "$samba_tool domain tombstones expunge --tombstone-lifetime=0 $env->{CONFIGURATION}";
2956 unless(system($cmd) == 0) {
2957 warn("Failed to expunge link target: \n$cmd");
2958 return undef;
2960 return $env;
2963 # returns the server/user-auth params needed to run an online backup cmd
2964 sub get_backup_server_args
2966 # dcvars contains the env info for the backup DC testenv
2967 my ($self, $dcvars) = @_;
2968 my $server = $dcvars->{DC_SERVER_IP};
2969 my $server_args = "--server=$server ";
2970 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2971 $server_args .= " $dcvars->{CONFIGURATION}";
2973 return $server_args;
2976 # Creates a backup of a running testenv DC
2977 sub create_backup
2979 # note: dcvars contains the env info for the backup DC testenv
2980 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2982 # get all the env variables we pass in with the samba-tool command
2983 # Note: use the backupfrom-DC's krb5.conf to do the backup
2984 my $overwrite = undef;
2985 $overwrite->{KRB5_CONFIG} = $dcvars->{KRB5_CONFIG};
2986 my $cmd_env = $self->get_cmd_env_vars($env, $overwrite);
2988 # use samba-tool to create a backup from the 'backupfromdc' DC
2989 my $cmd = "";
2990 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2992 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2993 $cmd .= " --targetdir=$backupdir";
2995 print "Executing: $cmd\n";
2996 unless(system($cmd) == 0) {
2997 warn("Failed to create backup using: \n$cmd");
2998 return undef;
3001 # get the name of the backup file created
3002 opendir(DIR, $backupdir);
3003 my @files = grep(/\.tar/, readdir(DIR));
3004 closedir(DIR);
3006 if(scalar @files != 1) {
3007 warn("Backup file not found in directory $backupdir\n");
3008 return undef;
3010 my $backup_file = "$backupdir/$files[0]";
3011 print "Using backup file $backup_file...\n";
3013 return $backup_file;
3016 # Restores a backup-file to populate a testenv for a new DC
3017 sub restore_backup_file
3019 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
3021 # pass the restore command the testenv's smb.conf that we've already
3022 # generated. But move it to a temp-dir first, so that the restore doesn't
3023 # overwrite it
3024 my $tmpdir = File::Temp->newdir();
3025 my $tmpconf = "$tmpdir/smb.conf";
3026 my $cmd = "cp $smbconf $tmpconf";
3027 unless(system($cmd) == 0) {
3028 warn("Failed to backup smb.conf using: \n$cmd");
3029 return -1;
3032 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3033 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
3034 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
3036 print "Executing: $cmd\n";
3037 unless(system($cmd) == 0) {
3038 warn("Failed to restore backup using: \n$cmd");
3039 return -1;
3042 print "Restore complete\n";
3043 return 0
3046 # sets up the initial directory and returns the new testenv's env info
3047 # (without actually doing a 'domain join')
3048 sub prepare_dc_testenv
3050 my ($self, $prefix, $dcname, $domain, $realm,
3051 $password, $conf_options, $dnsupdate_options) = @_;
3053 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
3054 $dcname,
3055 $domain,
3056 $realm,
3057 undef,
3058 "2008",
3059 $password,
3060 undef,
3061 undef);
3063 # the restore uses a slightly different state-dir location to other testenvs
3064 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
3065 push(@{$ctx->{directories}}, "$ctx->{statedir}");
3067 # add support for sysvol/netlogon/tmp shares
3068 $ctx->{share} = "$ctx->{prefix_abs}/share";
3069 push(@{$ctx->{directories}}, "$ctx->{share}");
3070 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
3072 if (defined($dnsupdate_options)) {
3073 $ctx->{samba_dnsupdate} .= $dnsupdate_options;
3076 $ctx->{smb_conf_extra_options} = "
3077 $conf_options
3078 max xmit = 32K
3079 server max protocol = SMB2
3080 samba kcc command = /bin/true
3081 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
3083 [sysvol]
3084 path = $ctx->{statedir}/sysvol
3085 read only = no
3087 [netlogon]
3088 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
3089 read only = no
3091 [tmp]
3092 path = $ctx->{share}
3093 read only = no
3094 posix:sharedelay = 10000
3095 posix:oplocktimeout = 3
3096 posix:writetimeupdatedelay = 50000
3098 [test1]
3099 path = $ctx->{share}/test1
3100 read only = no
3101 posix:sharedelay = 100000
3102 posix:oplocktimeout = 3
3103 posix:writetimeupdatedelay = 500000
3106 my $env = $self->provision_raw_step1($ctx);
3108 return ($env, $ctx);
3112 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3113 # commands. This proves that we can backup an online DC ('backupfromdc') and
3114 # use the backup file to create a valid, working samba DC.
3115 sub setup_restoredc
3117 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3118 my ($self, $prefix, $dcvars) = @_;
3119 print "Preparing RESTORE DC...\n";
3121 # we arbitrarily designate the restored DC as having SMBv1 disabled
3122 my $extra_conf = "
3123 server min protocol = SMB2
3124 client min protocol = SMB2
3125 prefork children = 1";
3126 my $dnsupdate_options = " --use-samba-tool --no-credentials";
3128 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3129 $dcvars->{DOMAIN},
3130 $dcvars->{REALM},
3131 $dcvars->{PASSWORD},
3132 $extra_conf,
3133 $dnsupdate_options);
3135 # create a backup of the 'backupfromdc'
3136 my $backupdir = File::Temp->newdir();
3137 my $server_args = $self->get_backup_server_args($dcvars);
3138 my $backup_args = "online $server_args";
3139 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3140 $backup_args);
3141 unless($backup_file) {
3142 return undef;
3145 # restore the backup file to populate the restore-DC testenv
3146 my $restore_dir = abs_path($prefix);
3147 my $ret = $self->restore_backup_file($backup_file,
3148 "--newservername=$env->{SERVER}",
3149 $restore_dir, $env->{SERVERCONFFILE});
3150 unless ($ret == 0) {
3151 return undef;
3155 # As we create a the same domain as a clone
3156 # we need a separate resolv.conf!
3158 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
3159 $ctx->{dns_ipv4} = $ctx->{ipv4};
3160 $ctx->{dns_ipv6} = $ctx->{ipv6};
3161 Samba::mk_resolv_conf($ctx);
3162 $env->{RESOLV_CONF} = $ctx->{resolv_conf};
3164 # start samba for the restored DC
3165 if (not defined($self->check_or_start($env))) {
3166 return undef;
3169 return $env;
3172 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3173 # restore commands. This proves that we can backup and rename an online DC
3174 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3175 sub setup_renamedc
3177 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3178 my ($self, $prefix, $dcvars) = @_;
3179 print "Preparing RENAME DC...\n";
3180 my $extra_conf = "prefork children = 1";
3182 my $realm = "renamedom.samba.example.com";
3183 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3184 "RENAMEDOMAIN", $realm,
3185 $dcvars->{PASSWORD}, $extra_conf);
3187 # create a backup of the 'backupfromdc' which renames the domain
3188 my $backupdir = File::Temp->newdir();
3189 my $server_args = $self->get_backup_server_args($dcvars);
3190 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3191 $backup_args .= " --backend-store=tdb";
3192 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3193 $backup_args);
3194 unless($backup_file) {
3195 return undef;
3198 # restore the backup file to populate the rename-DC testenv
3199 my $restore_dir = abs_path($prefix);
3200 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3201 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3202 $restore_dir, $env->{SERVERCONFFILE});
3203 unless ($ret == 0) {
3204 return undef;
3207 # start samba for the restored DC
3208 if (not defined($self->check_or_start($env))) {
3209 return undef;
3212 my $upn_array = ["$env->{REALM}.upn"];
3213 my $spn_array = ["$env->{REALM}.spn"];
3215 $self->setup_namespaces($env, $upn_array, $spn_array);
3217 return $env;
3220 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3221 # restore commands. This proves that we do an offline backup of a local DC
3222 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3223 sub setup_offlinebackupdc
3225 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3226 my ($self, $prefix, $dcvars) = @_;
3227 print "Preparing OFFLINE BACKUP DC...\n";
3228 my $extra_conf = "prefork children = 1";
3229 my $dnsupdate_options = " --use-samba-tool --no-credentials";
3231 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3232 $dcvars->{DOMAIN},
3233 $dcvars->{REALM},
3234 $dcvars->{PASSWORD},
3235 $extra_conf,
3236 $dnsupdate_options);
3238 # create an offline backup of the 'backupfromdc' target
3239 my $backupdir = File::Temp->newdir();
3240 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
3241 my $backup_file = $self->create_backup($env, $dcvars,
3242 $backupdir, $cmd);
3244 unless($backup_file) {
3245 return undef;
3248 # restore the backup file to populate the rename-DC testenv
3249 my $restore_dir = abs_path($prefix);
3250 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3251 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3252 $restore_dir, $env->{SERVERCONFFILE});
3253 unless ($ret == 0) {
3254 return undef;
3258 # As we create a the same domain as a clone
3259 # we need a separate resolv.conf!
3261 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
3262 $ctx->{dns_ipv4} = $ctx->{ipv4};
3263 $ctx->{dns_ipv6} = $ctx->{ipv6};
3264 Samba::mk_resolv_conf($ctx);
3265 $env->{RESOLV_CONF} = $ctx->{resolv_conf};
3267 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3268 Samba::mk_krb5_conf($ctx);
3270 # start samba for the restored DC
3271 if (not defined($self->check_or_start($env))) {
3272 return undef;
3275 return $env;
3278 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3279 # restore commands, using the --no-secrets option. This proves that we can
3280 # create a realistic lab environment from an online DC ('backupfromdc').
3281 sub setup_labdc
3283 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3284 my ($self, $prefix, $dcvars) = @_;
3285 print "Preparing LAB-DOMAIN DC...\n";
3286 my $extra_conf = "prefork children = 1";
3288 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3289 "LABDOMAIN",
3290 "labdom.samba.example.com",
3291 $dcvars->{PASSWORD}, $extra_conf);
3293 # create a backup of the 'backupfromdc' which renames the domain and uses
3294 # the --no-secrets option to scrub any sensitive info
3295 my $backupdir = File::Temp->newdir();
3296 my $server_args = $self->get_backup_server_args($dcvars);
3297 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3298 $backup_args .= " --no-secrets --backend-store=mdb";
3299 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3300 $backup_args);
3301 unless($backup_file) {
3302 return undef;
3305 # restore the backup file to populate the lab-DC testenv
3306 my $restore_dir = abs_path($prefix);
3307 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3308 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3309 $restore_dir, $env->{SERVERCONFFILE});
3310 unless ($ret == 0) {
3311 return undef;
3314 # because we don't include any secrets in the backup, we need to reset the
3315 # admin user's password back to what the testenv expects
3316 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3317 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3318 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3319 $cmd .= " $env->{CONFIGURATION}";
3321 unless(system($cmd) == 0) {
3322 warn("Failed to reset admin's password: \n$cmd");
3323 return undef;
3326 # start samba for the restored DC
3327 if (not defined($self->check_or_start($env))) {
3328 return undef;
3331 my $upn_array = ["$env->{REALM}.upn"];
3332 my $spn_array = ["$env->{REALM}.spn"];
3334 $self->setup_namespaces($env, $upn_array, $spn_array);
3336 return $env;
3339 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3340 sub get_backup_domain_realm
3342 my ($self, $backup_file) = @_;
3344 print "Determining REALM/DOMAIN values in backup...\n";
3346 # The backup will have the correct domain/realm values in the smb.conf.
3347 # So we can work out the env variables the testenv should use based on
3348 # that. Let's start by extracting the smb.conf
3349 my $tar = Archive::Tar->new($backup_file);
3350 my $tmpdir = File::Temp->newdir();
3351 my $smbconf = "$tmpdir/smb.conf";
3353 # note that the filepaths within the tar-file differ slightly for online
3354 # and offline backups
3355 if ($tar->contains_file("etc/smb.conf")) {
3356 $tar->extract_file("etc/smb.conf", $smbconf);
3357 } elsif ($tar->contains_file("./etc/smb.conf")) {
3358 $tar->extract_file("./etc/smb.conf", $smbconf);
3359 } else {
3360 warn("Could not find smb.conf in $backup_file");
3361 return undef, undef;
3364 # make sure we don't try to create locks/sockets in the default install
3365 # location (i.e. /usr/local/samba/)
3366 my $options = "--option=\"private dir = $tmpdir\"";
3367 $options .= " --option=\"lock dir = $tmpdir\"";
3369 # now use testparm to read the values we're interested in
3370 my $testparm = Samba::bindir_path($self, "testparm");
3371 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3372 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3373 chomp $realm;
3374 chomp $domain;
3375 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3377 return ($domain, $realm);
3380 # This spins up a custom testenv that can be based on any backup-file you want.
3381 # This is just intended for manual testing (rather than automated test-cases)
3382 sub setup_customdc
3384 my ($self, $prefix) = @_;
3385 print "Preparing CUSTOM RESTORE DC...\n";
3386 my $dc_name = "customdc";
3387 my $password = "locDCpass1";
3388 my $backup_file = $ENV{'BACKUP_FILE'};
3389 my $dnsupdate_options = " --use-samba-tool --no-credentials";
3391 # user must specify a backup file to restore via an ENV variable, i.e.
3392 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3393 if (not defined($backup_file)) {
3394 warn("Please specify BACKUP_FILE");
3395 return undef;
3398 # work out the correct domain/realm env values from the backup-file
3399 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3400 if ($domain eq '' or $realm eq '') {
3401 warn("Could not determine domain or realm");
3402 return undef;
3405 # create a placeholder directory and smb.conf, as well as the env vars.
3406 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3407 $domain, $realm, $password, "",
3408 $dnsupdate_options);
3410 # restore the specified backup file to populate the testenv
3411 my $restore_dir = abs_path($prefix);
3412 my $ret = $self->restore_backup_file($backup_file,
3413 "--newservername=$env->{SERVER}",
3414 $restore_dir, $env->{SERVERCONFFILE});
3415 unless ($ret == 0) {
3416 return undef;
3420 # As we create a the same domain as a clone
3421 # we need a separate resolv.conf!
3423 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
3424 $ctx->{dns_ipv4} = $ctx->{ipv4};
3425 $ctx->{dns_ipv6} = $ctx->{ipv6};
3426 Samba::mk_resolv_conf($ctx);
3427 $env->{RESOLV_CONF} = $ctx->{resolv_conf};
3429 # Change the admin password to the testenv default, just in case it's
3430 # different, or in case this was a --no-secrets backup
3431 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3432 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3433 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3434 $cmd .= " $env->{CONFIGURATION}";
3436 unless(system($cmd) == 0) {
3437 warn("Failed to reset admin's password: \n$cmd");
3438 return undef;
3441 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3442 # if the backup-file was an offline backup)
3443 Samba::mk_krb5_conf($ctx);
3445 # start samba for the restored DC
3446 if (not defined($self->check_or_start($env))) {
3447 return undef;
3450 # if this was a backup-rename, then we may need to setup namespaces
3451 my $upn_array = ["$env->{REALM}.upn"];
3452 my $spn_array = ["$env->{REALM}.spn"];
3454 $self->setup_namespaces($env, $upn_array, $spn_array);
3456 return $env;
3459 sub setup_none
3461 my ($self, $path) = @_;
3463 my $ret = {
3464 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
3465 SAMBA_PID => -1,