Debian Codegraph @

selftest/target/Samba4.pm

raw
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <[email protected]>
4 # Published under the GNU GPL, v3 or later.
5
6 # NOTE: Refer to the README for more details about the various testenvs,
7 # and tips about adding new testenvs.
8
9 package Samba4;
10
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;
20
21 sub new($$$$$) {
22 my ($classname, $SambaCtx, $bindir, $srcdir, $server_maxtime, $default_ldb_backend) = @_;
23
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),
31 default_ldb_backend => $default_ldb_backend,
32 };
33 bless $self;
34 return $self;
35 }
36
37 sub scriptdir_path($$) {
38 my ($self, $path) = @_;
39 return "$self->{srcdir}/source4/scripting/$path";
40 }
41
42 sub check_or_start($$$)
43 {
44 my ($self, $env_vars, $process_model) = @_;
45 my $STDIN_READER;
46
47 my $env_ok = $self->check_env($env_vars);
48 if ($env_ok) {
49 return $env_vars->{SAMBA_PID};
50 } elsif (defined($env_vars->{SAMBA_PID})) {
51 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
52 return undef;
53 }
54
55 # use a pipe for stdin in the child processes. This allows
56 # those processes to monitor the pipe for EOF to ensure they
57 # exit when the test script exits
58 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
59
60 # build up the command to run samba
61 my @preargs = ();
62 my @optargs = ();
63 if (defined($ENV{SAMBA_OPTIONS})) {
64 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
65 }
66 if(defined($ENV{SAMBA_VALGRIND})) {
67 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
68 }
69
70 if (defined($process_model)) {
71 push @optargs, ("-M", $process_model);
72 }
73 my $binary = Samba::bindir_path($self, "samba");
74 my @full_cmd = (@preargs, $binary, "-i",
75 "--no-process-group", "--maximum-runtime=$self->{server_maxtime}",
76 $env_vars->{CONFIGURATION}, @optargs);
77
78 # the samba process takes some additional env variables (compared to s3)
79 my $samba_envs = Samba::get_env_for_process("samba", $env_vars);
80 if (defined($ENV{MITKRB5})) {
81 $samba_envs->{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
82 }
83
84 # fork a child process and exec() samba
85 my $daemon_ctx = {
86 NAME => "samba",
87 BINARY_PATH => $binary,
88 FULL_CMD => [ @full_cmd ],
89 LOG_FILE => $env_vars->{SAMBA_TEST_LOG},
90 TEE_STDOUT => 1,
91 PCAP_FILE => "env-$ENV{ENVNAME}-samba",
92 ENV_VARS => $samba_envs,
93 };
94 my $pid = Samba::fork_and_exec($self, $env_vars, $daemon_ctx, $STDIN_READER);
95
96 $env_vars->{SAMBA_PID} = $pid;
97
98 # close the parent's read-end of the pipe
99 close($STDIN_READER);
100
101 if ($self->wait_for_start($env_vars) != 0) {
102 warn("Samba $pid failed to start up");
103 return undef;
104 }
105
106 return $pid;
107 }
108
109 sub wait_for_start($$)
110 {
111 my ($self, $testenv_vars) = @_;
112 my $count = 0;
113 my $ret = 0;
114
115 if (not $self->check_env($testenv_vars)) {
116 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
117 return -1;
118 }
119
120 # This will return quickly when things are up, but be slow if we
121 # need to wait for (eg) SSL init
122 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
123
124 do {
125 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
126 if ($ret != 0) {
127 sleep(1);
128 } else {
129 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
130 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
131 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
132 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
133 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
134 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
135 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
136 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
137 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
138 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
139 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
140 }
141 $count++;
142 } while ($ret != 0 && $count < 20);
143 if ($count == 20) {
144 teardown_env($self, $testenv_vars);
145 warn("nbt not reachable after 20 retries\n");
146 return -1;
147 }
148
149 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
150 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
151 print "waiting for working LDAP and a RID Set to be allocated\n";
152 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
153 my $count = 0;
154 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
155
156 my $search_dn = $base_dn;
157 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
158 # TODO currently no check for actual rIDAllocationPool
159 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
160 }
161 my $max_wait = 60;
162
163 # Add hosts file for name lookups
164 my $cmd = $self->get_cmd_env_vars($testenv_vars);
165
166 $cmd .= "$ldbsearch ";
167 $cmd .= "$testenv_vars->{CONFIGURATION} ";
168 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
169 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
170 $cmd .= "--scope base ";
171 $cmd .= "-b '$search_dn' ";
172 while (system("$cmd >/dev/null") != 0) {
173 $count++;
174 if ($count > $max_wait) {
175 teardown_env($self, $testenv_vars);
176 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}");
177 return -1;
178 }
179 print "Waiting for working LDAP...\n";
180 sleep(1);
181 }
182 }
183
184 my $wbinfo = Samba::bindir_path($self, "wbinfo");
185
186 $count = 0;
187 do {
188 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
189 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
190 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
191 $cmd .= "$wbinfo -P";
192 $ret = system($cmd);
193
194 if ($ret != 0) {
195 sleep(1);
196 }
197 $count++;
198 } while ($ret != 0 && $count < 20);
199 if ($count == 20) {
200 teardown_env($self, $testenv_vars);
201 warn("winbind not reachable after 20 retries\n");
202 return -1;
203 }
204
205 # Ensure we registered all our names
206 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
207 my $max_wait = 120;
208 my $dns_update_cache = "$testenv_vars->{PRIVATEDIR}/dns_update_cache";
209 print "Waiting for $dns_update_cache to be created.\n";
210 $count = 0;
211 while (not -e $dns_update_cache) {
212 $count++;
213 if ($count > $max_wait) {
214 teardown_env($self, $testenv_vars);
215 warn("Timed out ($max_wait sec) waiting for $dns_update_cache PID $testenv_vars->{SAMBA_PID}");
216 return -1;
217 }
218 print "Waiting for $dns_update_cache to be created...\n";
219 sleep(1);
220 }
221 print "Waiting for $dns_update_cache to be filled.\n";
222 $count = 0;
223 while ((-s "$dns_update_cache") == 0) {
224 $count++;
225 if ($count > $max_wait) {
226 teardown_env($self, $testenv_vars);
227 warn("Timed out ($max_wait sec) waiting for $dns_update_cache PID $testenv_vars->{SAMBA_PID}");
228 return -1;
229 }
230 print "Waiting for $dns_update_cache to be filled...\n";
231 sleep(1);
232 }
233 }
234
235 print $self->getlog_env($testenv_vars);
236
237 print "READY ($testenv_vars->{SAMBA_PID})\n";
238
239 return 0
240 }
241
242 sub write_ldb_file($$$)
243 {
244 my ($self, $file, $ldif_in) = @_;
245
246 my $ldbadd = Samba::bindir_path($self, "ldbadd");
247 open(my $ldif, "|$ldbadd -H $file > /dev/null")
248 or die "Failed to run $ldbadd: $!";
249 print $ldif $ldif_in;
250 close($ldif);
251
252 unless ($? == 0) {
253 warn("$ldbadd failed: $?");
254 return undef;
255 }
256 return 1;
257 }
258
259 sub add_wins_config($$)
260 {
261 my ($self, $privatedir) = @_;
262 my $client_ip = Samba::get_ipv4_addr("client");
263
264 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
265 dn: name=TORTURE_11,CN=PARTNERS
266 objectClass: wreplPartner
267 name: TORTURE_11
268 address: $client_ip
269 pullInterval: 0
270 pushChangeCount: 0
271 type: 0x3
272 ");
273 }
274
275 sub setup_dns_hub_internal($$$)
276 {
277 my ($self, $hostname, $prefix) = @_;
278 my $STDIN_READER;
279
280 unless(-d $prefix or mkdir($prefix, 0777)) {
281 warn("Unable to create $prefix");
282 return undef;
283 }
284
285 die ("prefix=''") if $prefix eq "";
286 die ("prefix='/'") if $prefix eq "/";
287
288 unless (system("rm -rf $prefix/*") == 0) {
289 warn("Unable to clean up");
290 }
291
292 my $env = undef;
293 $env->{NETBIOSNAME} = $hostname;
294
295 $env->{SERVER_IP} = Samba::get_ipv4_addr($hostname);
296 $env->{SERVER_IPV6} = Samba::get_ipv6_addr($hostname);
297 $env->{SOCKET_WRAPPER_DEFAULT_IFACE} = Samba::get_interface($hostname);
298 $env->{DNS_HUB_LOG} = "$prefix/dns_hub.log";
299 $env->{RESOLV_CONF} = "$prefix/resolv.conf";
300 $env->{TESTENV_DIR} = $prefix;
301
302 my $ctx = undef;
303 $ctx->{resolv_conf} = $env->{RESOLV_CONF};
304 $ctx->{dns_ipv4} = $env->{SERVER_IP};
305 $ctx->{dns_ipv6} = $env->{SERVER_IPV6};
306 Samba::mk_resolv_conf($ctx);
307
308 my @preargs = ();
309 my @args = ();
310 if (!defined($ENV{PYTHON})) {
311 push (@preargs, "env");
312 push (@preargs, "python");
313 } else {
314 push (@preargs, $ENV{PYTHON});
315 }
316 my $binary = "$self->{srcdir}/selftest/target/dns_hub.py";
317 push (@args, "$self->{server_maxtime}");
318 push (@args, "$env->{SERVER_IP},$env->{SERVER_IPV6}");
319 push (@args, Samba::realm_to_ip_mappings());
320 my @full_cmd = (@preargs, $binary, @args);
321
322 my $daemon_ctx = {
323 NAME => "dnshub",
324 BINARY_PATH => $binary,
325 FULL_CMD => [ @full_cmd ],
326 LOG_FILE => $env->{DNS_HUB_LOG},
327 TEE_STDOUT => 1,
328 PCAP_FILE => "env-$ENV{ENVNAME}-dns_hub",
329 ENV_VARS => {},
330 };
331
332 # use a pipe for stdin in the child processes. This allows
333 # those processes to monitor the pipe for EOF to ensure they
334 # exit when the test script exits
335 pipe($STDIN_READER, $env->{STDIN_PIPE});
336
337 my $pid = Samba::fork_and_exec($self, $env, $daemon_ctx, $STDIN_READER);
338
339 $env->{SAMBA_PID} = $pid;
340 $env->{KRB5_CONFIG} = "$prefix/no_krb5.conf";
341
342 # close the parent's read-end of the pipe
343 close($STDIN_READER);
344
345 return $env;
346 }
347
348 sub setup_dns_hub
349 {
350 my ($self, $prefix) = @_;
351
352 my $hostname = "rootdnsforwarder";
353
354 unless(-d $prefix or mkdir($prefix, 0777)) {
355 warn("Unable to create $prefix");
356 return undef;
357 }
358 my $env = $self->setup_dns_hub_internal("$hostname", "$prefix/$hostname");
359
360 $self->{dns_hub_env} = $env;
361
362 return $env;
363 }
364
365 sub get_dns_hub_env($)
366 {
367 my ($self, $prefix) = @_;
368
369 if (defined($self->{dns_hub_env})) {
370 return $self->{dns_hub_env};
371 }
372
373 die("get_dns_hub_env() not setup 'dns_hub_env'");
374 return undef;
375 }
376
377 sub return_env_value
378 {
379 my ($env, $overwrite, $key) = @_;
380
381 if (defined($overwrite) and defined($overwrite->{$key})) {
382 return $overwrite->{$key};
383 }
384
385 if (defined($env->{$key})) {
386 return $env->{$key};
387 }
388
389 return undef;
390 }
391
392 # Returns the environmental variables that we pass to samba-tool commands
393 sub get_cmd_env_vars
394 {
395 my ($self, $givenenv, $overwrite) = @_;
396
397 my @keys = (
398 "NSS_WRAPPER_HOSTS",
399 "SOCKET_WRAPPER_DEFAULT_IFACE",
400 "RESOLV_CONF",
401 "RESOLV_WRAPPER_CONF",
402 "RESOLV_WRAPPER_HOSTS",
403 "GNUTLS_FORCE_FIPS_MODE",
404 "OPENSSL_FORCE_FIPS_MODE",
405 "KRB5_CONFIG",
406 "KRB5_CCACHE",
407 "GNUPGHOME",
408 );
409
410 my $localenv = undef;
411 foreach my $key (@keys) {
412 my $v = return_env_value($givenenv, $overwrite, $key);
413 $localenv->{$key} = $v if defined($v);
414 }
415
416 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
417 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
418 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
419 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
420 } else {
421 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
422 }
423 if (defined($localenv->{GNUTLS_FORCE_FIPS_MODE})) {
424 $cmd_env .= "GNUTLS_FORCE_FIPS_MODE=$localenv->{GNUTLS_FORCE_FIPS_MODE} ";
425 }
426 if (defined($localenv->{OPENSSL_FORCE_FIPS_MODE})) {
427 $cmd_env .= "OPENSSL_FORCE_FIPS_MODE=$localenv->{OPENSSL_FORCE_FIPS_MODE} ";
428 }
429 $cmd_env .= "KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
430 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
431 $cmd_env .= "RESOLV_CONF=\"$localenv->{RESOLV_CONF}\" ";
432 $cmd_env .= "GNUPGHOME=\"$localenv->{GNUPGHOME}\" ";
433
434 return $cmd_env;
435 }
436
437 # Sets up a forest trust namespace.
438 # (Note this is different to kernel namespaces, setup by the
439 # USE_NAMESPACES=1 option)
440 sub setup_namespaces
441 {
442 my ($self, $localenv, $upn_array, $spn_array) = @_;
443
444 @{$upn_array} = [] unless defined($upn_array);
445 my $upn_args = "";
446 foreach my $upn (@{$upn_array}) {
447 $upn_args .= " --add-upn-suffix=$upn";
448 }
449
450 @{$spn_array} = [] unless defined($spn_array);
451 my $spn_args = "";
452 foreach my $spn (@{$spn_array}) {
453 $spn_args .= " --add-spn-suffix=$spn";
454 }
455
456 my $samba_tool = Samba::bindir_path($self, "samba-tool");
457
458 my $cmd_env = $self->get_cmd_env_vars($localenv);
459
460 my $cmd_config = " $localenv->{CONFIGURATION}";
461
462 my $namespaces = $cmd_env;
463 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
464 $namespaces .= $cmd_config;
465 unless (system($namespaces) == 0) {
466 warn("Failed to add namespaces \n$namespaces");
467 return -1;
468 }
469
470 return 0;
471 }
472
473 sub setup_trust($$$$$)
474 {
475 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
476
477 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
478 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
479 $localenv->{TRUST_DNSNAME} = $remoteenv->{DNSNAME};
480
481 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
482 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
483 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
484 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
485 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
486
487 # Add trusted domain realms to krb5.conf
488 Samba::append_krb5_conf_trust_realms($localenv);
489
490 my $samba_tool = Samba::bindir_path($self, "samba-tool");
491
492 # setup the trust
493 my $cmd_env = $self->get_cmd_env_vars($localenv);
494
495 my $cmd_config = " $localenv->{CONFIGURATION}";
496 my $cmd_creds = $cmd_config;
497 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
498
499 my $create = $cmd_env;
500 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
501 $create .= " $extra_args";
502 $create .= $cmd_creds;
503 unless (system($create) == 0) {
504 warn("Failed to create trust \n$create");
505 return undef;
506 }
507
508 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
509 my $groupadd = $cmd_env;
510 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
511 unless (system($groupadd) == 0) {
512 warn("Failed to create group \n$groupadd");
513 return undef;
514 }
515 my $groupmem = $cmd_env;
516 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
517 unless (system($groupmem) == 0) {
518 warn("Failed to add group member \n$groupmem");
519 return undef;
520 }
521
522 return $localenv
523 }
524
525 sub provision_raw_prepare($$$$$$$$$$$$$$)
526 {
527 my ($self,
528 $prefix,
529 $server_role,
530 $hostname,
531 $domain,
532 $realm,
533 $samsid,
534 $functional_level,
535 $password,
536 $kdc_ipv4,
537 $kdc_ipv6,
538 $force_fips_mode,
539 $extra_provision_options) = @_;
540 my $ctx;
541 my $python_cmd = "";
542 if (defined $ENV{PYTHON}) {
543 $python_cmd = $ENV{PYTHON} . " ";
544 }
545 $ctx->{python} = $python_cmd;
546 my $netbiosname = uc($hostname);
547
548 unless(-d $prefix or mkdir($prefix, 0777)) {
549 warn("Unable to create $prefix");
550 return undef;
551 }
552
553 die ("prefix=''") if $prefix eq "";
554 die ("prefix='/'") if $prefix eq "/";
555
556 unless (system("rm -rf $prefix/*") == 0) {
557 warn("Unable to clean up");
558 }
559
560
561 my $swiface = Samba::get_interface($hostname);
562
563 $ctx->{prefix} = $prefix;
564 $ctx->{server_role} = $server_role;
565 $ctx->{hostname} = $hostname;
566 $ctx->{netbiosname} = $netbiosname;
567 $ctx->{swiface} = $swiface;
568 $ctx->{password} = $password;
569 $ctx->{kdc_ipv4} = $kdc_ipv4;
570 $ctx->{kdc_ipv6} = $kdc_ipv6;
571 $ctx->{force_fips_mode} = $force_fips_mode;
572 $ctx->{krb5_ccname} = "$prefix/krb5cc_%{uid}";
573 if ($functional_level eq "2000") {
574 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc";
575 }
576
577 #
578 # Set smbd log level here.
579 #
580 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
581 $ctx->{username} = "Administrator";
582 $ctx->{domain} = $domain;
583 $ctx->{realm} = uc($realm);
584 $ctx->{dnsname} = lc($realm);
585 $ctx->{samsid} = $samsid;
586 $ctx->{domain_admin} = "Administrator";
587 $ctx->{domain_admin_password} = $password;
588 $ctx->{domain_user} = "alice";
589 $ctx->{domain_user_password} = "Secret007";
590
591 $ctx->{functional_level} = $functional_level;
592
593 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
594 chomp $unix_name;
595 $ctx->{unix_name} = $unix_name;
596 $ctx->{unix_uid} = $>;
597 my @mygid = split(" ", $();
598 $ctx->{unix_gid} = $mygid[0];
599 $ctx->{unix_gids_str} = $);
600 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
601
602 $ctx->{etcdir} = "$prefix/etc";
603 $ctx->{piddir} = "$prefix/pid";
604 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
605 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
606 $ctx->{krb5_ccache} = "$prefix/krb5_ccache";
607 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
608 $ctx->{gnupghome} = "$prefix/gnupg";
609 $ctx->{privatedir} = "$prefix/private";
610 $ctx->{binddnsdir} = "$prefix/bind-dns";
611 $ctx->{ncalrpcdir} = "$prefix/ncalrpc";
612 $ctx->{lockdir} = "$prefix/lockdir";
613 $ctx->{logdir} = "$prefix/logs";
614 $ctx->{statedir} = "$prefix/statedir";
615 $ctx->{cachedir} = "$prefix/cachedir";
616 $ctx->{winbindd_socket_dir} = "$prefix/wbsock";
617 $ctx->{nmbd_socket_dir} = "$prefix/nmbsock";
618 $ctx->{ntp_signd_socket_dir} = "$prefix/ntp_signd_socket";
619 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
620 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
621 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
622 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
623 if ($ENV{SAMBA_DNS_FAKING}) {
624 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
625 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --configfile=$ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
626 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
627 } else {
628 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --configfile=$ctx->{smb_conf} --all-interfaces";
629 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
630 $ctx->{use_resolv_wrapper} = 1;
631 }
632
633 my $dns_hub = $self->get_dns_hub_env();
634 $ctx->{resolv_conf} = $dns_hub->{RESOLV_CONF};
635
636 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
637
638 $ctx->{ipv4} = Samba::get_ipv4_addr($hostname);
639 $ctx->{ipv6} = Samba::get_ipv6_addr($hostname);
640
641 push(@{$ctx->{directories}}, $ctx->{privatedir});
642 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
643 push(@{$ctx->{directories}}, $ctx->{etcdir});
644 push(@{$ctx->{directories}}, $ctx->{piddir});
645 push(@{$ctx->{directories}}, $ctx->{lockdir});
646 push(@{$ctx->{directories}}, $ctx->{logdir});
647 push(@{$ctx->{directories}}, $ctx->{statedir});
648 push(@{$ctx->{directories}}, $ctx->{cachedir});
649
650 $ctx->{smb_conf_extra_options} = "";
651
652 my @provision_options = ();
653 push (@provision_options, "GNUPGHOME=\"$ctx->{gnupghome}\"");
654 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
655 push (@provision_options, "KRB5CCNAME=\"$ctx->{krb5_ccache}\"");
656 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
657 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
658 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
659 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
660 if (defined($ctx->{use_resolv_wrapper})) {
661 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
662 push (@provision_options, "RESOLV_CONF=\"$ctx->{resolv_conf}\"");
663 } else {
664 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
665 }
666 if (defined($ctx->{force_fips_mode})) {
667 push (@provision_options, "GNUTLS_FORCE_FIPS_MODE=1");
668 push (@provision_options, "OPENSSL_FORCE_FIPS_MODE=1");
669 }
670
671 if (defined($ENV{GDB_PROVISION}) ||
672 defined($ENV{RR_PROVISION}) ||
673 defined($ENV{PY_DEV_PROVISION}) ||
674 defined($ENV{VALGRIND_PROVISION})) {
675 if (defined($ENV{GDB_PROVISION})) {
676 push (@provision_options, "gdb --args");
677 }
678 if (defined($ENV{RR_PROVISION})) {
679 push (@provision_options, "rr");
680 }
681 if (defined($ENV{VALGRIND_PROVISION})) {
682 push (@provision_options, "valgrind");
683 }
684 if (!defined($ENV{PYTHON})) {
685 push (@provision_options, "env");
686 push (@provision_options, "python");
687 }
688 if (defined($ENV{PY_DEV_PROVISION})) {
689 # makes Python more likely to emit warnings
690 # and debug info.
691 push (@provision_options, "-X dev");
692 }
693 }
694
695 my $samba_tool = Samba::bindir_path($self, "samba-tool");
696
697 push (@provision_options, $samba_tool);
698 push (@provision_options, "domain");
699 push (@provision_options, "provision");
700 push (@provision_options, "--configfile=$ctx->{smb_conf}");
701 push (@provision_options, "--host-name=$ctx->{hostname}");
702 push (@provision_options, "--host-ip=$ctx->{ipv4}");
703 push (@provision_options, "--quiet");
704 push (@provision_options, "--domain=$ctx->{domain}");
705 push (@provision_options, "--realm=$ctx->{realm}");
706 if (defined($ctx->{samsid})) {
707 push (@provision_options, "--domain-sid=$ctx->{samsid}");
708 }
709 push (@provision_options, "--adminpass=$ctx->{password}");
710 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
711 push (@provision_options, "--machinepass=machine$ctx->{password}");
712 push (@provision_options, "--root=$ctx->{unix_name}");
713 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
714 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
715
716 @{$ctx->{provision_options}} = @provision_options;
717
718 if (defined($extra_provision_options)) {
719 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
720 }
721
722 return $ctx;
723 }
724
725 sub has_option
726 {
727 my ($self, $keyword, @options_list) = @_;
728
729 # convert the options-list to a hash-map for easy keyword lookup
730 my %options_dict = map { $_ => 1 } @options_list;
731
732 return exists $options_dict{$keyword};
733 }
734
735 #
736 # Step1 creates the basic configuration
737 #
738 sub provision_raw_step1($$)
739 {
740 my ($self, $ctx) = @_;
741
742 mkdir($_, 0777) foreach (@{$ctx->{directories}});
743
744 ##
745 ## lockdir and piddir must be 0755
746 ##
747 chmod 0755, $ctx->{lockdir};
748 chmod 0755, $ctx->{piddir};
749
750 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
751 warn("can't open $ctx->{smb_conf}$?");
752 return undef;
753 }
754
755 Samba::copy_gnupg_home($ctx);
756 Samba::prepare_keyblobs($ctx);
757 my $crlfile = "$ctx->{tlsdir}/crl.pem";
758 $crlfile = "" unless -e ${crlfile};
759
760 # work out which file server to use. Default to source3 smbd (s3fs),
761 # unless the source4 NTVFS (smb) file server has been specified
762 my $services = "-smb +s3fs";
763 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
764 $services = "+smb -s3fs";
765 }
766
767 my $interfaces = Samba::get_interfaces_config($ctx->{netbiosname});
768
769 print CONFFILE "
770 [global]
771 netbios name = $ctx->{netbiosname}
772 posix:eadb = $ctx->{statedir}/eadb.tdb
773 workgroup = $ctx->{domain}
774 realm = $ctx->{realm}
775 private dir = $ctx->{privatedir}
776 binddns dir = $ctx->{binddnsdir}
777 pid directory = $ctx->{piddir}
778 ncalrpc dir = $ctx->{ncalrpcdir}
779 lock dir = $ctx->{lockdir}
780 state directory = $ctx->{statedir}
781 cache directory = $ctx->{cachedir}
782 winbindd socket directory = $ctx->{winbindd_socket_dir}
783 nmbd:socket dir = $ctx->{nmbd_socket_dir}
784 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
785 winbind separator = /
786 interfaces = $interfaces
787 tls dh params file = $ctx->{tlsdir}/dhparms.pem
788 tls crlfile = ${crlfile}
789 tls verify peer = no_check
790 panic action = $RealBin/gdb_backtrace \%d
791 smbd:suicide mode = yes
792 smbd:FSCTL_SMBTORTURE = yes
793 smbd:validate_oplock_types = yes
794 wins support = yes
795 server role = $ctx->{server_role}
796 server services = +echo $services
797 dcerpc endpoint servers = +winreg +srvsvc +rpcecho
798 notify:inotify = false
799 ldb:nosync = true
800 ldap server require strong auth = yes
801 log file = $ctx->{logdir}/log.\%m
802 log level = $ctx->{server_loglevel}
803 lanman auth = Yes
804 ntlm auth = Yes
805 client min protocol = SMB2_02
806 server min protocol = SMB2_02
807 mangled names = yes
808 dns update command = $ctx->{samba_dnsupdate}
809 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate --configfile $ctx->{smb_conf}
810 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate --configfile $ctx->{smb_conf} --target=Computer
811 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
812 dreplsrv:periodic_startup_interval = 0
813 dsdb:schema update allowed = yes
814
815 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
816
817 idmap_ldb:use rfc2307=yes
818 winbind enum users = yes
819 winbind enum groups = yes
820 winbind expand groups = 1
821
822 winbind varlink : socket directory = $ctx->{winbindd_socket_dir}
823 winbind varlink : service name = org.samba.selftest
824
825 rpc server port:netlogon = 1026
826 include system krb5 conf = no
827
828 debug syslog format = always
829 debug hires timestamp = yes
830
831 ";
832
833 print CONFFILE "
834
835 # Begin extra options
836 $ctx->{smb_conf_extra_options}
837 # End extra options
838 ";
839 close(CONFFILE);
840
841 #Default the KDC IP to the server's IP
842 if (not defined($ctx->{kdc_ipv4})) {
843 $ctx->{kdc_ipv4} = $ctx->{ipv4};
844 }
845 if (not defined($ctx->{kdc_ipv6})) {
846 $ctx->{kdc_ipv6} = $ctx->{ipv6};
847 }
848
849 Samba::mk_krb5_conf($ctx);
850 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
851
852 open(PWD, ">$ctx->{nsswrap_passwd}");
853 if ($ctx->{unix_uid} != 0) {
854 print PWD "root:x:0:0:root gecos:$ctx->{prefix}:/bin/false\n";
855 }
856 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix}:/bin/false\n";
857 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix}:/bin/false
858 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix}:/bin/false
859 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix}:/bin/false
860 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix}:/bin/false
861 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix}:/bin/false
862 ";
863 close(PWD);
864 my $uid_rfc2307test = 65533;
865
866 open(GRP, ">$ctx->{nsswrap_group}");
867 if ($ctx->{unix_gid} != 0) {
868 print GRP "root:x:0:\n";
869 }
870 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
871 print GRP "wheel:x:10:
872 users:x:65531:
873 nobody:x:65533:
874 nogroup:x:65534:nobody
875 ";
876 close(GRP);
877 my $gid_rfc2307test = 65532;
878
879 my $hostname = lc($ctx->{hostname});
880 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
881 if ($hostname eq "localdc" || $hostname eq "localvampiredc") {
882 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
883 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
884 } else {
885 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
886 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
887 }
888 close(HOSTS);
889
890 my $configuration = "--configfile=$ctx->{smb_conf}";
891
892 #Ensure the config file is valid before we start
893 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
894 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
895 system("$testparm -v --suppress-prompt $configuration >&2");
896 warn("Failed to create a valid smb.conf configuration $testparm!");
897 return undef;
898 }
899 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) {
900 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
901 return undef;
902 }
903
904 # Return the environment variables for the new testenv DC.
905 # Note that we have SERVER_X and DC_SERVER_X variables (which have the same
906 # value initially). In a 2 DC setup, $DC_SERVER_X will always be the PDC.
907 my $ret = {
908 GNUPGHOME => $ctx->{gnupghome},
909 KRB5_CONFIG => $ctx->{krb5_conf},
910 KRB5_CCACHE => $ctx->{krb5_ccache},
911 MITKDC_CONFIG => $ctx->{mitkdc_conf},
912 PIDDIR => $ctx->{piddir},
913 SERVER => $ctx->{hostname},
914 DC_SERVER => $ctx->{hostname},
915 SERVER_IP => $ctx->{ipv4},
916 DC_SERVER_IP => $ctx->{ipv4},
917 SERVER_IPV6 => $ctx->{ipv6},
918 DC_SERVER_IPV6 => $ctx->{ipv6},
919 NETBIOSNAME => $ctx->{netbiosname},
920 DC_NETBIOSNAME => $ctx->{netbiosname},
921 DOMAIN => $ctx->{domain},
922 USERNAME => $ctx->{username},
923 DC_USERNAME => $ctx->{username},
924 DOMAIN_ADMIN => $ctx->{domain_admin},
925 DOMAIN_ADMIN_PASSWORD => $ctx->{domain_admin_password},
926 DOMAIN_USER => $ctx->{domain_user},
927 DOMAIN_USER_PASSWORD => $ctx->{domain_user_password},
928 REALM => $ctx->{realm},
929 DNSNAME => $ctx->{dnsname},
930 SAMSID => $ctx->{samsid},
931 PASSWORD => $ctx->{password},
932 DC_PASSWORD => $ctx->{password},
933 LDAPDIR => $ctx->{ldapdir},
934 LDAP_INSTANCE => $ctx->{ldap_instance},
935 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
936 NCALRPCDIR => $ctx->{ncalrpcdir},
937 LOCKDIR => $ctx->{lockdir},
938 STATEDIR => $ctx->{statedir},
939 CACHEDIR => $ctx->{cachedir},
940 PRIVATEDIR => $ctx->{privatedir},
941 BINDDNSDIR => $ctx->{binddnsdir},
942 SERVERCONFFILE => $ctx->{smb_conf},
943 TESTENV_DIR => $ctx->{prefix},
944 CONFIGURATION => $configuration,
945 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
946 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
947 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
948 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
949 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
950 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
951 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
952 SAMBA_TEST_LOG_POS => 0,
953 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
954 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
955 LOCAL_PATH => $ctx->{share},
956 UID_RFC2307TEST => $uid_rfc2307test,
957 GID_RFC2307TEST => $gid_rfc2307test,
958 SERVER_ROLE => $ctx->{server_role},
959 RESOLV_CONF => $ctx->{resolv_conf},
960 KRB5_CRL_FILE => $crlfile,
961 };
962
963 if (defined($ctx->{use_resolv_wrapper})) {
964 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
965 } else {
966 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
967 }
968 if (defined($ctx->{force_fips_mode})) {
969 $ret->{GNUTLS_FORCE_FIPS_MODE} = "1",
970 $ret->{OPENSSL_FORCE_FIPS_MODE} = "1",
971 }
972
973 if ($ctx->{server_role} eq "domain controller") {
974 $ret->{DOMSID} = $ret->{SAMSID};
975 }
976
977 return $ret;
978 }
979
980 #
981 # Step2 runs the provision script
982 #
983 sub provision_raw_step2($$$)
984 {
985 my ($self, $ctx, $ret) = @_;
986
987 my $ldif;
988
989 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
990 unless (system($provision_cmd) == 0) {
991 warn("Unable to provision: \n$provision_cmd\n");
992 return undef;
993 }
994
995 my $cmd_env = $self->get_cmd_env_vars($ret);
996
997 my $testallowed_account = "testallowed account";
998 my $samba_tool_cmd = ${cmd_env};
999 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1000 . " user create --configfile=$ctx->{smb_conf} '$testallowed_account' $ctx->{password}";
1001 unless (system($samba_tool_cmd) == 0) {
1002 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
1003 return undef;
1004 }
1005
1006 my $srv_account = "srv_account";
1007 $samba_tool_cmd = ${cmd_env};
1008 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1009 . " user create --configfile=$ctx->{smb_conf} $srv_account $ctx->{password}";
1010 unless (system($samba_tool_cmd) == 0) {
1011 warn("Unable to add $srv_account user: \n$samba_tool_cmd\n");
1012 return undef;
1013 }
1014
1015 $samba_tool_cmd = ${cmd_env};
1016 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1017 . " spn add HOST/$srv_account --configfile=$ctx->{smb_conf} $srv_account";
1018 unless (system($samba_tool_cmd) == 0) {
1019 warn("Unable to add spn for $srv_account: \n$samba_tool_cmd\n");
1020 return undef;
1021 }
1022
1023 my $ldbmodify = ${cmd_env};
1024 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
1025 $ldbmodify .= " --configfile=$ctx->{smb_conf}";
1026 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
1027
1028 if ($ctx->{server_role} ne "domain controller") {
1029 $base_dn = "DC=$ctx->{netbiosname}";
1030 }
1031
1032 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
1033 open($ldif, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb")
1034 or die "Failed to run $ldbmodify: $!";
1035 print $ldif "dn: $user_dn
1036 changetype: modify
1037 replace: userPrincipalName
1038 userPrincipalName: testallowed upn\@$ctx->{realm}
1039 replace: servicePrincipalName
1040 servicePrincipalName: host/testallowed
1041 -
1042 ";
1043 close($ldif);
1044 unless ($? == 0) {
1045 warn("$ldbmodify failed: $?");
1046 return undef;
1047 }
1048
1049 $samba_tool_cmd = ${cmd_env};
1050 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1051 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
1052 unless (system($samba_tool_cmd) == 0) {
1053 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
1054 return undef;
1055 }
1056
1057 $user_dn = "cn=testdenied,cn=users,$base_dn";
1058 open($ldif, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb")
1059 or die "Failed to run $ldbmodify: $!";
1060 print $ldif "dn: $user_dn
1061 changetype: modify
1062 replace: userPrincipalName
1063 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
1064 -
1065 ";
1066 close($ldif);
1067 unless ($? == 0) {
1068 warn("$ldbmodify failed: $?");
1069 return undef;
1070 }
1071
1072 $samba_tool_cmd = ${cmd_env};
1073 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1074 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
1075 unless (system($samba_tool_cmd) == 0) {
1076 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
1077 return undef;
1078 }
1079
1080 $user_dn = "cn=testupnspn,cn=users,$base_dn";
1081 open($ldif, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb")
1082 or die "Failed to run $ldbmodify: $!";
1083 print $ldif "dn: $user_dn
1084 changetype: modify
1085 replace: userPrincipalName
1086 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
1087 replace: servicePrincipalName
1088 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
1089 -
1090 ";
1091 close($ldif);
1092 unless ($? == 0) {
1093 warn("$ldbmodify failed: $?");
1094 return undef;
1095 }
1096
1097 $samba_tool_cmd = ${cmd_env};
1098 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1099 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
1100 unless (system($samba_tool_cmd) == 0) {
1101 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
1102 return undef;
1103 }
1104
1105 # Create two users alice and bob!
1106 my $user_account_array = ["alice", "bob", "jane", "joe"];
1107
1108 foreach my $user_account (@{$user_account_array}) {
1109 my $samba_tool_cmd = ${cmd_env};
1110
1111 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1112 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
1113 unless (system($samba_tool_cmd) == 0) {
1114 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
1115 return undef;
1116 }
1117 }
1118
1119 my $group_array = ["Samba Users"];
1120
1121 foreach my $group (@{$group_array}) {
1122 my $samba_tool_cmd = ${cmd_env};
1123
1124 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1125 . " group add --configfile=$ctx->{smb_conf} \"$group\"";
1126 unless (system($samba_tool_cmd) == 0) {
1127 warn("Unable to create group: $group\n$samba_tool_cmd\n");
1128 return undef;
1129 }
1130 }
1131
1132 # Add user joe to group "Samba Users"
1133 my $group = "Samba Users";
1134 my $user_account = "joe";
1135
1136 $samba_tool_cmd = ${cmd_env};
1137 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1138 . " group addmembers --configfile=$ctx->{smb_conf} \"$group\" $user_account";
1139 unless (system($samba_tool_cmd) == 0) {
1140 warn("Unable to add " . $user_account . "to group group : $group\n$samba_tool_cmd\n");
1141 return undef;
1142 }
1143
1144 $group = "Samba Users";
1145 $user_account = "joe";
1146
1147 $samba_tool_cmd = ${cmd_env};
1148 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
1149 . " user setprimarygroup --configfile=$ctx->{smb_conf} $user_account \"$group\"";
1150 unless (system($samba_tool_cmd) == 0) {
1151 warn("Unable to set primary group of user: $user_account\n$samba_tool_cmd\n");
1152 return undef;
1153 }
1154
1155 # Change the userPrincipalName for jane
1156 $user_dn = "cn=jane,cn=users,$base_dn";
1157
1158 open($ldif, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb")
1159 or die "Failed to run $ldbmodify: $!";
1160 print $ldif "dn: $user_dn
1161 changetype: modify
1162 replace: userPrincipalName
1163 userPrincipalName: jane.doe\@$ctx->{realm}
1164 -
1165 ";
1166 close($ldif);
1167 unless ($? == 0) {
1168 warn("$ldbmodify failed: $?");
1169 return undef;
1170 }
1171
1172 return $ret;
1173 }
1174
1175 sub provision($$$$$$$$$$$)
1176 {
1177 my ($self,
1178 $prefix,
1179 $server_role,
1180 $hostname,
1181 $domain,
1182 $realm,
1183 $functional_level,
1184 $password,
1185 $kdc_ipv4,
1186 $kdc_ipv6,
1187 $force_fips_mode,
1188 $extra_smbconf_options,
1189 $extra_smbconf_shares,
1190 $extra_provision_options) = @_;
1191
1192 my $samsid = Samba::random_domain_sid();
1193
1194 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
1195 $hostname,
1196 $domain, $realm,
1197 $samsid,
1198 $functional_level,
1199 $password,
1200 $kdc_ipv4,
1201 $kdc_ipv6,
1202 $force_fips_mode,
1203 $extra_provision_options);
1204
1205 $ctx->{share} = "$ctx->{prefix}/share";
1206 push(@{$ctx->{directories}}, "$ctx->{share}");
1207 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
1208 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
1209
1210 # precreate directories for printer drivers
1211 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
1212 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
1213 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
1214
1215 my $msdfs = "no";
1216 $msdfs = "yes" if ($server_role eq "domain controller");
1217 $ctx->{smb_conf_extra_options} = "
1218
1219 max xmit = 32K
1220 server max protocol = SMB2
1221 host msdfs = $msdfs
1222 lanman auth = yes
1223
1224 # fruit:copyfile is a global option
1225 fruit:copyfile = yes
1226
1227 $extra_smbconf_options
1228
1229 [tmp]
1230 path = $ctx->{share}
1231 read only = no
1232 posix:sharedelay = 100000
1233 posix:oplocktimeout = 3
1234 posix:writetimeupdatedelay = 500000
1235
1236 [xcopy_share]
1237 path = $ctx->{share}
1238 read only = no
1239 posix:sharedelay = 100000
1240 posix:oplocktimeout = 3
1241 posix:writetimeupdatedelay = 500000
1242 create mask = 777
1243 force create mode = 777
1244
1245 [posix_share]
1246 path = $ctx->{share}
1247 read only = no
1248 create mask = 0777
1249 force create mode = 0
1250 directory mask = 0777
1251 force directory mode = 0
1252
1253 [test1]
1254 path = $ctx->{share}/test1
1255 read only = no
1256 posix:sharedelay = 100000
1257 posix:oplocktimeout = 3
1258 posix:writetimeupdatedelay = 500000
1259
1260 [test2]
1261 path = $ctx->{share}/test2
1262 read only = no
1263 posix:sharedelay = 100000
1264 posix:oplocktimeout = 3
1265 posix:writetimeupdatedelay = 500000
1266
1267 [cifs]
1268 path = $ctx->{share}/_ignore_cifs_
1269 read only = no
1270 ntvfs handler = cifs
1271 cifs:server = $ctx->{netbiosname}
1272 cifs:share = tmp
1273 cifs:use-s4u2proxy = yes
1274 # There is no username specified here, instead the client is expected
1275 # to log in with kerberos, and the serverwill use delegated credentials.
1276 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1277
1278 [simple]
1279 path = $ctx->{share}
1280 read only = no
1281 ntvfs handler = simple
1282
1283 [sysvol]
1284 path = $ctx->{statedir}/sysvol
1285 read only = no
1286
1287 [netlogon]
1288 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1289 read only = no
1290
1291 [cifsposix]
1292 copy = simple
1293 ntvfs handler = cifsposix
1294
1295 [vfs_fruit]
1296 path = $ctx->{share}
1297 vfs objects = catia fruit streams_xattr acl_xattr
1298 ea support = yes
1299 fruit:resource = file
1300 fruit:metadata = netatalk
1301 fruit:locking = netatalk
1302 fruit:encoding = native
1303
1304 [xattr]
1305 path = $ctx->{share}
1306 # This can be used for testing real fs xattr stuff
1307 vfs objects = streams_xattr acl_xattr
1308
1309 $extra_smbconf_shares
1310 ";
1311
1312 my $ret = $self->provision_raw_step1($ctx);
1313 unless (defined $ret) {
1314 return undef;
1315 }
1316
1317 return $self->provision_raw_step2($ctx, $ret);
1318 }
1319
1320 # For multi-DC testenvs, we want $DC_SERVER to always be the PDC (i.e. the
1321 # original DC) in the testenv. $SERVER is always the joined DC that we are
1322 # actually running the test against
1323 sub set_pdc_env_vars
1324 {
1325 my ($self, $env, $dcvars) = @_;
1326
1327 $env->{DC_SERVER} = $dcvars->{DC_SERVER};
1328 $env->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1329 $env->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1330 $env->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
1331 $env->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1332 $env->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1333 $env->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1334 }
1335
1336 sub provision_s4member($$$$$)
1337 {
1338 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1339 print "PROVISIONING MEMBER...\n";
1340 my $extra_smb_conf = "
1341 passdb backend = samba_dsdb
1342 winbindd:use external pipes = true
1343
1344 # the source4 smb server doesn't allow signing by default
1345 server signing = enabled
1346 raw NTLMv2 auth = yes
1347
1348 # override the new SMB2 only default
1349 client min protocol = CORE
1350 server min protocol = LANMAN1
1351 ";
1352 if ($more_conf) {
1353 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1354 }
1355 my $extra_provision_options = ["--use-ntvfs"];
1356 my $ret = $self->provision($prefix,
1357 "member server",
1358 $hostname,
1359 $dcvars->{DOMAIN},
1360 $dcvars->{REALM},
1361 "2008",
1362 "locMEMpass3",
1363 $dcvars->{SERVER_IP},
1364 $dcvars->{SERVER_IPV6},
1365 undef,
1366 $extra_smb_conf, "",
1367 $extra_provision_options);
1368 unless ($ret) {
1369 return undef;
1370 }
1371
1372 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1373 my $cmd = $self->get_cmd_env_vars($ret);
1374 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} --experimental-s4-member member";
1375 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1376 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1377
1378 unless (system($cmd) == 0) {
1379 warn("Join failed\n$cmd");
1380 return undef;
1381 }
1382
1383 $ret->{DOMSID} = $dcvars->{DOMSID};
1384 $self->set_pdc_env_vars($ret, $dcvars);
1385
1386 return $ret;
1387 }
1388
1389 sub provision_rpc_proxy($$$)
1390 {
1391 my ($self, $prefix, $dcvars) = @_;
1392 print "PROVISIONING RPC PROXY...\n";
1393
1394 my $extra_smbconf_options = "
1395 passdb backend = samba_dsdb
1396
1397 # rpc_proxy
1398 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1399 dcerpc endpoint servers = epmapper, remote
1400 dcerpc_remote:interfaces = rpcecho
1401 dcerpc_remote:allow_anonymous_fallback = yes
1402 # override the new SMB2 only default
1403 client min protocol = CORE
1404 server min protocol = LANMAN1
1405 [cifs_to_dc]
1406 path = /tmp/_ignore_cifs_to_dc_/_none_
1407 read only = no
1408 ntvfs handler = cifs
1409 cifs:server = $dcvars->{SERVER}
1410 cifs:share = cifs
1411 cifs:use-s4u2proxy = yes
1412 # There is no username specified here, instead the client is expected
1413 # to log in with kerberos, and the serverwill use delegated credentials.
1414 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1415
1416 ";
1417
1418 my $extra_provision_options = ["--use-ntvfs"];
1419 my $ret = $self->provision($prefix,
1420 "member server",
1421 "localrpcproxy",
1422 $dcvars->{DOMAIN},
1423 $dcvars->{REALM},
1424 "2008",
1425 "locRPCproxypass4",
1426 $dcvars->{SERVER_IP},
1427 $dcvars->{SERVER_IPV6},
1428 undef,
1429 $extra_smbconf_options, "",
1430 $extra_provision_options);
1431 unless ($ret) {
1432 return undef;
1433 }
1434
1435 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1436
1437 # The joind runs in the context of the rpc_proxy/member for now
1438 my $cmd = $self->get_cmd_env_vars($ret);
1439 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} --experimental-s4-member member";
1440 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1441 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1442
1443 unless (system($cmd) == 0) {
1444 warn("Join failed\n$cmd");
1445 return undef;
1446 }
1447
1448 # Prepare a context of the DC, but using the local CCACHE.
1449 my $overwrite = undef;
1450 $overwrite->{KRB5_CCACHE} = $ret->{KRB5_CCACHE};
1451 my $dc_cmd_env = $self->get_cmd_env_vars($dcvars, $overwrite);
1452
1453 # Setting up delegation runs in the context of the DC for now
1454 $cmd = $dc_cmd_env;
1455 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1456 $cmd .= " $dcvars->{CONFIGURATION}";
1457 print $cmd;
1458
1459 unless (system($cmd) == 0) {
1460 warn("Delegation failed\n$cmd");
1461 return undef;
1462 }
1463
1464 # Setting up delegation runs in the context of the DC for now
1465 $cmd = $dc_cmd_env;
1466 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1467 $cmd .= " $dcvars->{CONFIGURATION}";
1468
1469 unless (system($cmd) == 0) {
1470 warn("Delegation failed\n$cmd");
1471 return undef;
1472 }
1473
1474 $ret->{DOMSID} = $dcvars->{DOMSID};
1475 $self->set_pdc_env_vars($ret, $dcvars);
1476
1477 return $ret;
1478 }
1479
1480 sub provision_promoted_dc($$$)
1481 {
1482 my ($self, $prefix, $dcvars) = @_;
1483 print "PROVISIONING PROMOTED DC...\n";
1484
1485 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1486 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1487 "promotedvdc",
1488 $dcvars->{DOMAIN},
1489 $dcvars->{REALM},
1490 $dcvars->{SAMSID},
1491 "2008",
1492 $dcvars->{PASSWORD},
1493 $dcvars->{SERVER_IP},
1494 $dcvars->{SERVER_IPV6});
1495
1496 $ctx->{smb_conf_extra_options} = "
1497 max xmit = 32K
1498 server max protocol = SMB2
1499
1500 ntlm auth = ntlmv2-only
1501
1502 kdc force enable rc4 weak session keys = yes
1503
1504 [sysvol]
1505 path = $ctx->{statedir}/sysvol
1506 read only = yes
1507
1508 [netlogon]
1509 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1510 read only = no
1511
1512 ";
1513
1514 my $ret = $self->provision_raw_step1($ctx);
1515 unless ($ret) {
1516 return undef;
1517 }
1518
1519 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1520 my $cmd = $self->get_cmd_env_vars($ret);
1521 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} --experimental-s4-member MEMBER --realm=$dcvars->{REALM}";
1522 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1523 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1524
1525 unless (system($cmd) == 0) {
1526 warn("Join failed\n$cmd");
1527 return undef;
1528 }
1529
1530 $samba_tool = Samba::bindir_path($self, "samba-tool");
1531 $cmd = $self->get_cmd_env_vars($ret);
1532 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1533 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1534 $cmd .= " --machinepass=machine$ret->{PASSWORD} --dns-backend=BIND9_DLZ";
1535
1536 unless (system($cmd) == 0) {
1537 warn("Join failed\n$cmd");
1538 return undef;
1539 }
1540
1541 $self->set_pdc_env_vars($ret, $dcvars);
1542
1543 return $ret;
1544 }
1545
1546 sub provision_vampire_dc($$$)
1547 {
1548 my ($self, $prefix, $dcvars, $fl) = @_;
1549 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1550 my $name = "localvampiredc";
1551 my $extra_conf = "";
1552
1553 if ($fl == "2000") {
1554 $name = "vampire2000dc";
1555 } else {
1556 $extra_conf = "drs: immediate link sync = yes
1557 drs: max link sync = 250";
1558 }
1559
1560 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1561 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1562 $name,
1563 $dcvars->{DOMAIN},
1564 $dcvars->{REALM},
1565 $dcvars->{DOMSID},
1566 $fl,
1567 $dcvars->{PASSWORD},
1568 $dcvars->{SERVER_IP},
1569 $dcvars->{SERVER_IPV6});
1570
1571 $ctx->{smb_conf_extra_options} = "
1572 max xmit = 32K
1573 server max protocol = SMB2
1574
1575 ntlm auth = mschapv2-and-ntlmv2-only
1576 $extra_conf
1577
1578 [sysvol]
1579 path = $ctx->{statedir}/sysvol
1580 read only = yes
1581
1582 [netlogon]
1583 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1584 read only = no
1585
1586 ";
1587
1588 my $ret = $self->provision_raw_step1($ctx);
1589 unless ($ret) {
1590 return undef;
1591 }
1592
1593 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1594 my $cmd = $self->get_cmd_env_vars($ret);
1595 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1596 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1597 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1598 $cmd .= " --backend-store=$self->{default_ldb_backend}";
1599
1600 unless (system($cmd) == 0) {
1601 warn("Join failed\n$cmd");
1602 return undef;
1603 }
1604
1605 $self->set_pdc_env_vars($ret, $dcvars);
1606 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1607
1608 return $ret;
1609 }
1610
1611 sub provision_ad_dc_ntvfs($$$)
1612 {
1613 my ($self, $prefix, $extra_provision_options) = @_;
1614
1615 # We keep the old 'winbind' name here in server services to
1616 # ensure upgrades which used that name still work with the now
1617 # alias.
1618
1619 print "PROVISIONING AD DC (NTVFS)...\n";
1620 my $extra_conf_options = "netbios aliases = localDC1-a
1621 server services = +winbind -winbindd
1622 ldap server require strong auth = allow_sasl_without_tls_channel_bindings
1623 raw NTLMv2 auth = yes
1624 lsa over netlogon = yes
1625 wins hook = $ENV{SRCDIR_ABS}/testprogs/blackbox/wins_hook_test
1626 rpc server port = 1027
1627 auth event notification = true
1628 dsdb event notification = true
1629 dsdb password event notification = true
1630 dsdb group change notification = true
1631 # override the new SMB2 only default
1632 client min protocol = CORE
1633 server min protocol = LANMAN1
1634 kdc name match implicit dollar without canonicalization = no
1635
1636 server support krb5 netlogon = yes
1637 CVE_2020_1472:warn_about_unused_debug_level = 3
1638 CVE_2022_38023:warn_about_unused_debug_level = 3
1639 allow nt4 crypto:torturetest\$ = yes
1640 server reject md5 schannel:schannel2\$ = no
1641 server reject md5 schannel:schannel3\$ = no
1642 server reject md5 schannel:schannel8\$ = no
1643 server reject md5 schannel:schannel9\$ = no
1644 server reject md5 schannel:torturetest\$ = no
1645 server reject md5 schannel:tests4u2proxywk\$ = no
1646 server reject md5 schannel:tests4u2selfbdc\$ = no
1647 server reject md5 schannel:tests4u2selfwk\$ = no
1648 server reject md5 schannel:torturepacbdc\$ = no
1649 server reject md5 schannel:torturepacwksta\$ = no
1650 server reject aes schannel:schannel2\$ = no
1651 server reject aes schannel:schannel3\$ = no
1652 server reject aes schannel:schannel8\$ = no
1653 server reject aes schannel:schannel9\$ = no
1654 server reject aes schannel:torturetest\$ = no
1655 server reject aes schannel:tests4u2proxywk\$ = no
1656 server reject aes schannel:tests4u2selfbdc\$ = no
1657 server reject aes schannel:tests4u2selfwk\$ = no
1658 server reject aes schannel:torturepacbdc\$ = no
1659 server reject aes schannel:torturepacwksta\$ = no
1660 server require schannel:schannel0\$ = no
1661 server require schannel:schannel1\$ = no
1662 server require schannel:schannel2\$ = no
1663 server require schannel:schannel3\$ = no
1664 server require schannel:schannel4\$ = no
1665 server require schannel:schannel5\$ = no
1666 server require schannel:schannel6\$ = no
1667 server require schannel:schannel7\$ = no
1668 server require schannel:schannel8\$ = no
1669 server require schannel:schannel9\$ = no
1670 server require schannel:schannel10\$ = no
1671 server require schannel:schannel11\$ = no
1672 server require schannel:torturetest\$ = no
1673 server schannel require seal:schannel0\$ = no
1674 server schannel require seal:schannel1\$ = no
1675 server schannel require seal:schannel2\$ = no
1676 server schannel require seal:schannel3\$ = no
1677 server schannel require seal:schannel4\$ = no
1678 server schannel require seal:schannel5\$ = no
1679 server schannel require seal:schannel6\$ = no
1680 server schannel require seal:schannel7\$ = no
1681 server schannel require seal:schannel8\$ = no
1682 server schannel require seal:schannel9\$ = no
1683 server schannel require seal:schannel10\$ = no
1684 server schannel require seal:schannel11\$ = no
1685 server schannel require seal:torturetest\$ = no
1686
1687 # needed for 'samba.tests.auth_log' tests
1688 server require schannel:LOCALDC\$ = no
1689 server schannel require seal:LOCALDC\$ = no
1690
1691 strong certificate binding enforcement = compatibility
1692 certificate backdating compensation = 1500
1693 ";
1694 push (@{$extra_provision_options},
1695 "--base-schema=2008_R2",
1696 "--use-ntvfs");
1697 my $ret = $self->provision($prefix,
1698 "domain controller",
1699 "localdc",
1700 "SAMBADOMAIN",
1701 "samba.example.com",
1702 "2008",
1703 "locDCpass1",
1704 undef,
1705 undef,
1706 undef,
1707 $extra_conf_options,
1708 "",
1709 $extra_provision_options);
1710 unless ($ret) {
1711 return undef;
1712 }
1713
1714 unless($self->add_wins_config("$prefix/private")) {
1715 warn("Unable to add wins configuration");
1716 return undef;
1717 }
1718 $ret->{NETBIOSALIAS} = "localdc1-a";
1719 $ret->{DC_REALM} = $ret->{REALM};
1720
1721 return $ret;
1722 }
1723
1724 sub provision_fl2000dc($$)
1725 {
1726 my ($self, $prefix) = @_;
1727
1728 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1729 my $extra_conf_options = "
1730 kdc enable fast = no
1731 spnego:simulate_w2k=yes
1732 ntlmssp_server:force_old_spnego=yes
1733
1734 CVE_2022_38023:warn_about_unused_debug_level = 3
1735 server reject md5 schannel:tests4u2proxywk\$ = no
1736 server reject md5 schannel:tests4u2selfbdc\$ = no
1737 server reject md5 schannel:tests4u2selfwk\$ = no
1738 server reject md5 schannel:torturepacbdc\$ = no
1739 server reject md5 schannel:torturepacwksta\$ = no
1740 server reject aes schannel:tests4u2proxywk\$ = no
1741 server reject aes schannel:tests4u2selfbdc\$ = no
1742 server reject aes schannel:tests4u2selfwk\$ = no
1743 server reject aes schannel:torturepacbdc\$ = no
1744 server reject aes schannel:torturepacwksta\$ = no
1745 ";
1746 my $extra_provision_options = ["--base-schema=2008_R2"];
1747 # This environment uses plain text secrets
1748 # i.e. secret attributes are not encrypted on disk.
1749 # This allows testing of the --plaintext-secrets option for
1750 # provision
1751 push (@{$extra_provision_options}, "--plaintext-secrets");
1752 my $ret = $self->provision($prefix,
1753 "domain controller",
1754 "dc5",
1755 "SAMBA2000",
1756 "samba2000.example.com",
1757 "2000",
1758 "locDCpass5",
1759 undef,
1760 undef,
1761 undef,
1762 $extra_conf_options,
1763 "",
1764 $extra_provision_options);
1765 unless ($ret) {
1766 return undef;
1767 }
1768
1769 unless($self->add_wins_config("$prefix/private")) {
1770 warn("Unable to add wins configuration");
1771 return undef;
1772 }
1773 $ret->{DC_REALM} = $ret->{REALM};
1774
1775 return $ret;
1776 }
1777
1778 sub provision_fl2003dc($$$)
1779 {
1780 my ($self, $prefix, $dcvars) = @_;
1781 my $ip_addr1 = Samba::get_ipv4_addr("fakednsforwarder1");
1782 my $ip_addr2 = Samba::get_ipv6_addr("fakednsforwarder2");
1783
1784 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1785 my $extra_conf_options = "
1786 allow dns updates = nonsecure and secure
1787
1788 kdc enable fast = no
1789 dcesrv:header signing = no
1790 dcesrv:max auth states = 0
1791
1792 dns forwarder = $ip_addr1 [$ip_addr2]:54
1793
1794 CVE_2022_38023:warn_about_unused_debug_level = 3
1795 server reject md5 schannel:tests4u2proxywk\$ = no
1796 server reject md5 schannel:tests4u2selfbdc\$ = no
1797 server reject md5 schannel:tests4u2selfwk\$ = no
1798 server reject md5 schannel:torturepacbdc\$ = no
1799 server reject md5 schannel:torturepacwksta\$ = no
1800 server reject aes schannel:tests4u2proxywk\$ = no
1801 server reject aes schannel:tests4u2selfbdc\$ = no
1802 server reject aes schannel:tests4u2selfwk\$ = no
1803 server reject aes schannel:torturepacbdc\$ = no
1804 server reject aes schannel:torturepacwksta\$ = no
1805 ";
1806
1807 my $extra_provision_options = ["--base-schema=2008_R2"];
1808 my $ret = $self->provision($prefix,
1809 "domain controller",
1810 "dc6",
1811 "SAMBA2003",
1812 "samba2003.example.com",
1813 "2003",
1814 "locDCpass6",
1815 undef,
1816 undef,
1817 undef,
1818 $extra_conf_options,
1819 "",
1820 $extra_provision_options);
1821 unless (defined $ret) {
1822 return undef;
1823 }
1824
1825 $ret->{DNS_FORWARDER1} = $ip_addr1;
1826 $ret->{DNS_FORWARDER2} = $ip_addr2;
1827
1828 my @samba_tool_options;
1829 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1830 push (@samba_tool_options, "domain");
1831 push (@samba_tool_options, "passwordsettings");
1832 push (@samba_tool_options, "set");
1833 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1834 push (@samba_tool_options, "--min-pwd-age=0");
1835 push (@samba_tool_options, "--history-length=1");
1836
1837 my $samba_tool_cmd = join(" ", @samba_tool_options);
1838
1839 unless (system($samba_tool_cmd) == 0) {
1840 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1841 return undef;
1842 }
1843
1844 unless($self->add_wins_config("$prefix/private")) {
1845 warn("Unable to add wins configuration");
1846 return undef;
1847 }
1848
1849 return $ret;
1850 }
1851
1852 sub provision_fl2008r2dc($$$)
1853 {
1854 my ($self, $prefix, $dcvars) = @_;
1855
1856 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1857 my $extra_conf_options = "
1858 ldap server require strong auth = no
1859 # delay by 10 seconds, 10^7 usecs
1860 ldap_server:delay_expire_disconnect = 10000
1861
1862 server support krb5 netlogon = yes
1863 CVE_2022_38023:warn_about_unused_debug_level = 3
1864 server reject md5 schannel:tests4u2proxywk\$ = no
1865 server reject md5 schannel:tests4u2selfbdc\$ = no
1866 server reject md5 schannel:tests4u2selfwk\$ = no
1867 server reject md5 schannel:torturepacbdc\$ = no
1868 server reject md5 schannel:torturepacwksta\$ = no
1869 server reject aes schannel:tests4u2proxywk\$ = no
1870 server reject aes schannel:tests4u2selfbdc\$ = no
1871 server reject aes schannel:tests4u2selfwk\$ = no
1872 server reject aes schannel:torturepacbdc\$ = no
1873 server reject aes schannel:torturepacwksta\$ = no
1874
1875 kdc always include pac = no
1876 krb5 acceptor report canonical client name = no
1877 ";
1878 my $extra_provision_options = ["--base-schema=2008_R2"];
1879 my $ret = $self->provision($prefix,
1880 "domain controller",
1881 "dc7",
1882 "SAMBA2008R2",
1883 "samba2008R2.example.com",
1884 "2008_R2",
1885 "locDCpass7",
1886 undef,
1887 undef,
1888 undef,
1889 $extra_conf_options,
1890 "",
1891 $extra_provision_options);
1892 unless (defined $ret) {
1893 return undef;
1894 }
1895
1896 unless ($self->add_wins_config("$prefix/private")) {
1897 warn("Unable to add wins configuration");
1898 return undef;
1899 }
1900 $ret->{DC_REALM} = $ret->{REALM};
1901
1902 return $ret;
1903 }
1904
1905
1906 sub provision_rodc($$$)
1907 {
1908 my ($self, $prefix, $dcvars) = @_;
1909 print "PROVISIONING RODC...\n";
1910
1911 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1912 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1913 "rodc",
1914 $dcvars->{DOMAIN},
1915 $dcvars->{REALM},
1916 $dcvars->{DOMSID},
1917 "2008",
1918 $dcvars->{PASSWORD},
1919 $dcvars->{SERVER_IP},
1920 $dcvars->{SERVER_IPV6});
1921 unless ($ctx) {
1922 return undef;
1923 }
1924
1925 $ctx->{share} = "$ctx->{prefix}/share";
1926 push(@{$ctx->{directories}}, "$ctx->{share}");
1927
1928 $ctx->{smb_conf_extra_options} = "
1929 max xmit = 32K
1930 server max protocol = SMB2
1931 password server = $dcvars->{DC_SERVER}
1932
1933 [sysvol]
1934 path = $ctx->{statedir}/sysvol
1935 read only = yes
1936
1937 [netlogon]
1938 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1939 read only = yes
1940
1941 [tmp]
1942 path = $ctx->{share}
1943 read only = no
1944 posix:sharedelay = 10000
1945 posix:oplocktimeout = 3
1946 posix:writetimeupdatedelay = 50000
1947
1948 ";
1949
1950 my $ret = $self->provision_raw_step1($ctx);
1951 unless ($ret) {
1952 return undef;
1953 }
1954
1955 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1956 my $cmd = $self->get_cmd_env_vars($ret);
1957 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1958 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1959 $cmd .= " --server=$dcvars->{DC_SERVER}";
1960
1961 unless (system($cmd) == 0) {
1962 warn("RODC join failed\n$cmd");
1963 return undef;
1964 }
1965
1966 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1967 # user password verified on the RODC
1968 my $testallowed_account = "testallowed account";
1969 $cmd = $self->get_cmd_env_vars($ret);
1970 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1971 $cmd .= " --server=$dcvars->{DC_SERVER}";
1972
1973 unless (system($cmd) == 0) {
1974 warn("RODC join failed\n$cmd");
1975 return undef;
1976 }
1977
1978 # we overwrite the kdc after the RODC join
1979 # so that use the RODC as kdc and test
1980 # the proxy code
1981 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1982 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1983 Samba::mk_krb5_conf($ctx);
1984 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1985
1986 $self->set_pdc_env_vars($ret, $dcvars);
1987
1988 return $ret;
1989 }
1990
1991 sub read_config_h($)
1992 {
1993 my ($name) = @_;
1994 my %ret;
1995 open(LF, "<$name") or die("unable to read $name: $!");
1996 while (<LF>) {
1997 chomp;
1998 next if not (/^#define /);
1999 if (/^#define (.*?)[ \t]+(.*?)$/) {
2000 $ret{$1} = $2;
2001 next;
2002 }
2003 if (/^#define (.*?)[ \t]+$/) {
2004 $ret{$1} = 1;;
2005 next;
2006 }
2007 }
2008 close(LF);
2009 return \%ret;
2010 }
2011
2012 sub provision_ad_dc()
2013 {
2014 my ($self,
2015 $prefix,
2016 $hostname,
2017 $domain,
2018 $realm,
2019 $force_fips_mode,
2020 $smbconf_args,
2021 $extra_provision_options,
2022 $functional_level) = @_;
2023
2024 my $bindir_abs = abs_path($self->{bindir});
2025 my $lockdir="$prefix/lockdir";
2026 my $conffile="$prefix/etc/smb.conf";
2027
2028 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
2029 if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} // '' eq "1") {
2030 $require_mutexes = "";
2031 }
2032
2033 my $config_h = {};
2034
2035 if (!defined($functional_level)) {
2036 $functional_level = "2016";
2037 }
2038
2039 # If we choose to have distinct environments for experimental
2040 # 2012 as well as the experimental 2016 support, we should
2041 # extend what we match here.
2042 if ($functional_level eq "2016") {
2043 $smbconf_args = "$smbconf_args
2044
2045 [global]
2046 ad dc functional level = 2016
2047 ";
2048 }
2049 if (defined($ENV{CONFIG_H})) {
2050 $config_h = read_config_h($ENV{CONFIG_H});
2051 }
2052
2053 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
2054 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
2055
2056 my $extra_smbconf_options = "
2057 xattr_tdb:file = $prefix/statedir/xattr.tdb
2058
2059 dbwrap_tdb_mutexes:* = yes
2060 ${require_mutexes}
2061
2062 ${password_hash_gpg_key_ids}
2063
2064 kernel oplocks = no
2065 kernel change notify = no
2066 smb2 leases = no
2067 smb2 disable oplock break retry = yes
2068 server multi channel support = yes
2069
2070 logging = file
2071 printing = bsd
2072 printcap name = /dev/null
2073
2074 max protocol = SMB3
2075 read only = no
2076
2077 smbd:sharedelay = 100000
2078 smbd:writetimeupdatedelay = 500000
2079 create mask = 755
2080 dos filemode = yes
2081 check parent directory delete on close = yes
2082
2083 dcerpc endpoint servers = -winreg -srvsvc
2084
2085 printcap name = /dev/null
2086
2087 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
2088 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
2089
2090 printing = vlp
2091 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
2092 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
2093 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
2094 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
2095 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
2096 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
2097 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
2098 lpq cache time = 0
2099 print notify backchannel = yes
2100
2101 server support krb5 netlogon = yes
2102 CVE_2020_1472:warn_about_unused_debug_level = 3
2103 CVE_2022_38023:warn_about_unused_debug_level = 3
2104 CVE_2022_38023:error_debug_level = 2
2105 allow nt4 crypto:samlogontest\$ = yes
2106 server reject md5 schannel:schannel2\$ = no
2107 server reject md5 schannel:schannel3\$ = no
2108 server reject md5 schannel:schannel8\$ = no
2109 server reject md5 schannel:schannel9\$ = no
2110 server reject md5 schannel:torturetest\$ = no
2111 server reject md5 schannel:tests4u2proxywk\$ = no
2112 server reject md5 schannel:tests4u2selfbdc\$ = no
2113 server reject md5 schannel:tests4u2selfwk\$ = no
2114 server reject md5 schannel:torturepacbdc\$ = no
2115 server reject md5 schannel:torturepacwksta\$ = no
2116 server reject md5 schannel:samlogontest\$ = no
2117 server reject aes schannel:schannel2\$ = no
2118 server reject aes schannel:schannel3\$ = no
2119 server reject aes schannel:schannel8\$ = no
2120 server reject aes schannel:schannel9\$ = no
2121 server reject aes schannel:torturetest\$ = no
2122 server reject aes schannel:tests4u2proxywk\$ = no
2123 server reject aes schannel:tests4u2selfbdc\$ = no
2124 server reject aes schannel:tests4u2selfwk\$ = no
2125 server reject aes schannel:torturepacbdc\$ = no
2126 server reject aes schannel:torturepacwksta\$ = no
2127 server reject aes schannel:samlogontest\$ = no
2128 server require schannel:schannel0\$ = no
2129 server require schannel:schannel1\$ = no
2130 server require schannel:schannel2\$ = no
2131 server require schannel:schannel3\$ = no
2132 server require schannel:schannel4\$ = no
2133 server require schannel:schannel5\$ = no
2134 server require schannel:schannel6\$ = no
2135 server require schannel:schannel7\$ = no
2136 server require schannel:schannel8\$ = no
2137 server require schannel:schannel9\$ = no
2138 server require schannel:schannel10\$ = no
2139 server require schannel:schannel11\$ = no
2140 server require schannel:torturetest\$ = no
2141 server schannel require seal:schannel0\$ = no
2142 server schannel require seal:schannel1\$ = no
2143 server schannel require seal:schannel2\$ = no
2144 server schannel require seal:schannel3\$ = no
2145 server schannel require seal:schannel4\$ = no
2146 server schannel require seal:schannel5\$ = no
2147 server schannel require seal:schannel6\$ = no
2148 server schannel require seal:schannel7\$ = no
2149 server schannel require seal:schannel8\$ = no
2150 server schannel require seal:schannel9\$ = no
2151 server schannel require seal:schannel10\$ = no
2152 server schannel require seal:schannel11\$ = no
2153 server schannel require seal:torturetest\$ = no
2154
2155 auth event notification = true
2156 dsdb event notification = true
2157 dsdb password event notification = true
2158 dsdb group change notification = true
2159
2160 winbind varlink service = yes
2161
2162 $smbconf_args
2163 ";
2164
2165 my $extra_smbconf_shares = "
2166
2167 [tmpenc]
2168 copy = tmp
2169 smb encrypt = required
2170
2171 [tmpcase]
2172 copy = tmp
2173 case sensitive = yes
2174
2175 [tmpguest]
2176 copy = tmp
2177 guest ok = yes
2178
2179 [hideunread]
2180 copy = tmp
2181 hide unreadable = yes
2182
2183 [durable]
2184 copy = tmp
2185 kernel share modes = no
2186 kernel oplocks = no
2187 posix locking = no
2188
2189 [print\$]
2190 copy = tmp
2191
2192 [print1]
2193 copy = tmp
2194 printable = yes
2195
2196 [print2]
2197 copy = print1
2198 [print3]
2199 copy = print1
2200 [print4]
2201 copy = print1
2202 guest ok = yes
2203 [lp]
2204 copy = print1
2205 ";
2206
2207 push (@{$extra_provision_options}, "--backend-store=$self->{default_ldb_backend}");
2208 print "PROVISIONING AD DC...\n";
2209 my $ret = $self->provision($prefix,
2210 "domain controller",
2211 $hostname,
2212 $domain,
2213 $realm,
2214 $functional_level,
2215 "locDCpass1",
2216 undef,
2217 undef,
2218 $force_fips_mode,
2219 $extra_smbconf_options,
2220 $extra_smbconf_shares,
2221 $extra_provision_options);
2222 unless (defined $ret) {
2223 return undef;
2224 }
2225
2226 unless($self->add_wins_config("$prefix/private")) {
2227 warn("Unable to add wins configuration");
2228 return undef;
2229 }
2230
2231 return $ret;
2232 }
2233
2234 sub provision_chgdcpass($$)
2235 {
2236 my ($self, $prefix) = @_;
2237
2238 print "PROVISIONING CHGDCPASS...\n";
2239 # This environment disallows the use of this password
2240 # (and also removes the default AD complexity checks)
2241 my $unacceptable_password = "Paßßword-widk3Dsle32jxdBdskldsk55klASKQ";
2242
2243 # This environment also sets some settings that are unusual,
2244 # to test specific behaviours. In particular, this
2245 # environment fails to correctly support DRSUAPI_DRS_GET_ANC
2246 # like Samba before 4.5 and DRSUAPI_DRS_GET_TGT before 4.8
2247 #
2248 # Additionally, disabling DRSUAPI_DRS_GET_TGT causes all links
2249 # to be sent last (in the final chunk), which is like Samba
2250 # before 4.8.
2251
2252 my $extra_smb_conf = "
2253 check password script = $self->{srcdir}/selftest/checkpassword_arg1.sh ${unacceptable_password}
2254 dcesrv:max auth states = 8
2255 drs:broken_samba_4.5_get_anc_emulation = true
2256 drs:get_tgt_support = false
2257 ";
2258 my $extra_provision_options = ["--dns-backend=BIND9_DLZ"];
2259 my $ret = $self->provision($prefix,
2260 "domain controller",
2261 "chgdcpass",
2262 "CHDCDOMAIN",
2263 "chgdcpassword.samba.example.com",
2264 "2008",
2265 "chgDCpass1",
2266 undef,
2267 undef,
2268 undef,
2269 $extra_smb_conf,
2270 "",
2271 $extra_provision_options);
2272 unless (defined $ret) {
2273 return undef;
2274 }
2275
2276 unless($self->add_wins_config("$prefix/private")) {
2277 warn("Unable to add wins configuration");
2278 return undef;
2279 }
2280
2281 # Remove secrets.tdb from this environment to test that we
2282 # still start up on systems without the new matching
2283 # secrets.tdb records.
2284 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2285 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2286 return undef;
2287 }
2288
2289 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2290
2291 return $ret;
2292 }
2293
2294 sub teardown_env_terminate($$)
2295 {
2296 my ($self, $envvars) = @_;
2297 my $pid;
2298
2299 # This should cause samba to terminate gracefully
2300 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2301 my $cmd = "";
2302 $cmd .= "$smbcontrol samba shutdown $envvars->{CONFIGURATION}";
2303 my $ret = system($cmd);
2304 if ($ret != 0) {
2305 warn "'$cmd' failed with '$ret'\n";
2306 }
2307
2308 # This should cause samba to terminate gracefully
2309 close($envvars->{STDIN_PIPE});
2310
2311 $pid = $envvars->{SAMBA_PID};
2312 my $count = 0;
2313 my $childpid;
2314
2315 # This should give it time to write out the gcov data
2316 until ($count > 15) {
2317 if (Samba::cleanup_child($pid, "samba") != 0) {
2318 return;
2319 }
2320 sleep(1);
2321 $count++;
2322 }
2323
2324 # After 15 Seconds, work out why this thing is still alive
2325 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2326 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2327
2328 until ($count > 30) {
2329 if (Samba::cleanup_child($pid, "samba") != 0) {
2330 return;
2331 }
2332 sleep(1);
2333 $count++;
2334 }
2335
2336 if (kill(0, $pid)) {
2337 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2338 kill "TERM", $pid;
2339 }
2340
2341 until ($count > 40) {
2342 if (Samba::cleanup_child($pid, "samba") != 0) {
2343 return;
2344 }
2345 sleep(1);
2346 $count++;
2347 }
2348 # If it is still around, kill it
2349 if (kill(0, $pid)) {
2350 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2351 kill 9, $pid;
2352 }
2353 return;
2354 }
2355
2356 sub teardown_env($$)
2357 {
2358 my ($self, $envvars) = @_;
2359 teardown_env_terminate($self, $envvars);
2360
2361 print $self->getlog_env($envvars);
2362
2363 return;
2364 }
2365
2366 sub getlog_env($$)
2367 {
2368 my ($self, $envvars) = @_;
2369 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2370 my $out = $title;
2371
2372 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2373
2374 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2375 while (<LOG>) {
2376 $out .= $_;
2377 }
2378 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2379 close(LOG);
2380
2381 return "" if $out eq $title;
2382
2383 return $out;
2384 }
2385
2386 sub check_env($$)
2387 {
2388 my ($self, $envvars) = @_;
2389 my $samba_pid = $envvars->{SAMBA_PID};
2390
2391 if (not defined($samba_pid)) {
2392 return 0;
2393 } elsif ($samba_pid > 0) {
2394 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2395
2396 if ($childpid == 0) {
2397 return 1;
2398 }
2399 return 0;
2400 } else {
2401 return 1;
2402 }
2403 }
2404
2405 # Declare the environments Samba4 makes available.
2406 # To be set up, they will be called as
2407 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2408 # The interdependencies between the testenvs are declared below. Some testenvs
2409 # are dependent on another testenv running first, e.g. vampire_dc is dependent
2410 # on ad_dc_ntvfs because vampire_dc joins ad_dc_ntvfs's domain. All DCs are
2411 # dependent on dns_hub, which handles resolving DNS queries for the realm.
2412 %Samba4::ENV_DEPS = (
2413 # name => [dep_1, dep_2, ...],
2414 dns_hub => [],
2415 ad_dc_ntvfs => ["dns_hub"],
2416 ad_dc_fips => ["dns_hub"],
2417 ad_dc => ["dns_hub"],
2418 ad_dc_smb1 => ["dns_hub"],
2419 ad_dc_smb1_done => ["ad_dc_smb1"],
2420 ad_dc_no_nss => ["dns_hub"],
2421 ad_dc_no_ntlm => ["dns_hub"],
2422
2423 fl2008r2dc => ["ad_dc", "nt4_dc"],
2424 fl2003dc => ["ad_dc"],
2425 fl2000dc => ["ad_dc"],
2426
2427 vampire_2000_dc => ["fl2000dc"],
2428 vampire_dc => ["ad_dc_ntvfs"],
2429 promoted_dc => ["ad_dc_ntvfs"],
2430
2431 rodc => ["ad_dc_ntvfs"],
2432 rpc_proxy => ["ad_dc_ntvfs"],
2433 chgdcpass => ["dns_hub"],
2434
2435 s4member_dflt_domain => ["ad_dc_ntvfs"],
2436 s4member => ["ad_dc_ntvfs"],
2437
2438 # envs that test the server process model
2439 proclimitdc => ["dns_hub"],
2440 preforkrestartdc => ["dns_hub"],
2441
2442 # backup/restore testenvs
2443 backupfromdc => ["dns_hub"],
2444 customdc => ["dns_hub"],
2445 restoredc => ["backupfromdc"],
2446 renamedc => ["backupfromdc"],
2447 offlinebackupdc => ["backupfromdc"],
2448 labdc => ["backupfromdc"],
2449
2450 # aliases in order to split autobuild tasks
2451 fl2008dc => ["ad_dc_ntvfs"],
2452 ad_dc_default => ["ad_dc"],
2453 ad_dc_default_smb1 => ["ad_dc_smb1"],
2454 ad_dc_default_smb1_done => ["ad_dc_default_smb1"],
2455 ad_dc_slowtests => ["ad_dc"],
2456 ad_dc_backup => ["ad_dc"],
2457
2458 schema_dc => ["dns_hub"],
2459 schema_pair_dc => ["schema_dc"],
2460
2461 none => [],
2462 );
2463
2464 %Samba4::ENV_DEPS_POST = (
2465 schema_dc => ["schema_pair_dc"],
2466 );
2467
2468 sub return_alias_env
2469 {
2470 my ($self, $path, $env) = @_;
2471
2472 # just an alias
2473 return $env;
2474 }
2475
2476 sub setup_fl2008dc
2477 {
2478 my ($self, $path, $dep_env) = @_;
2479 return $self->return_alias_env($path, $dep_env)
2480 }
2481
2482 sub setup_ad_dc_default
2483 {
2484 my ($self, $path, $dep_env) = @_;
2485 return $self->return_alias_env($path, $dep_env)
2486 }
2487
2488 sub setup_ad_dc_default_smb1
2489 {
2490 my ($self, $path, $dep_env) = @_;
2491 return $self->return_alias_env($path, $dep_env)
2492 }
2493
2494 sub setup_ad_dc_default_smb1_done
2495 {
2496 my ($self, $path, $dep_env) = @_;
2497 return $self->return_alias_env($path, $dep_env)
2498 }
2499
2500 sub setup_ad_dc_slowtests
2501 {
2502 my ($self, $path, $dep_env) = @_;
2503 return $self->return_alias_env($path, $dep_env)
2504 }
2505
2506 sub setup_ad_dc_backup
2507 {
2508 my ($self, $path, $dep_env) = @_;
2509 return $self->return_alias_env($path, $dep_env)
2510 }
2511
2512 sub setup_s4member
2513 {
2514 my ($self, $path, $dc_vars) = @_;
2515
2516 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2517
2518 if (defined $env) {
2519 if (not defined($self->check_or_start($env, "standard"))) {
2520 return undef;
2521 }
2522 }
2523
2524 return $env;
2525 }
2526
2527 sub setup_s4member_dflt_domain
2528 {
2529 my ($self, $path, $dc_vars) = @_;
2530
2531 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2532 "winbind use default domain = yes");
2533
2534 if (defined $env) {
2535 if (not defined($self->check_or_start($env, "standard"))) {
2536 return undef;
2537 }
2538 }
2539
2540 return $env;
2541 }
2542
2543 sub setup_rpc_proxy
2544 {
2545 my ($self, $path, $dc_vars) = @_;
2546
2547 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2548
2549 if (defined $env) {
2550 if (not defined($self->check_or_start($env, "standard"))) {
2551 return undef;
2552 }
2553 }
2554 return $env;
2555 }
2556
2557 sub setup_ad_dc_ntvfs
2558 {
2559 my ($self, $path) = @_;
2560
2561 my $env = $self->provision_ad_dc_ntvfs($path, undef);
2562 if (defined $env) {
2563 if (not defined($self->check_or_start($env, "standard"))) {
2564 warn("Failed to start ad_dc_ntvfs");
2565 return undef;
2566 }
2567 }
2568 return $env;
2569 }
2570
2571 sub setup_chgdcpass
2572 {
2573 my ($self, $path) = @_;
2574
2575 my $env = $self->provision_chgdcpass($path);
2576 if (defined $env) {
2577 if (not defined($self->check_or_start($env, "standard"))) {
2578 return undef;
2579 }
2580 }
2581 return $env;
2582 }
2583
2584 sub setup_fl2000dc
2585 {
2586 my ($self, $path, $dc_vars) = @_;
2587
2588 my $env = $self->provision_fl2000dc($path);
2589 if (defined $env) {
2590 if (not defined($self->check_or_start($env, "standard"))) {
2591 return undef;
2592 }
2593
2594 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys --direction=outgoing");
2595 }
2596
2597 return $env;
2598 }
2599
2600 sub setup_fl2003dc
2601 {
2602 my ($self, $path, $dc_vars) = @_;
2603
2604 my $env = $self->provision_fl2003dc($path);
2605
2606 if (defined $env) {
2607 if (not defined($self->check_or_start($env, "standard"))) {
2608 return undef;
2609 }
2610
2611 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2612 }
2613 return $env;
2614 }
2615
2616 sub setup_fl2008r2dc
2617 {
2618 my ($self, $path, $ad_dc_vars, $nt4_dc_vars) = @_;
2619
2620 my $env = $self->provision_fl2008r2dc($path);
2621
2622 if (!defined $env) {
2623 return $env;
2624 }
2625
2626 if (not defined($self->check_or_start($env, "standard"))) {
2627 return undef;
2628 }
2629
2630 my $upn_array = ["$env->{REALM}.upn"];
2631 my $spn_array = ["$env->{REALM}.spn"];
2632
2633 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
2634 return undef;
2635 }
2636
2637 $env = $self->setup_trust($env, $ad_dc_vars, "forest", "");
2638 if (!defined $env) {
2639 return undef;
2640 }
2641
2642 my $net = Samba::bindir_path($self, "net");
2643 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
2644
2645 my $trustpw = "TrUsTpW";
2646 $trustpw .= "$env->{SOCKET_WRAPPER_DEFAULT_IFACE}";
2647 $trustpw .= "$nt4_dc_vars->{SOCKET_WRAPPER_DEFAULT_IFACE}";
2648
2649 my $cmd_env = $self->get_cmd_env_vars($env);
2650 my $cmd = $cmd_env;
2651 $cmd .= "$net rpc trust create ";
2652 $cmd .= "otherdomainsid=$nt4_dc_vars->{SAMSID} ";
2653 $cmd .= "otherdomain=$nt4_dc_vars->{DOMAIN} ";
2654 $cmd .= "other_netbios_domain=$nt4_dc_vars->{DOMAIN} ";
2655 $cmd .= "trustpw=$trustpw ";
2656 $cmd .= "$env->{CONFIGURATION} ";
2657 $cmd .= "-U $env->{DOMAIN}/$env->{USERNAME}\%$env->{PASSWORD} ";
2658
2659 if (system($cmd) != 0) {
2660 warn("net rpc trust create failed\n$cmd");
2661 return undef;
2662 }
2663
2664 my $nt4_cmd_env = $self->get_cmd_env_vars($nt4_dc_vars);
2665 $cmd = $nt4_cmd_env;
2666 $cmd .= "$net rpc trustdom establish $env->{DOMAIN} -U/%$trustpw $nt4_dc_vars->{CONFIGURATION}";
2667
2668 if (system($cmd) != 0) {
2669 warn("add failed\n$cmd");
2670 return undef;
2671 }
2672
2673 # Reload trusts
2674 $cmd = $nt4_cmd_env;
2675 $cmd .= "$smbcontrol winbindd reload-config $nt4_dc_vars->{CONFIGURATION}";
2676
2677 if (system($cmd) != 0) {
2678 warn("add failed\n$cmd");
2679 return undef;
2680 }
2681
2682 $env->{NT4_TRUST_SERVER} = $nt4_dc_vars->{SERVER};
2683 $env->{NT4_TRUST_SERVER_IP} = $nt4_dc_vars->{SERVER_IP};
2684 $env->{NT4_TRUST_DOMAIN} = $nt4_dc_vars->{DOMAIN};
2685 $env->{NT4_TRUST_DOMSID} = $nt4_dc_vars->{DOMSID};
2686
2687 return $env;
2688 }
2689
2690 sub setup_vampire_dc
2691 {
2692 return setup_generic_vampire_dc(@_, "2008");
2693 }
2694
2695 sub setup_vampire_2000_dc
2696 {
2697 return setup_generic_vampire_dc(@_, "2000");
2698 }
2699
2700 sub setup_generic_vampire_dc
2701 {
2702 my ($self, $path, $dc_vars, $fl) = @_;
2703
2704 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2705
2706 if (defined $env) {
2707 if (not defined($self->check_or_start($env, "single"))) {
2708 return undef;
2709 }
2710
2711 # force replicated DC to update repsTo/repsFrom
2712 # for vampired partitions
2713 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2714
2715 # as 'vampired' dc may add data in its local replica
2716 # we need to synchronize data between DCs
2717 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2718 my $cmd = $self->get_cmd_env_vars($env);
2719 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2720 $cmd .= " $dc_vars->{CONFIGURATION}";
2721 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2722 # replicate Configuration NC
2723 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2724 unless(system($cmd_repl) == 0) {
2725 warn("Failed to replicate\n$cmd_repl");
2726 return undef;
2727 }
2728 # replicate Default NC
2729 $cmd_repl = "$cmd \"$base_dn\"";
2730 unless(system($cmd_repl) == 0) {
2731 warn("Failed to replicate\n$cmd_repl");
2732 return undef;
2733 }
2734
2735 # Pull in a full set of changes from the main DC
2736 $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2737 $cmd = $self->get_cmd_env_vars($env);
2738 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2739 $cmd .= " $dc_vars->{CONFIGURATION}";
2740 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2741 # replicate Configuration NC
2742 $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2743 unless(system($cmd_repl) == 0) {
2744 warn("Failed to replicate\n$cmd_repl");
2745 return undef;
2746 }
2747 # replicate Default NC
2748 $cmd_repl = "$cmd \"$base_dn\"";
2749 unless(system($cmd_repl) == 0) {
2750 warn("Failed to replicate\n$cmd_repl");
2751 return undef;
2752 }
2753 }
2754
2755 return $env;
2756 }
2757
2758 sub setup_promoted_dc
2759 {
2760 my ($self, $path, $dc_vars) = @_;
2761
2762 my $env = $self->provision_promoted_dc($path, $dc_vars);
2763
2764 if (defined $env) {
2765 if (not defined($self->check_or_start($env, "single"))) {
2766 return undef;
2767 }
2768
2769 # force source and replicated DC to update repsTo/repsFrom
2770 # for vampired partitions
2771 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2772 my $cmd = $self->get_cmd_env_vars($env);
2773 # as 'vampired' dc may add data in its local replica
2774 # we need to synchronize data between DCs
2775 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2776 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2777 $cmd .= " $dc_vars->{CONFIGURATION}";
2778 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2779 # replicate Configuration NC
2780 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2781 unless(system($cmd_repl) == 0) {
2782 warn("Failed to replicate\n$cmd_repl");
2783 return undef;
2784 }
2785 # replicate Default NC
2786 $cmd_repl = "$cmd \"$base_dn\"";
2787 unless(system($cmd_repl) == 0) {
2788 warn("Failed to replicate\n$cmd_repl");
2789 return undef;
2790 }
2791 }
2792
2793 return $env;
2794 }
2795
2796 sub setup_rodc
2797 {
2798 my ($self, $path, $dc_vars) = @_;
2799
2800 my $env = $self->provision_rodc($path, $dc_vars);
2801
2802 unless ($env) {
2803 return undef;
2804 }
2805
2806 if (not defined($self->check_or_start($env, "standard"))) {
2807 return undef;
2808 }
2809
2810 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2811 my $cmd = $self->get_cmd_env_vars($env);
2812
2813 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2814 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2815 $cmd .= " $dc_vars->{CONFIGURATION}";
2816 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2817 # replicate Configuration NC
2818 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2819 unless(system($cmd_repl) == 0) {
2820 warn("Failed to replicate\n$cmd_repl");
2821 return undef;
2822 }
2823 # replicate Default NC
2824 $cmd_repl = "$cmd \"$base_dn\"";
2825 unless(system($cmd_repl) == 0) {
2826 warn("Failed to replicate\n$cmd_repl");
2827 return undef;
2828 }
2829
2830 return $env;
2831 }
2832
2833 sub _setup_ad_dc
2834 {
2835 my ($self, $path, $conf_opts, $server, $dom, $functional_level) = @_;
2836
2837 # If we didn't build with ADS, pretend this env was never available
2838 if (not $self->{target3}->have_ads()) {
2839 return "UNKNOWN";
2840 }
2841
2842 if (!defined($conf_opts)) {
2843 $conf_opts = "";
2844 }
2845 if (!defined($server)) {
2846 $server = "addc";
2847 }
2848 if (!defined($dom)) {
2849 $dom = "addom.samba.example.com";
2850 }
2851 my $env = $self->provision_ad_dc($path, $server, "ADDOMAIN",
2852 $dom,
2853 undef,
2854 $conf_opts,
2855 undef,
2856 $functional_level);
2857 unless ($env) {
2858 return undef;
2859 }
2860
2861 if (not defined($self->check_or_start($env, "prefork"))) {
2862 return undef;
2863 }
2864
2865 my $upn_array = ["$env->{REALM}.upn"];
2866 my $spn_array = ["$env->{REALM}.spn"];
2867
2868 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
2869 return undef;
2870 }
2871
2872 return $env;
2873 }
2874
2875 sub setup_ad_dc
2876 {
2877 my ($self, $path) = @_;
2878 # Disable certificate binding enforcement, to avoid
2879 # breaking kerberos tests
2880 my $conf_opts = "strong certificate binding enforcement = none\n";
2881
2882 return _setup_ad_dc($self, $path, $conf_opts, undef, undef);
2883 }
2884
2885 sub setup_ad_dc_smb1
2886 {
2887 my ($self, $path) = @_;
2888 my $conf_opts = "
2889 [global]
2890 client min protocol = CORE
2891 server min protocol = LANMAN1
2892
2893 # needed for 'samba.tests.auth_log' tests
2894 server require schannel:ADDCSMB1\$ = no
2895 server schannel require seal:ADDCSMB1\$ = no
2896 ";
2897 return _setup_ad_dc($self, $path, $conf_opts, "addcsmb1", "addom2.samba.example.com");
2898 }
2899
2900 sub setup_ad_dc_smb1_done
2901 {
2902 my ($self, $path, $dep_env) = @_;
2903 return $self->return_alias_env($path, $dep_env);
2904 }
2905
2906 sub setup_ad_dc_no_nss
2907 {
2908 my ($self, $path) = @_;
2909
2910 # If we didn't build with ADS, pretend this env was never available
2911 if (not $self->{target3}->have_ads()) {
2912 return "UNKNOWN";
2913 }
2914
2915 my $env = $self->provision_ad_dc($path,
2916 "addc_no_nss",
2917 "ADNONSSDOMAIN",
2918 "adnonssdom.samba.example.com",
2919 undef,
2920 "",
2921 undef);
2922 unless ($env) {
2923 return undef;
2924 }
2925
2926 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2927 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2928
2929 if (not defined($self->check_or_start($env, "single"))) {
2930 return undef;
2931 }
2932
2933 my $upn_array = ["$env->{REALM}.upn"];
2934 my $spn_array = ["$env->{REALM}.spn"];
2935
2936 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
2937 return undef;
2938 }
2939
2940 return $env;
2941 }
2942
2943 sub setup_ad_dc_no_ntlm
2944 {
2945 my ($self, $path) = @_;
2946
2947 # If we didn't build with ADS, pretend this env was never available
2948 if (not $self->{target3}->have_ads()) {
2949 return "UNKNOWN";
2950 }
2951
2952 my $env = $self->provision_ad_dc($path,
2953 "addc_no_ntlm",
2954 "ADNONTLMDOMAIN",
2955 "adnontlmdom.samba.example.com",
2956 undef,
2957 "ntlm auth = disabled\nnt hash store = never",
2958 undef);
2959 unless ($env) {
2960 return undef;
2961 }
2962
2963 if (not defined($self->check_or_start($env, "prefork"))) {
2964 return undef;
2965 }
2966
2967 my $upn_array = ["$env->{REALM}.upn"];
2968 my $spn_array = ["$env->{REALM}.spn"];
2969
2970 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
2971 return undef;
2972 }
2973
2974 return $env;
2975 }
2976
2977 sub setup_ad_dc_fips
2978 {
2979 my ($self, $path) = @_;
2980
2981 # If we didn't build with ADS, pretend this env was never available
2982 if (not $self->{target3}->have_ads()) {
2983 return "UNKNOWN";
2984 }
2985
2986 my $env = $self->provision_ad_dc($path,
2987 "fipsdc",
2988 "FIPSDOMAIN",
2989 "fips.samba.example.com",
2990 1,
2991 "",
2992 undef);
2993 unless ($env) {
2994 return undef;
2995 }
2996
2997 if (not defined($self->check_or_start($env, "prefork"))) {
2998 return undef;
2999 }
3000
3001 my $upn_array = ["$env->{REALM}.upn"];
3002 my $spn_array = ["$env->{REALM}.spn"];
3003
3004 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3005 return undef;
3006 }
3007
3008 return $env;
3009 }
3010
3011 #
3012 # AD DC test environment used solely to test pre-fork process restarts.
3013 # As processes get killed off and restarted it should not be used for other
3014 sub setup_preforkrestartdc
3015 {
3016 my ($self, $path) = @_;
3017
3018 # If we didn't build with ADS, pretend this env was never available
3019 if (not $self->{target3}->have_ads()) {
3020 return "UNKNOWN";
3021 }
3022
3023 # note DC name must be <= 15 chars so we use 'prockill' instead of
3024 # 'preforkrestart'
3025 my $env = $self->provision_ad_dc($path,
3026 "prockilldc",
3027 "PROCKILLDOMAIN",
3028 "prockilldom.samba.example.com",
3029 undef,
3030 "prefork backoff increment = 5\nprefork maximum backoff=10",
3031 undef);
3032 unless ($env) {
3033 return undef;
3034 }
3035
3036 # We treat processes in this environment cruelly, sometimes
3037 # sending them SIGSEGV signals. We don't need gdb_backtrace
3038 # dissecting these fake crashes in precise detail.
3039 $env->{PLEASE_NO_GDB_BACKTRACE} = '1';
3040
3041 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
3042 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
3043
3044 if (not defined($self->check_or_start($env, "prefork"))) {
3045 return undef;
3046 }
3047
3048 my $upn_array = ["$env->{REALM}.upn"];
3049 my $spn_array = ["$env->{REALM}.spn"];
3050
3051 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3052 return undef;
3053 }
3054
3055 return $env;
3056 }
3057
3058 #
3059 # ad_dc test environment used solely to test standard process model connection
3060 # process limits. As the limit is set artificially low it should not be used
3061 # for other tests.
3062 sub setup_proclimitdc
3063 {
3064 my ($self, $path) = @_;
3065
3066 # If we didn't build with ADS, pretend this env was never available
3067 if (not $self->{target3}->have_ads()) {
3068 return "UNKNOWN";
3069 }
3070
3071 my $env = $self->provision_ad_dc($path,
3072 "proclimitdc",
3073 "PROCLIMITDOM",
3074 "proclimit.samba.example.com",
3075 undef,
3076 "max smbd processes = 20",
3077 undef);
3078 unless ($env) {
3079 return undef;
3080 }
3081
3082 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
3083 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
3084
3085 if (not defined($self->check_or_start($env, "standard"))) {
3086 return undef;
3087 }
3088
3089 my $upn_array = ["$env->{REALM}.upn"];
3090 my $spn_array = ["$env->{REALM}.spn"];
3091
3092 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3093 return undef;
3094 }
3095
3096 return $env;
3097 }
3098
3099 # Used to test a live upgrade of the schema on a 2 DC network.
3100 sub setup_schema_dc
3101 {
3102 my ($self, $path) = @_;
3103
3104 # provision the PDC using an older base schema
3105 my $provision_args = ["--base-schema=2008_R2", "--backend-store=$self->{default_ldb_backend}"];
3106
3107 # We set the functional level to 2008_R2 to match the older
3108 # base-schema (to allow schema upgrade to be tested)
3109 my $env = $self->provision_ad_dc($path,
3110 "liveupgrade1dc",
3111 "SCHEMADOMAIN",
3112 "schema.samba.example.com",
3113 undef,
3114 "drs: max link sync = 2\n" .
3115 "kdc require canonicalization = yes",
3116 $provision_args,
3117 "2008_R2");
3118 unless ($env) {
3119 return undef;
3120 }
3121
3122 if (not defined($self->check_or_start($env, "prefork"))) {
3123 return undef;
3124 }
3125
3126 my $upn_array = ["$env->{REALM}.upn"];
3127 my $spn_array = ["$env->{REALM}.spn"];
3128
3129 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3130 return undef;
3131 }
3132
3133 return $env;
3134 }
3135
3136 # the second DC in the live schema upgrade pair
3137 sub setup_schema_pair_dc
3138 {
3139 # note: dcvars contains the env info for the dependent testenv ('schema_dc')
3140 my ($self, $prefix, $dcvars) = @_;
3141 print "Preparing SCHEMA UPGRADE PAIR DC...\n";
3142
3143 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "liveupgrade2dc",
3144 $dcvars->{DOMAIN},
3145 $dcvars->{REALM},
3146 $dcvars->{PASSWORD},
3147 "");
3148
3149 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3150 my $cmd_vars = $self->get_cmd_env_vars($env);
3151
3152 my $join_cmd = $cmd_vars;
3153 $join_cmd .= "$samba_tool domain join $env->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
3154 $join_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} ";
3155 $join_cmd .= " --backend-store=$self->{default_ldb_backend}";
3156
3157 my $upgrade_cmd = $cmd_vars;
3158 $upgrade_cmd .= "$samba_tool domain schemaupgrade $dcvars->{CONFIGURATION}";
3159 $upgrade_cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
3160
3161 my $repl_cmd = $cmd_vars;
3162 $repl_cmd .= "$samba_tool drs replicate $env->{SERVER} $dcvars->{SERVER}";
3163 $repl_cmd .= " $env->{CONFIGURATION}";
3164 $repl_cmd .= " CN=Schema,CN=Configuration,DC=schema,DC=samba,DC=example,DC=com";
3165 $repl_cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
3166
3167 unless (system($join_cmd) == 0) {
3168 warn("Join failed\n$join_cmd");
3169 return undef;
3170 }
3171
3172 $env->{DC_SERVER} = $dcvars->{SERVER};
3173 $env->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
3174 $env->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
3175 $env->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
3176
3177 # start samba for the new DC
3178 if (not defined($self->check_or_start($env, "standard"))) {
3179 return undef;
3180 }
3181
3182 unless (system($upgrade_cmd) == 0) {
3183 warn("Schema upgrade failed\n$upgrade_cmd");
3184 return undef;
3185 }
3186
3187 unless (system($repl_cmd) == 0) {
3188 warn("Post-update schema replication failed\n$repl_cmd");
3189 return undef;
3190 }
3191
3192 return $env;
3193 }
3194
3195 # Sets up a DC that's solely used to do a domain backup from. We then use the
3196 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
3197 # process will create a Samba DC that will actually start up.
3198 # We don't use the backup-DC for anything else because its domain will conflict
3199 # with the restore DC.
3200 sub setup_backupfromdc
3201 {
3202 my ($self, $path) = @_;
3203
3204 # If we didn't build with ADS, pretend this env was never available
3205 if (not $self->{target3}->have_ads()) {
3206 return "UNKNOWN";
3207 }
3208
3209 my $provision_args = ["--site=Backup-Site"];
3210
3211 my $env = $self->provision_ad_dc($path,
3212 "backupfromdc",
3213 "BACKUPDOMAIN",
3214 "backupdom.samba.example.com",
3215 undef,
3216 "samba kcc command = /bin/true",
3217 $provision_args);
3218 unless ($env) {
3219 return undef;
3220 }
3221
3222 if (not defined($self->check_or_start($env))) {
3223 return undef;
3224 }
3225
3226 my $upn_array = ["$env->{REALM}.upn"];
3227 my $spn_array = ["$env->{REALM}.spn"];
3228
3229 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3230 return undef;
3231 }
3232
3233 # Set up a dangling forward link to an expunged object
3234 #
3235 # We need this to ensure that the "samba-tool domain backup rename"
3236 # that is part of the creation of the labdc environment can
3237 # cope with this situation on the source DC.
3238
3239 if (not $self->write_ldb_file("$env->{PRIVATEDIR}/sam.ldb", "
3240 dn: ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
3241 objectclass: organizationalUnit
3242 -
3243
3244 dn: cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
3245 objectclass: msExchConfigurationContainer
3246 -
3247
3248 dn: cn=linkfrom,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
3249 objectclass: msExchConfigurationContainer
3250 addressBookRoots: cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com
3251 -
3252
3253 ")) {
3254 return undef;
3255 }
3256 my $ldbdel = Samba::bindir_path($self, "ldbdel");
3257 my $cmd = "$ldbdel -H $env->{PRIVATEDIR}/sam.ldb cn=linkto,ou=linktest,dc=backupdom,dc=samba,dc=example,dc=com";
3258
3259 unless(system($cmd) == 0) {
3260 warn("Failed to delete link target: \n$cmd");
3261 return undef;
3262 }
3263
3264 # Expunge will ensure that linkto is totally wiped from the DB
3265 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3266 $cmd = "$samba_tool domain tombstones expunge --tombstone-lifetime=0 $env->{CONFIGURATION}";
3267
3268 unless(system($cmd) == 0) {
3269 warn("Failed to expunge link target: \n$cmd");
3270 return undef;
3271 }
3272 return $env;
3273 }
3274
3275 # returns the server/user-auth params needed to run an online backup cmd
3276 sub get_backup_server_args
3277 {
3278 # dcvars contains the env info for the backup DC testenv
3279 my ($self, $dcvars) = @_;
3280 my $server = $dcvars->{DC_SERVER_IP};
3281 my $server_args = "--server=$server ";
3282 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
3283 $server_args .= " $dcvars->{CONFIGURATION}";
3284
3285 return $server_args;
3286 }
3287
3288 # Creates a backup of a running testenv DC
3289 sub create_backup
3290 {
3291 # note: dcvars contains the env info for the backup DC testenv
3292 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
3293
3294 # get all the env variables we pass in with the samba-tool command
3295 # Note: use the backupfrom-DC's krb5.conf to do the backup
3296 my $overwrite = undef;
3297 $overwrite->{KRB5_CONFIG} = $dcvars->{KRB5_CONFIG};
3298 my $cmd_env = $self->get_cmd_env_vars($env, $overwrite);
3299
3300 # use samba-tool to create a backup from the 'backupfromdc' DC
3301 my $cmd = "";
3302 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3303
3304 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
3305 $cmd .= " --targetdir=$backupdir";
3306
3307 print "Executing: $cmd\n";
3308 unless(system($cmd) == 0) {
3309 warn("Failed to create backup using: \n$cmd");
3310 return undef;
3311 }
3312
3313 # get the name of the backup file created
3314 opendir(DIR, $backupdir);
3315 my @files = grep(/\.tar/, readdir(DIR));
3316 closedir(DIR);
3317
3318 if(scalar @files != 1) {
3319 warn("Backup file not found in directory $backupdir\n");
3320 return undef;
3321 }
3322 my $backup_file = "$backupdir/$files[0]";
3323 print "Using backup file $backup_file...\n";
3324
3325 return $backup_file;
3326 }
3327
3328 # Restores a backup-file to populate a testenv for a new DC
3329 sub restore_backup_file
3330 {
3331 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
3332
3333 # pass the restore command the testenv's smb.conf that we've already
3334 # generated. But move it to a temp-dir first, so that the restore doesn't
3335 # overwrite it
3336 my $tmpdir = File::Temp->newdir();
3337 my $tmpconf = "$tmpdir/smb.conf";
3338 my $cmd = "cp $smbconf $tmpconf";
3339 unless(system($cmd) == 0) {
3340 warn("Failed to backup smb.conf using: \n$cmd");
3341 return -1;
3342 }
3343
3344 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3345 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
3346 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
3347
3348 print "Executing: $cmd\n";
3349 unless(system($cmd) == 0) {
3350 warn("Failed to restore backup using: \n$cmd");
3351 return -1;
3352 }
3353
3354 print "Restore complete\n";
3355 return 0
3356 }
3357
3358 # sets up the initial directory and returns the new testenv's env info
3359 # (without actually doing a 'domain join')
3360 sub prepare_dc_testenv
3361 {
3362 my ($self, $prefix, $dcname, $domain, $realm,
3363 $password, $conf_options, $dnsupdate_options) = @_;
3364
3365 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
3366 $dcname,
3367 $domain,
3368 $realm,
3369 undef,
3370 "2008",
3371 $password,
3372 undef,
3373 undef);
3374
3375 # the restore uses a slightly different state-dir location to other testenvs
3376 $ctx->{statedir} = "$ctx->{prefix}/state";
3377 push(@{$ctx->{directories}}, "$ctx->{statedir}");
3378
3379 # add support for sysvol/netlogon/tmp shares
3380 $ctx->{share} = "$ctx->{prefix}/share";
3381 push(@{$ctx->{directories}}, "$ctx->{share}");
3382 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
3383
3384 if (defined($dnsupdate_options)) {
3385 $ctx->{samba_dnsupdate} .= $dnsupdate_options;
3386 }
3387
3388 $ctx->{smb_conf_extra_options} = "
3389 $conf_options
3390
3391 # Some of the DCs based on this will be in FL 2016 domains, so
3392 # claim FL 2016 DC capability
3393 ad dc functional level = 2016
3394
3395 max xmit = 32K
3396 server max protocol = SMB2
3397 samba kcc command = /bin/true
3398 xattr_tdb:file = $ctx->{statedir}/xattr.tdb
3399
3400 [sysvol]
3401 path = $ctx->{statedir}/sysvol
3402 read only = no
3403
3404 [netlogon]
3405 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
3406 read only = no
3407
3408 [tmp]
3409 path = $ctx->{share}
3410 read only = no
3411 posix:sharedelay = 10000
3412 posix:oplocktimeout = 3
3413 posix:writetimeupdatedelay = 50000
3414
3415 [test1]
3416 path = $ctx->{share}/test1
3417 read only = no
3418 posix:sharedelay = 100000
3419 posix:oplocktimeout = 3
3420 posix:writetimeupdatedelay = 500000
3421 ";
3422
3423 my $env = $self->provision_raw_step1($ctx);
3424
3425 return ($env, $ctx);
3426 }
3427
3428
3429 # Set up a DC testenv solely by using the samba-tool domain backup/restore
3430 # commands. This proves that we can backup an online DC ('backupfromdc') and
3431 # use the backup file to create a valid, working samba DC.
3432 sub setup_restoredc
3433 {
3434 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3435 my ($self, $prefix, $dcvars) = @_;
3436 print "Preparing RESTORE DC...\n";
3437
3438 # we arbitrarily designate the restored DC as having SMBv1 disabled
3439 my $extra_conf = "
3440 server min protocol = SMB2
3441 client min protocol = SMB2
3442 prefork children = 1";
3443 my $dnsupdate_options = " --use-samba-tool --no-credentials";
3444
3445 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
3446 $dcvars->{DOMAIN},
3447 $dcvars->{REALM},
3448 $dcvars->{PASSWORD},
3449 $extra_conf,
3450 $dnsupdate_options);
3451
3452 # create a backup of the 'backupfromdc'
3453 my $backupdir = File::Temp->newdir();
3454 my $server_args = $self->get_backup_server_args($dcvars);
3455 my $backup_args = "online $server_args";
3456 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3457 $backup_args);
3458 unless($backup_file) {
3459 return undef;
3460 }
3461
3462 # restore the backup file to populate the restore-DC testenv
3463 my $restore_dir = abs_path($prefix);
3464 my $ret = $self->restore_backup_file($backup_file,
3465 "--newservername=$env->{SERVER}",
3466 $restore_dir, $env->{SERVERCONFFILE});
3467 unless ($ret == 0) {
3468 return undef;
3469 }
3470
3471 #
3472 # As we create the same domain as a clone
3473 # we need a separate resolv.conf!
3474 #
3475 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
3476 $ctx->{dns_ipv4} = $ctx->{ipv4};
3477 $ctx->{dns_ipv6} = $ctx->{ipv6};
3478 Samba::mk_resolv_conf($ctx);
3479 $env->{RESOLV_CONF} = $ctx->{resolv_conf};
3480
3481 # start samba for the restored DC
3482 if (not defined($self->check_or_start($env))) {
3483 return undef;
3484 }
3485
3486 return $env;
3487 }
3488
3489 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
3490 # restore commands. This proves that we can backup and rename an online DC
3491 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3492 sub setup_renamedc
3493 {
3494 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3495 my ($self, $prefix, $dcvars) = @_;
3496 print "Preparing RENAME DC...\n";
3497 my $extra_conf = "prefork children = 1";
3498
3499 my $realm = "renamedom.samba.example.com";
3500 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
3501 "RENAMEDOMAIN", $realm,
3502 $dcvars->{PASSWORD}, $extra_conf);
3503
3504 # create a backup of the 'backupfromdc' which renames the domain
3505 my $backupdir = File::Temp->newdir();
3506 my $server_args = $self->get_backup_server_args($dcvars);
3507 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3508 $backup_args .= " --backend-store=tdb";
3509 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3510 $backup_args);
3511 unless($backup_file) {
3512 return undef;
3513 }
3514
3515 # restore the backup file to populate the rename-DC testenv
3516 my $restore_dir = abs_path($prefix);
3517 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3518 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3519 $restore_dir, $env->{SERVERCONFFILE});
3520 unless ($ret == 0) {
3521 return undef;
3522 }
3523
3524 # start samba for the restored DC
3525 if (not defined($self->check_or_start($env))) {
3526 return undef;
3527 }
3528
3529 my $upn_array = ["$env->{REALM}.upn"];
3530 my $spn_array = ["$env->{REALM}.spn"];
3531
3532 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3533 return undef;
3534 }
3535
3536 return $env;
3537 }
3538
3539 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
3540 # restore commands. This proves that we do an offline backup of a local DC
3541 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
3542 sub setup_offlinebackupdc
3543 {
3544 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3545 my ($self, $prefix, $dcvars) = @_;
3546 print "Preparing OFFLINE BACKUP DC...\n";
3547 my $extra_conf = "prefork children = 1";
3548 my $dnsupdate_options = " --use-samba-tool --no-credentials";
3549
3550 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
3551 $dcvars->{DOMAIN},
3552 $dcvars->{REALM},
3553 $dcvars->{PASSWORD},
3554 $extra_conf,
3555 $dnsupdate_options);
3556
3557 # create an offline backup of the 'backupfromdc' target
3558 my $backupdir = File::Temp->newdir();
3559 my $cmd = "offline --configfile $dcvars->{SERVERCONFFILE}";
3560 my $backup_file = $self->create_backup($env, $dcvars,
3561 $backupdir, $cmd);
3562
3563 unless($backup_file) {
3564 return undef;
3565 }
3566
3567 # restore the backup file to populate the rename-DC testenv
3568 my $restore_dir = abs_path($prefix);
3569 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3570 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3571 $restore_dir, $env->{SERVERCONFFILE});
3572 unless ($ret == 0) {
3573 return undef;
3574 }
3575
3576 #
3577 # As we create the same domain as a clone
3578 # we need a separate resolv.conf!
3579 #
3580 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
3581 $ctx->{dns_ipv4} = $ctx->{ipv4};
3582 $ctx->{dns_ipv6} = $ctx->{ipv6};
3583 Samba::mk_resolv_conf($ctx);
3584 $env->{RESOLV_CONF} = $ctx->{resolv_conf};
3585
3586 # re-create the testenv's krb5.conf (the restore may have overwritten it)
3587 Samba::mk_krb5_conf($ctx);
3588
3589 # start samba for the restored DC
3590 if (not defined($self->check_or_start($env))) {
3591 return undef;
3592 }
3593
3594 return $env;
3595 }
3596
3597 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3598 # restore commands, using the --no-secrets option. This proves that we can
3599 # create a realistic lab environment from an online DC ('backupfromdc').
3600 sub setup_labdc
3601 {
3602 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3603 my ($self, $prefix, $dcvars) = @_;
3604 print "Preparing LAB-DOMAIN DC...\n";
3605 my $extra_conf = "prefork children = 1";
3606
3607 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3608 "LABDOMAIN",
3609 "labdom.samba.example.com",
3610 $dcvars->{PASSWORD}, $extra_conf);
3611
3612 # create a backup of the 'backupfromdc' which renames the domain and uses
3613 # the --no-secrets option to scrub any sensitive info
3614 my $backupdir = File::Temp->newdir();
3615 my $server_args = $self->get_backup_server_args($dcvars);
3616 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3617 $backup_args .= " --no-secrets --backend-store=$self->{default_ldb_backend}";
3618 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3619 $backup_args);
3620 unless($backup_file) {
3621 return undef;
3622 }
3623
3624 # restore the backup file to populate the lab-DC testenv
3625 my $restore_dir = abs_path($prefix);
3626 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3627 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3628 $restore_dir, $env->{SERVERCONFFILE});
3629 unless ($ret == 0) {
3630 return undef;
3631 }
3632
3633 # because we don't include any secrets in the backup, we need to reset the
3634 # admin user's password back to what the testenv expects
3635 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3636 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3637 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3638 $cmd .= " $env->{CONFIGURATION}";
3639
3640 unless(system($cmd) == 0) {
3641 warn("Failed to reset admin's password: \n$cmd");
3642 return undef;
3643 }
3644
3645 # start samba for the restored DC
3646 if (not defined($self->check_or_start($env))) {
3647 return undef;
3648 }
3649
3650 my $upn_array = ["$env->{REALM}.upn"];
3651 my $spn_array = ["$env->{REALM}.spn"];
3652
3653 if ($self->setup_namespaces($env, $upn_array, $spn_array) != 0) {
3654 return undef;
3655 }
3656
3657 return $env;
3658 }
3659
3660 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3661 sub get_backup_domain_realm
3662 {
3663 my ($self, $backup_file) = @_;
3664
3665 print "Determining REALM/DOMAIN values in backup...\n";
3666
3667 # The backup will have the correct domain/realm values in the smb.conf.
3668 # So we can work out the env variables the testenv should use based on
3669 # that. Let's start by extracting the smb.conf
3670 my $tar = Archive::Tar->new($backup_file);
3671 my $tmpdir = File::Temp->newdir();
3672 my $smbconf = "$tmpdir/smb.conf";
3673
3674 # note that the filepaths within the tar-file differ slightly for online
3675 # and offline backups
3676 if ($tar->contains_file("etc/smb.conf")) {
3677 $tar->extract_file("etc/smb.conf", $smbconf);
3678 } elsif ($tar->contains_file("./etc/smb.conf")) {
3679 $tar->extract_file("./etc/smb.conf", $smbconf);
3680 } else {
3681 warn("Could not find smb.conf in $backup_file");
3682 return undef, undef;
3683 }
3684
3685 # make sure we don't try to create locks/sockets in the default install
3686 # location (i.e. /usr/local/samba/)
3687 my $options = "--option=\"private dir = $tmpdir\"";
3688 $options .= " --option=\"lock dir = $tmpdir\"";
3689
3690 # now use testparm to read the values we're interested in
3691 my $testparm = Samba::bindir_path($self, "testparm");
3692 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP $options`;
3693 my $realm = `$testparm $smbconf -sl --parameter-name=REALM $options`;
3694 chomp $realm;
3695 chomp $domain;
3696 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3697
3698 return ($domain, $realm);
3699 }
3700
3701 # This spins up a custom testenv that can be based on any backup-file you want.
3702 # This is just intended for manual testing (rather than automated test-cases)
3703 sub setup_customdc
3704 {
3705 my ($self, $prefix) = @_;
3706 print "Preparing CUSTOM RESTORE DC...\n";
3707 my $dc_name = "customdc";
3708 my $password = "locDCpass1";
3709 my $backup_file = $ENV{'BACKUP_FILE'};
3710 my $dnsupdate_options = " --use-samba-tool --no-credentials";
3711
3712 # user must specify a backup file to restore via an ENV variable, i.e.
3713 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3714 if (not defined($backup_file)) {
3715 warn("Please specify BACKUP_FILE");
3716 return undef;
3717 }
3718
3719 # work out the correct domain/realm env values from the backup-file
3720 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3721 if ($domain eq '' or $realm eq '') {
3722 warn("Could not determine domain or realm");
3723 return undef;
3724 }
3725
3726 # create a placeholder directory and smb.conf, as well as the env vars.
3727 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3728 $domain, $realm, $password, "",
3729 $dnsupdate_options);
3730
3731 # restore the specified backup file to populate the testenv
3732 my $restore_dir = abs_path($prefix);
3733 my $ret = $self->restore_backup_file($backup_file,
3734 "--newservername=$env->{SERVER}",
3735 $restore_dir, $env->{SERVERCONFFILE});
3736 unless ($ret == 0) {
3737 return undef;
3738 }
3739
3740 #
3741 # As we create the same domain as a clone
3742 # we need a separate resolv.conf!
3743 #
3744 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
3745 $ctx->{dns_ipv4} = $ctx->{ipv4};
3746 $ctx->{dns_ipv6} = $ctx->{ipv6};
3747 Samba::mk_resolv_conf($ctx);
3748 $env->{RESOLV_CONF} = $ctx->{resolv_conf};
3749
3750 # Change the admin password to the testenv default, just in case it's
3751 # different, or in case this was a --no-secrets backup
3752 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3753 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3754 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3755 $cmd .= " $env->{CONFIGURATION}";
3756
3757 unless(system($cmd) == 0) {
3758 warn("Failed to reset admin's password: \n$cmd");
3759 return undef;
3760 }
3761
3762 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3763 # if the backup-file was an offline backup)
3764 Samba::mk_krb5_conf($ctx);
3765
3766 # start samba for the restored DC
3767 if (not defined($self->check_or_start($env))) {
3768 return undef;
3769 }
3770
3771 # if this was a backup-rename, then we may need to setup namespaces
3772 my $upn_array = ["$env->{REALM}.upn"];
3773 my $spn_array = ["$env->{REALM}.spn"];
3774
3775 return $env;
3776 }
3777
3778 sub setup_none
3779 {
3780 my ($self, $path) = @_;
3781
3782 my $ret = {
3783 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
3784 SAMBA_PID => -1,
3785 }
3786 }
3787
3788 1;