selftest: Only set netbios aliases for the ad_member env
[samba.git] / selftest / target / Samba3.pm
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
5
6 # NOTE: Refer to the README for more details about the various testenvs,
7 # and tips about adding new testenvs.
8
9 package Samba3;
10
11 use strict;
12 use warnings;
13 use Cwd qw(abs_path);
14 use FindBin qw($RealBin);
15 use POSIX;
16 use target::Samba;
17 use File::Path 'remove_tree';
18
19 sub return_alias_env
20 {
21         my ($self, $path, $env) = @_;
22
23         # just an alias
24         return $env;
25 }
26
27 sub have_ads($) {
28         my ($self) = @_;
29         my $found_ads = 0;
30         my $smbd_build_options = Samba::bindir_path($self, "smbd") . " --configfile=/dev/null -b|";
31         open(IN, $smbd_build_options) or die("Unable to run $smbd_build_options: $!");
32
33         while (<IN>) {
34                 if (/WITH_ADS/) {
35                        $found_ads = 1;
36                 }
37         }
38         close IN;
39
40         # If we were not built with ADS support, pretend we were never even available
41         print "smbd does not have ADS support\n" unless $found_ads;
42         return $found_ads;
43 }
44
45 # return smb.conf parameters applicable to @path, based on the underlying
46 # filesystem type
47 sub get_fs_specific_conf($$)
48 {
49         my ($self, $path) = @_;
50         my $mods = "";
51         my $stat_out = `stat --file-system $path` or return "";
52
53         if ($stat_out =~ m/Type:\s+btrfs/) {
54                 $mods .= "streams_xattr btrfs";
55         }
56
57         if ($mods) {
58                 return "vfs objects = $mods";
59         }
60
61         return '';
62 }
63
64 sub new($$) {
65         my ($classname, $SambaCtx, $bindir, $srcdir, $server_maxtime) = @_;
66         my $self = { vars => {},
67                      SambaCtx => $SambaCtx,
68                      bindir => $bindir,
69                      srcdir => $srcdir,
70                      server_maxtime => $server_maxtime
71         };
72         bless $self;
73         return $self;
74 }
75
76 sub teardown_env($$)
77 {
78         my ($self, $envvars) = @_;
79
80         if (defined($envvars->{CTDB_PREFIX})) {
81                 $self->teardown_env_ctdb($envvars);
82         } else {
83                 $self->teardown_env_samba($envvars);
84         }
85
86         return;
87 }
88
89 sub teardown_env_samba($$)
90 {
91         my ($self, $envvars) = @_;
92         my $count = 0;
93
94         # This should cause smbd to terminate gracefully
95         close($envvars->{STDIN_PIPE});
96
97         my $smbdpid = $envvars->{SMBD_TL_PID};
98         my $nmbdpid = $envvars->{NMBD_TL_PID};
99         my $winbinddpid = $envvars->{WINBINDD_TL_PID};
100
101         # This should give it time to write out the gcov data
102         until ($count > 20) {
103             my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
104             my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
105             my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
106             if ($smbdchild == -1
107                 && $nmbdchild == -1
108                 && $winbinddchild == -1) {
109                 last;
110             }
111             sleep(1);
112             $count++;
113         }
114
115         if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
116             return;
117         }
118
119         $self->stop_sig_term($smbdpid);
120         $self->stop_sig_term($nmbdpid);
121         $self->stop_sig_term($winbinddpid);
122
123         $count = 0;
124         until ($count > 10) {
125             my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
126             my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
127             my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
128             if ($smbdchild == -1
129                 && $nmbdchild == -1
130                 && $winbinddchild == -1) {
131                 last;
132             }
133             sleep(1);
134             $count++;
135         }
136
137         if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
138             return;
139         }
140
141         warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
142         $self->stop_sig_kill($smbdpid);
143         $self->stop_sig_kill($nmbdpid);
144         $self->stop_sig_kill($winbinddpid);
145
146         return 0;
147 }
148
149 sub teardown_env_ctdb($$)
150 {
151         my ($self, $data) = @_;
152
153         if (defined($data->{SAMBA_NODES})) {
154                 my $num_nodes = $data->{NUM_NODES};
155                 my $nodes = $data->{SAMBA_NODES};
156
157                 for (my $i = 0; $i < $num_nodes; $i++) {
158                         if (defined($nodes->[$i])) {
159                                 $self->teardown_env_samba($nodes->[$i]);
160                         }
161                 }
162         }
163
164         close($data->{CTDB_STDIN_PIPE});
165
166         if (not defined($data->{SAMBA_NODES})) {
167                 # Give waiting children time to exit
168                 sleep(5);
169         }
170
171         return 0;
172 }
173
174 sub getlog_env_app($$$)
175 {
176         my ($self, $envvars, $name) = @_;
177
178         my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
179         my $out = $title;
180
181         open(LOG, "<".$envvars->{$name."_TEST_LOG"});
182
183         seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
184         while (<LOG>) {
185                 $out .= $_;
186         }
187         $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
188         close(LOG);
189
190         return "" if $out eq $title;
191  
192         return $out;
193 }
194
195 sub getlog_env($$)
196 {
197         my ($self, $envvars) = @_;
198         my $ret = "";
199
200         $ret .= $self->getlog_env_app($envvars, "SMBD");
201         $ret .= $self->getlog_env_app($envvars, "NMBD");
202         $ret .= $self->getlog_env_app($envvars, "WINBINDD");
203
204         return $ret;
205 }
206
207 sub check_env($$)
208 {
209         my ($self, $envvars) = @_;
210
211         my $childpid = waitpid(-1, WNOHANG);
212
213         # TODO ...
214         return 1;
215 }
216
217 # Declare the environments Samba3 makes available.
218 # To be set up, they will be called as
219 #   samba3->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
220 %Samba3::ENV_DEPS = (
221         # name              => [dep_1, dep_2, ...],
222         nt4_dc              => [],
223         nt4_dc_smb1         => [],
224         nt4_dc_smb1_done    => ["nt4_dc_smb1"],
225         nt4_dc_schannel     => [],
226
227         simpleserver        => [],
228         fileserver          => [],
229         fileserver_smb1     => [],
230         fileserver_smb1_done => ["fileserver_smb1"],
231         maptoguest          => [],
232         ktest               => [],
233
234         nt4_member          => ["nt4_dc"],
235
236         ad_member           => ["ad_dc", "fl2008r2dc", "fl2003dc"],
237         ad_member_rfc2307   => ["ad_dc_ntvfs"],
238         ad_member_idmap_rid => ["ad_dc"],
239         ad_member_idmap_ad  => ["fl2008r2dc"],
240         ad_member_fips      => ["ad_dc_fips"],
241         ad_member_offlogon  => ["ad_dc"],
242
243         clusteredmember => ["nt4_dc"],
244 );
245
246 %Samba3::ENV_DEPS_POST = ();
247
248 sub setup_nt4_dc
249 {
250         my ($self, $path, $more_conf, $server) = @_;
251
252         print "PROVISIONING NT4 DC...";
253
254         my $nt4_dc_options = "
255         domain master = yes
256         domain logons = yes
257         lanman auth = yes
258         ntlm auth = yes
259         raw NTLMv2 auth = yes
260         server schannel = auto
261
262         rpc_server:epmapper = external
263         rpc_server:spoolss = external
264         rpc_server:lsarpc = external
265         rpc_server:samr = external
266         rpc_server:netlogon = external
267         rpc_server:register_embedded_np = yes
268         rpc_server:FssagentRpc = external
269
270         rpc_daemon:epmd = fork
271         rpc_daemon:spoolssd = fork
272         rpc_daemon:lsasd = fork
273         rpc_daemon:fssd = fork
274         fss: sequence timeout = 1
275         check parent directory delete on close = yes
276 ";
277
278         if (defined($more_conf)) {
279                 $nt4_dc_options = $nt4_dc_options . $more_conf;
280         }
281         if (!defined($server)) {
282                 $server = "LOCALNT4DC2";
283         }
284         my $vars = $self->provision(
285             prefix => $path,
286             domain => "SAMBA-TEST",
287             server => $server,
288             password => "localntdc2pass",
289             extra_options => $nt4_dc_options);
290
291         $vars or return undef;
292
293         if (not $self->check_or_start(
294                 env_vars => $vars,
295                 nmbd => "yes",
296                 winbindd => "yes",
297                 smbd => "yes")) {
298                return undef;
299         }
300
301         $vars->{DOMSID} = $vars->{SAMSID};
302         $vars->{DC_SERVER} = $vars->{SERVER};
303         $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
304         $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
305         $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
306         $vars->{DC_USERNAME} = $vars->{USERNAME};
307         $vars->{DC_PASSWORD} = $vars->{PASSWORD};
308
309         return $vars;
310 }
311
312 sub setup_nt4_dc_smb1
313 {
314         my ($self, $path) = @_;
315         my $conf = "
316 [global]
317         client min protocol = CORE
318         server min protocol = LANMAN1
319 ";
320         return $self->setup_nt4_dc($path, $conf, "LCLNT4DC2SMB1");
321 }
322
323 sub setup_nt4_dc_smb1_done
324 {
325         my ($self, $path, $dep_env) = @_;
326         return $self->return_alias_env($path, $dep_env);
327 }
328
329 sub setup_nt4_dc_schannel
330 {
331         my ($self, $path) = @_;
332
333         print "PROVISIONING NT4 DC WITH SERVER SCHANNEL ...";
334
335         my $pdc_options = "
336         domain master = yes
337         domain logons = yes
338         lanman auth = yes
339
340         rpc_server:epmapper = external
341         rpc_server:spoolss = external
342         rpc_server:lsarpc = external
343         rpc_server:samr = external
344         rpc_server:netlogon = external
345         rpc_server:register_embedded_np = yes
346
347         rpc_daemon:epmd = fork
348         rpc_daemon:spoolssd = fork
349         rpc_daemon:lsasd = fork
350
351         server schannel = yes
352         # used to reproduce bug #12772
353         server max protocol = SMB2_02
354 ";
355
356         my $vars = $self->provision(
357             prefix => $path,
358             domain => "NT4SCHANNEL",
359             server => "LOCALNT4DC9",
360             password => "localntdc9pass",
361             extra_options => $pdc_options);
362
363         $vars or return undef;
364
365         if (not $self->check_or_start(
366                 env_vars => $vars,
367                 nmbd => "yes",
368                 winbindd => "yes",
369                 smbd => "yes")) {
370                return undef;
371         }
372
373         $vars->{DOMSID} = $vars->{SAMSID};
374         $vars->{DC_SERVER} = $vars->{SERVER};
375         $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
376         $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
377         $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
378         $vars->{DC_USERNAME} = $vars->{USERNAME};
379         $vars->{DC_PASSWORD} = $vars->{PASSWORD};
380
381         return $vars;
382 }
383
384 sub setup_nt4_member
385 {
386         my ($self, $prefix, $nt4_dc_vars) = @_;
387         my $count = 0;
388         my $rc;
389
390         print "PROVISIONING MEMBER...";
391
392         my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
393         if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} // '' eq "1") {
394                 $require_mutexes = "";
395         }
396
397         my $member_options = "
398         security = domain
399         dbwrap_tdb_mutexes:* = yes
400         ${require_mutexes}
401 ";
402         my $ret = $self->provision(
403             prefix => $prefix,
404             domain => $nt4_dc_vars->{DOMAIN},
405             server => "LOCALNT4MEMBER3",
406             password => "localnt4member3pass",
407             extra_options => $member_options);
408
409         $ret or return undef;
410
411         my $nmblookup = Samba::bindir_path($self, "nmblookup");
412         do {
413                 print "Waiting for the LOGON SERVER registration ...\n";
414                 $rc = system("$nmblookup $ret->{CONFIGURATION} $ret->{DOMAIN}\#1c");
415                 if ($rc != 0) {
416                         sleep(1);
417                 }
418                 $count++;
419         } while ($rc != 0 && $count < 10);
420         if ($count == 10) {
421                 print "NMBD not reachable after 10 retries\n";
422                 teardown_env($self, $ret);
423                 return 0;
424         }
425
426         my $net = Samba::bindir_path($self, "net");
427         # Add hosts file for name lookups
428         my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
429         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
430         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
431         $cmd .= "$net rpc join $ret->{CONFIGURATION} $nt4_dc_vars->{DOMAIN} member";
432         $cmd .= " -U$nt4_dc_vars->{USERNAME}\%$nt4_dc_vars->{PASSWORD}";
433
434         if (system($cmd) != 0) {
435             warn("Join failed\n$cmd");
436             return undef;
437         }
438
439         # Add hosts file for name lookups
440         $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
441         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
442         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
443         $cmd .= "$net $ret->{CONFIGURATION} primarytrust dumpinfo | grep -q 'REDACTED SECRET VALUES'";
444
445         if (system($cmd) != 0) {
446             warn("check failed\n$cmd");
447             return undef;
448         }
449
450         if (not $self->check_or_start(
451                 env_vars => $ret,
452                 nmbd => "yes",
453                 winbindd => "yes",
454                 smbd => "yes")) {
455                return undef;
456         }
457
458         $ret->{DOMSID} = $nt4_dc_vars->{DOMSID};
459         $ret->{DC_SERVER} = $nt4_dc_vars->{SERVER};
460         $ret->{DC_SERVER_IP} = $nt4_dc_vars->{SERVER_IP};
461         $ret->{DC_SERVER_IPV6} = $nt4_dc_vars->{SERVER_IPV6};
462         $ret->{DC_NETBIOSNAME} = $nt4_dc_vars->{NETBIOSNAME};
463         $ret->{DC_USERNAME} = $nt4_dc_vars->{USERNAME};
464         $ret->{DC_PASSWORD} = $nt4_dc_vars->{PASSWORD};
465
466         return $ret;
467 }
468
469 sub setup_clusteredmember
470 {
471         my ($self, $prefix, $nt4_dc_vars) = @_;
472         my $count = 0;
473         my $rc;
474         my @retvals = ();
475         my $ret;
476
477         print "PROVISIONING CLUSTEREDMEMBER...\n";
478
479         my $prefix_abs = abs_path($prefix);
480         mkdir($prefix_abs, 0777);
481
482         my $server_name = "CLUSTEREDMEMBER";
483
484         my $ctdb_data = $self->setup_ctdb($prefix);
485
486         if (not $ctdb_data) {
487                 print "No ctdb data\n";
488                 return undef;
489         }
490
491         print "PROVISIONING CLUSTERED SAMBA...\n";
492
493         my $num_nodes = $ctdb_data->{NUM_NODES};
494         my $nodes = $ctdb_data->{CTDB_NODES};
495
496         # Enable cleanup of earlier nodes if a later node fails
497         $ctdb_data->{SAMBA_NODES} = \@retvals;
498
499         for (my $i = 0; $i < $num_nodes; $i++) {
500                 my $node = $nodes->[$i];
501                 my $socket = $node->{SOCKET_FILE};
502                 my $server_name = $node->{SERVER_NAME};
503                 my $pub_iface = $node->{SOCKET_WRAPPER_DEFAULT_IFACE};
504                 my $node_prefix = $node->{NODE_PREFIX};
505
506                 print "NODE_PREFIX=${node_prefix}\n";
507                 print "SOCKET=${socket}\n";
508
509                 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
510                 if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} // '' eq "1") {
511                         $require_mutexes = "" ;
512                 }
513
514                 my $member_options = "
515        security = domain
516        server signing = on
517        clustering = yes
518        ctdbd socket = ${socket}
519        dbwrap_tdb_mutexes:* = yes
520        ${require_mutexes}
521 ";
522
523                 my $node_ret = $self->provision(
524                     prefix => "$node_prefix",
525                     domain => $nt4_dc_vars->{DOMAIN},
526                     server => "$server_name",
527                     password => "clustermember8pass",
528                     netbios_name => "CLUSTEREDMEMBER",
529                     share_dir => "${prefix_abs}/shared",
530                     extra_options => $member_options,
531                     no_delete_prefix => 1);
532                 if (not $node_ret) {
533                         print "Provision node $i failed\n";
534                         teardown_env($self, $ctdb_data);
535                         return undef;
536                 }
537
538                 my $nmblookup = Samba::bindir_path($self, "nmblookup");
539                 do {
540                         print "Waiting for the LOGON SERVER registration ...\n";
541                         $rc = system("$nmblookup $node_ret->{CONFIGURATION} " .
542                                      "$node_ret->{DOMAIN}\#1c");
543                         if ($rc != 0) {
544                                 sleep(1);
545                         }
546                         $count++;
547                 } while ($rc != 0 && $count < 10);
548
549                 if ($count == 10) {
550                         print "NMBD not reachable after 10 retries\n";
551                         teardown_env($self, $node_ret);
552                         teardown_env($self, $ctdb_data);
553                         return undef;
554                 }
555
556                 push(@retvals, $node_ret);
557         }
558
559         $ret = {%$ctdb_data, %{$retvals[0]}};
560
561         my $net = Samba::bindir_path($self, "net");
562         my $cmd = "";
563         $cmd .= "UID_WRAPPER_ROOT=1 ";
564         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
565         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
566         $cmd .= "$net join $ret->{CONFIGURATION} $nt4_dc_vars->{DOMAIN} member";
567         $cmd .= " -U$nt4_dc_vars->{USERNAME}\%$nt4_dc_vars->{PASSWORD}";
568
569         if (system($cmd) != 0) {
570                 warn("Join failed\n$cmd");
571                 teardown_env($self, $ret);
572                 return undef;
573         }
574
575         for (my $i=0; $i<@retvals; $i++) {
576                 my $node_provision = $retvals[$i];
577                 my $ok;
578                 $ok = $self->check_or_start(
579                     env_vars => $node_provision,
580                     winbindd => "yes",
581                     smbd => "yes",
582                     child_cleanup => sub {
583                         map {
584                             my $fh = $_->{STDIN_PIPE};
585                             close($fh) if defined($fh);
586                         } @retvals });
587                 if (not $ok) {
588                         teardown_env($self, $ret);
589                         return undef;
590                 }
591         }
592
593         #
594         # Build a unclist for every share
595         #
596         unless (open(NODES, "<$ret->{CTDB_NODES_FILE}")) {
597                 warn("Unable to open CTDB nodes file");
598                 teardown_env($self, $ret);
599                 return undef;
600         }
601         my @nodes = <NODES>;
602         close(NODES);
603         chomp @nodes;
604
605         my $conffile = $ret->{SERVERCONFFILE};
606         $cmd = "";
607         $cmd .= 'sed -n -e \'s|^\[\(.*\)\]$|\1|p\'';
608         $cmd .= " \"$conffile\"";
609         $cmd .= " | grep -vx 'global'";
610
611         my @shares = `$cmd`;
612         $rc = $?;
613         if ($rc != 0) {
614                 warn("Listing shares failed\n$cmd");
615                 teardown_env($self, $ret);
616                 return undef;
617         }
618         chomp @shares;
619
620         my $unclistdir = "${prefix_abs}/unclists";
621         mkdir($unclistdir, 0777);
622         foreach my $share (@shares) {
623                 my $l = "${unclistdir}/${share}.txt";
624                 unless (open(UNCLIST, ">${l}")) {
625                         warn("Unable to open UNC list ${l}");
626                         teardown_env($self, $ret);
627                         return undef;
628                 }
629                 foreach my $node (@nodes) {
630                         print UNCLIST "//${node}/${share}\n";
631                 }
632                 close(UNCLIST);
633         }
634
635         $ret->{DOMSID} = $nt4_dc_vars->{DOMSID};
636         $ret->{DC_SERVER} = $nt4_dc_vars->{SERVER};
637         $ret->{DC_SERVER_IP} = $nt4_dc_vars->{SERVER_IP};
638         $ret->{DC_SERVER_IPV6} = $nt4_dc_vars->{SERVER_IPV6};
639         $ret->{DC_NETBIOSNAME} = $nt4_dc_vars->{NETBIOSNAME};
640         $ret->{DC_USERNAME} = $nt4_dc_vars->{USERNAME};
641         $ret->{DC_PASSWORD} = $nt4_dc_vars->{PASSWORD};
642
643         return $ret;
644 }
645
646 sub provision_ad_member
647 {
648         my ($self,
649             $prefix,
650             $machine_account,
651             $dcvars,
652             $trustvars_f,
653             $trustvars_e,
654             $force_fips_mode,
655             $offline_logon) = @_;
656
657         my $prefix_abs = abs_path($prefix);
658         my @dirs = ();
659
660         mkdir($prefix_abs, 0777);
661
662         my $share_dir="$prefix_abs/share";
663         push(@dirs, $share_dir);
664
665         my $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}";
666         push(@dirs, $substitution_path);
667
668         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/U_alice";
669         push(@dirs, $substitution_path);
670
671         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/U_alice/G_domain users";
672         push(@dirs, $substitution_path);
673
674         # Using '/' as the winbind separator is a bad idea ...
675         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}";
676         push(@dirs, $substitution_path);
677
678         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice";
679         push(@dirs, $substitution_path);
680
681         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice/g_$dcvars->{DOMAIN}";
682         push(@dirs, $substitution_path);
683
684         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice/g_$dcvars->{DOMAIN}/domain users";
685         push(@dirs, $substitution_path);
686
687         my $option_offline_logon = "no";
688         if (defined($offline_logon)) {
689                 $option_offline_logon = "yes";
690         }
691
692         my $netbios_aliases = "";
693         if ($machine_account eq "LOCALADMEMBER") {
694                 $netbios_aliases = "netbios aliases = foo bar";
695         }
696
697         my $member_options = "
698         security = ads
699         workgroup = $dcvars->{DOMAIN}
700         realm = $dcvars->{REALM}
701         $netbios_aliases
702         template homedir = /home/%D/%G/%U
703         auth event notification = true
704         password server = $dcvars->{SERVER}
705         winbind scan trusted domains = no
706         winbind use krb5 enterprise principals = yes
707         winbind offline logon = $option_offline_logon
708
709         allow dcerpc auth level connect:lsarpc = yes
710         dcesrv:max auth states = 8
711
712         rpc_server:epmapper = external
713         rpc_server:lsarpc = external
714         rpc_server:samr = external
715         rpc_server:netlogon = disabled
716         rpc_server:register_embedded_np = yes
717
718         rpc_daemon:epmd = fork
719         rpc_daemon:lsasd = fork
720
721 [sub_dug]
722         path = $share_dir/D_%D/U_%U/G_%G
723         writeable = yes
724
725 [sub_dug2]
726         path = $share_dir/D_%D/u_%u/g_%g
727         writeable = yes
728
729 [sub_valid_users]
730         path = $share_dir
731         valid users = ADDOMAIN/%U
732
733 [sub_valid_users_domain]
734     path = $share_dir
735     valid users = %D/%U
736
737 [sub_valid_users_group]
738     path = $share_dir
739     valid users = \@$dcvars->{DOMAIN}/%G
740
741 [valid_users]
742     path = $share_dir
743     valid users = $dcvars->{DOMAIN}/$dcvars->{DC_USERNAME}
744
745 [valid_users_group]
746     path = $share_dir
747     valid users = \"\@$dcvars->{DOMAIN}/domain users\"
748
749 [valid_users_unix_group]
750     path = $share_dir
751     valid users = \"+$dcvars->{DOMAIN}/domain users\"
752
753 [valid_users_unix_nis_group]
754     path = $share_dir
755     valid users = \"+&$dcvars->{DOMAIN}/domain users\"
756
757 [valid_users_nis_unix_group]
758     path = $share_dir
759     valid users = \"&+$dcvars->{DOMAIN}/domain users\"
760
761 [invalid_users]
762     path = $share_dir
763     invalid users = $dcvars->{DOMAIN}/$dcvars->{DC_USERNAME}
764
765 [valid_and_invalid_users]
766     path = $share_dir
767     valid users = $dcvars->{DOMAIN}/$dcvars->{DC_USERNAME} $dcvars->{DOMAIN}/alice
768     invalid users = $dcvars->{DOMAIN}/$dcvars->{DC_USERNAME}
769 ";
770
771         my $ret = $self->provision(
772             prefix => $prefix,
773             domain => $dcvars->{DOMAIN},
774             realm => $dcvars->{REALM},
775             server => $machine_account,
776             password => "loCalMemberPass",
777             extra_options => $member_options,
778             resolv_conf => $dcvars->{RESOLV_CONF});
779
780         $ret or return undef;
781
782         mkdir($_, 0777) foreach(@dirs);
783
784         close(USERMAP);
785         $ret->{DOMAIN} = $dcvars->{DOMAIN};
786         $ret->{REALM} = $dcvars->{REALM};
787         $ret->{DOMSID} = $dcvars->{DOMSID};
788
789         my $ctx;
790         $ctx = {};
791         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
792         $ctx->{domain} = $dcvars->{DOMAIN};
793         $ctx->{realm} = $dcvars->{REALM};
794         $ctx->{dnsname} = lc($dcvars->{REALM});
795         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
796         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
797         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
798         Samba::mk_krb5_conf($ctx, "");
799
800         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
801
802         if (defined($force_fips_mode)) {
803                 $ret->{GNUTLS_FORCE_FIPS_MODE} = "1";
804                 $ret->{OPENSSL_FORCE_FIPS_MODE} = "1";
805         }
806
807         my $net = Samba::bindir_path($self, "net");
808         # Add hosts file for name lookups
809         my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
810         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
811         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
812                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
813         } else {
814                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
815         }
816         if (defined($force_fips_mode)) {
817                 $cmd .= "GNUTLS_FORCE_FIPS_MODE=1 ";
818                 $cmd .= "OPENSSL_FORCE_FIPS_MODE=1 ";
819         }
820         $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
821         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
822         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
823         $cmd .= "$net join $ret->{CONFIGURATION}";
824         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD} --use-kerberos=required";
825
826         if (system($cmd) != 0) {
827             warn("Join failed\n$cmd");
828             return undef;
829         }
830
831         # We need world access to this share, as otherwise the domain
832         # administrator from the AD domain provided by Samba4 can't
833         # access the share for tests.
834         chmod 0777, "$prefix/share";
835
836         if (defined($offline_logon)) {
837                 my $wbinfo = Samba::bindir_path($self, "wbinfo");
838
839                 if (not $self->check_or_start(
840                         env_vars => $ret,
841                         winbindd => "yes")) {
842                         return undef;
843                 }
844
845                 # Fill samlogoncache for alice
846                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
847                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
848                 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
849                 $cmd .= "$wbinfo --pam-logon=ADDOMAIN/alice%Secret007";
850                 if (system($cmd) != 0) {
851                         warn("Filling the cache failed\n$cmd");
852                         return undef;
853                 }
854
855                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
856                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
857                 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
858                 $cmd .= "$wbinfo --ccache-save=ADDOMAIN/alice%Secret007";
859                 if (system($cmd) != 0) {
860                         warn("Filling the cache failed\n$cmd");
861                         return undef;
862                 }
863
864                 # Fill samlogoncache for bob
865                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
866                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
867                 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
868                 $cmd .= "$wbinfo --pam-logon=ADDOMAIN/bob%Secret007";
869                 if (system($cmd) != 0) {
870                         warn("Filling the cache failed\n$cmd");
871                         return undef;
872                 }
873
874                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
875                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
876                 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
877                 $cmd .= "$wbinfo --ccache-save=ADDOMAIN/bob%Secret007";
878                 if (system($cmd) != 0) {
879                         warn("Filling the cache failed\n$cmd");
880                         return undef;
881                 }
882
883                 # Set windindd offline
884                 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
885                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
886                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
887                 $cmd .= "UID_WRAPPER_ROOT='1' ";
888                 $cmd .= "$smbcontrol $ret->{CONFIGURATION} winbindd offline";
889                 if (system($cmd) != 0) {
890                         warn("Setting winbindd offline failed\n$cmd");
891                         return undef;
892                 }
893
894                 # Validate the offline cache
895                 my $smbcontrol = Samba::bindir_path($self, "smbcontrol");
896                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
897                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
898                 $cmd .= "UID_WRAPPER_ROOT='1' ";
899                 $cmd .= "$smbcontrol $ret->{CONFIGURATION} winbindd validate-cache";
900                 if (system($cmd) != 0) {
901                         warn("Validation of winbind credential cache failed\n$cmd");
902                         teardown_env($self, $ret);
903                         return undef;
904                 }
905
906                 # Shut down winbindd
907                 teardown_env($self, $ret);
908
909                 ### Change SOCKET_WRAPPER_DIR so it can't connect to AD
910                 my $swrap_env = $ENV{SOCKET_WRAPPER_DIR};
911                 $ENV{SOCKET_WRAPPER_DIR} = "$prefix_abs";
912
913                 # Start winbindd in offline mode
914                 if (not $self->check_or_start(
915                         env_vars => $ret,
916                         winbindd => "yes",
917                         skip_wait => 1)) {
918                         return undef;
919                 }
920
921                 # Set socket dir again
922                 $ENV{SOCKET_WRAPPER_DIR} = $swrap_env;
923
924                 print "checking for winbindd\n";
925                 my $count = 0;
926                 my $rc = 0;
927                 $cmd = "NSS_WRAPPER_PASSWD='$ret->{NSS_WRAPPER_PASSWD}' ";
928                 $cmd .= "NSS_WRAPPER_GROUP='$ret->{NSS_WRAPPER_GROUP}' ";
929                 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
930                 $cmd .= "$wbinfo --ping";
931
932                 do {
933                         $rc = system($cmd);
934                         if ($rc != 0) {
935                                 sleep(1);
936                         }
937                         $count++;
938                 } while ($rc != 0 && $count < 20);
939                 if ($count == 20) {
940                         print "WINBINDD not reachable after 20 seconds\n";
941                         teardown_env($self, $ret);
942                         return undef;
943                 }
944         } else {
945                 if (not $self->check_or_start(
946                         env_vars => $ret,
947                         nmbd => "yes",
948                         winbindd => "yes",
949                         smbd => "yes")) {
950                         return undef;
951                 }
952         }
953
954         $ret->{DC_SERVER} = $dcvars->{SERVER};
955         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
956         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
957         $ret->{DC_SERVERCONFFILE} = $dcvars->{SERVERCONFFILE};
958         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
959         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
960         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
961
962         # forest trust
963         $ret->{TRUST_F_BOTH_SERVER} = $trustvars_f->{SERVER};
964         $ret->{TRUST_F_BOTH_SERVER_IP} = $trustvars_f->{SERVER_IP};
965         $ret->{TRUST_F_BOTH_SERVER_IPV6} = $trustvars_f->{SERVER_IPV6};
966         $ret->{TRUST_F_BOTH_NETBIOSNAME} = $trustvars_f->{NETBIOSNAME};
967         $ret->{TRUST_F_BOTH_USERNAME} = $trustvars_f->{USERNAME};
968         $ret->{TRUST_F_BOTH_PASSWORD} = $trustvars_f->{PASSWORD};
969         $ret->{TRUST_F_BOTH_DOMAIN} = $trustvars_f->{DOMAIN};
970         $ret->{TRUST_F_BOTH_REALM} = $trustvars_f->{REALM};
971
972         # external trust
973         $ret->{TRUST_E_BOTH_SERVER} = $trustvars_e->{SERVER};
974         $ret->{TRUST_E_BOTH_SERVER_IP} = $trustvars_e->{SERVER_IP};
975         $ret->{TRUST_E_BOTH_SERVER_IPV6} = $trustvars_e->{SERVER_IPV6};
976         $ret->{TRUST_E_BOTH_NETBIOSNAME} = $trustvars_e->{NETBIOSNAME};
977         $ret->{TRUST_E_BOTH_USERNAME} = $trustvars_e->{USERNAME};
978         $ret->{TRUST_E_BOTH_PASSWORD} = $trustvars_e->{PASSWORD};
979         $ret->{TRUST_E_BOTH_DOMAIN} = $trustvars_e->{DOMAIN};
980         $ret->{TRUST_E_BOTH_REALM} = $trustvars_e->{REALM};
981
982         return $ret;
983 }
984
985 sub setup_ad_member
986 {
987         my ($self,
988             $prefix,
989             $dcvars,
990             $trustvars_f,
991             $trustvars_e) = @_;
992
993         # If we didn't build with ADS, pretend this env was never available
994         if (not $self->have_ads()) {
995                 return "UNKNOWN";
996         }
997
998         print "PROVISIONING AD MEMBER...";
999
1000         return $self->provision_ad_member($prefix,
1001                                           "LOCALADMEMBER",
1002                                           $dcvars,
1003                                           $trustvars_f,
1004                                           $trustvars_e);
1005 }
1006
1007 sub setup_ad_member_rfc2307
1008 {
1009         my ($self, $prefix, $dcvars) = @_;
1010
1011         # If we didn't build with ADS, pretend this env was never available
1012         if (not $self->have_ads()) {
1013                 return "UNKNOWN";
1014         }
1015
1016         print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
1017
1018         my $member_options = "
1019         security = ads
1020         workgroup = $dcvars->{DOMAIN}
1021         realm = $dcvars->{REALM}
1022         idmap cache time = 0
1023         idmap negative cache time = 0
1024         idmap config * : backend = autorid
1025         idmap config * : range = 1000000-1999999
1026         idmap config * : rangesize = 100000
1027         idmap config $dcvars->{DOMAIN} : backend = rfc2307
1028         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
1029         idmap config $dcvars->{DOMAIN} : ldap_server = ad
1030         idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
1031         idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
1032
1033         password server = $dcvars->{SERVER}
1034 ";
1035
1036         my $ret = $self->provision(
1037             prefix => $prefix,
1038             domain => $dcvars->{DOMAIN},
1039             realm => $dcvars->{REALM},
1040             server => "RFC2307MEMBER",
1041             password => "loCalMemberPass",
1042             extra_options => $member_options,
1043             resolv_conf => $dcvars->{RESOLV_CONF});
1044
1045         $ret or return undef;
1046
1047         close(USERMAP);
1048         $ret->{DOMAIN} = $dcvars->{DOMAIN};
1049         $ret->{REALM} = $dcvars->{REALM};
1050         $ret->{DOMSID} = $dcvars->{DOMSID};
1051
1052         my $ctx;
1053         my $prefix_abs = abs_path($prefix);
1054         $ctx = {};
1055         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
1056         $ctx->{domain} = $dcvars->{DOMAIN};
1057         $ctx->{realm} = $dcvars->{REALM};
1058         $ctx->{dnsname} = lc($dcvars->{REALM});
1059         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
1060         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
1061         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
1062         Samba::mk_krb5_conf($ctx, "");
1063
1064         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
1065
1066         my $net = Samba::bindir_path($self, "net");
1067         # Add hosts file for name lookups
1068         my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1069         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1070         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1071                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1072         } else {
1073                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1074         }
1075         $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1076         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1077         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
1078         $cmd .= "$net join $ret->{CONFIGURATION}";
1079         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
1080
1081         if (system($cmd) != 0) {
1082             warn("Join failed\n$cmd");
1083             return undef;
1084         }
1085
1086         # We need world access to this share, as otherwise the domain
1087         # administrator from the AD domain provided by Samba4 can't
1088         # access the share for tests.
1089         chmod 0777, "$prefix/share";
1090
1091         if (not $self->check_or_start(
1092                 env_vars => $ret,
1093                 nmbd => "yes",
1094                 winbindd => "yes",
1095                 smbd => "yes")) {
1096                 return undef;
1097         }
1098
1099         $ret->{DC_SERVER} = $dcvars->{SERVER};
1100         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
1101         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
1102         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
1103         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
1104         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
1105
1106         return $ret;
1107 }
1108
1109 sub setup_ad_member_idmap_rid
1110 {
1111         my ($self, $prefix, $dcvars) = @_;
1112
1113         # If we didn't build with ADS, pretend this env was never available
1114         if (not $self->have_ads()) {
1115                 return "UNKNOWN";
1116         }
1117
1118         print "PROVISIONING S3 AD MEMBER WITH idmap_rid config...";
1119
1120         my $member_options = "
1121         security = ads
1122         workgroup = $dcvars->{DOMAIN}
1123         realm = $dcvars->{REALM}
1124         idmap config * : backend = tdb
1125         idmap config * : range = 1000000-1999999
1126         idmap config $dcvars->{DOMAIN} : backend = rid
1127         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
1128         # Prevent overridding the provisioned lib/krb5.conf which sets certain
1129         # values required for tests to succeed
1130         create krb5 conf = no
1131         map to guest = bad user
1132 ";
1133
1134         my $ret = $self->provision(
1135             prefix => $prefix,
1136             domain => $dcvars->{DOMAIN},
1137             realm => $dcvars->{REALM},
1138             server => "IDMAPRIDMEMBER",
1139             password => "loCalMemberPass",
1140             extra_options => $member_options,
1141             resolv_conf => $dcvars->{RESOLV_CONF});
1142
1143         $ret or return undef;
1144
1145         close(USERMAP);
1146         $ret->{DOMAIN} = $dcvars->{DOMAIN};
1147         $ret->{REALM} = $dcvars->{REALM};
1148         $ret->{DOMSID} = $dcvars->{DOMSID};
1149
1150         my $ctx;
1151         my $prefix_abs = abs_path($prefix);
1152         $ctx = {};
1153         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
1154         $ctx->{domain} = $dcvars->{DOMAIN};
1155         $ctx->{realm} = $dcvars->{REALM};
1156         $ctx->{dnsname} = lc($dcvars->{REALM});
1157         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
1158         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
1159         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
1160         Samba::mk_krb5_conf($ctx, "");
1161
1162         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
1163
1164         my $net = Samba::bindir_path($self, "net");
1165         # Add hosts file for name lookups
1166         my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1167         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1168         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1169                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1170         } else {
1171                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1172         }
1173         $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1174         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1175         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
1176         $cmd .= "$net join $ret->{CONFIGURATION}";
1177         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
1178
1179         if (system($cmd) != 0) {
1180             warn("Join failed\n$cmd");
1181             return undef;
1182         }
1183
1184         # We need world access to this share, as otherwise the domain
1185         # administrator from the AD domain provided by Samba4 can't
1186         # access the share for tests.
1187         chmod 0777, "$prefix/share";
1188
1189         if (not $self->check_or_start(
1190                 env_vars => $ret,
1191                 nmbd => "yes",
1192                 winbindd => "yes",
1193                 smbd => "yes")) {
1194                 return undef;
1195         }
1196
1197         $ret->{DC_SERVER} = $dcvars->{SERVER};
1198         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
1199         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
1200         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
1201         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
1202         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
1203
1204         return $ret;
1205 }
1206
1207 sub setup_ad_member_idmap_ad
1208 {
1209         my ($self, $prefix, $dcvars) = @_;
1210
1211         # If we didn't build with ADS, pretend this env was never available
1212         if (not $self->have_ads()) {
1213                 return "UNKNOWN";
1214         }
1215
1216         print "PROVISIONING S3 AD MEMBER WITH idmap_ad config...";
1217
1218         my $member_options = "
1219         security = ads
1220         workgroup = $dcvars->{DOMAIN}
1221         realm = $dcvars->{REALM}
1222         password server = $dcvars->{SERVER}
1223         idmap config * : backend = tdb
1224         idmap config * : range = 1000000-1999999
1225         idmap config $dcvars->{DOMAIN} : backend = ad
1226         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
1227         idmap config $dcvars->{DOMAIN} : unix_primary_group = yes
1228         idmap config $dcvars->{DOMAIN} : unix_nss_info = yes
1229         idmap config $dcvars->{TRUST_DOMAIN} : backend = ad
1230         idmap config $dcvars->{TRUST_DOMAIN} : range = 2000000-2999999
1231         gensec_gssapi:requested_life_time = 5
1232 ";
1233
1234         my $ret = $self->provision(
1235             prefix => $prefix,
1236             domain => $dcvars->{DOMAIN},
1237             realm => $dcvars->{REALM},
1238             server => "IDMAPADMEMBER",
1239             password => "loCalMemberPass",
1240             extra_options => $member_options,
1241             resolv_conf => $dcvars->{RESOLV_CONF});
1242
1243         $ret or return undef;
1244
1245         close(USERMAP);
1246         $ret->{DOMAIN} = $dcvars->{DOMAIN};
1247         $ret->{REALM} = $dcvars->{REALM};
1248         $ret->{DOMSID} = $dcvars->{DOMSID};
1249
1250         my $ctx;
1251         my $prefix_abs = abs_path($prefix);
1252         $ctx = {};
1253         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
1254         $ctx->{domain} = $dcvars->{DOMAIN};
1255         $ctx->{realm} = $dcvars->{REALM};
1256         $ctx->{dnsname} = lc($dcvars->{REALM});
1257         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
1258         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
1259         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
1260         Samba::mk_krb5_conf($ctx, "");
1261
1262         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
1263
1264         my $net = Samba::bindir_path($self, "net");
1265         # Add hosts file for name lookups
1266         my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1267         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1268         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1269                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1270         } else {
1271                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1272         }
1273         $cmd .= "RESOLV_CONF=\"$ret->{RESOLV_CONF}\" ";
1274         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1275         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
1276         $cmd .= "$net join $ret->{CONFIGURATION}";
1277         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
1278
1279         if (system($cmd) != 0) {
1280             warn("Join failed\n$cmd");
1281             return undef;
1282         }
1283
1284         # We need world access to this share, as otherwise the domain
1285         # administrator from the AD domain provided by Samba4 can't
1286         # access the share for tests.
1287         chmod 0777, "$prefix/share";
1288
1289         if (not $self->check_or_start(
1290                 env_vars => $ret,
1291                 nmbd => "yes",
1292                 winbindd => "yes",
1293                 smbd => "yes")) {
1294                 return undef;
1295         }
1296
1297         $ret->{DC_SERVER} = $dcvars->{SERVER};
1298         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
1299         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
1300         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
1301         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
1302         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
1303
1304         $ret->{TRUST_SERVER} = $dcvars->{TRUST_SERVER};
1305         $ret->{TRUST_USERNAME} = $dcvars->{TRUST_USERNAME};
1306         $ret->{TRUST_PASSWORD} = $dcvars->{TRUST_PASSWORD};
1307         $ret->{TRUST_DOMAIN} = $dcvars->{TRUST_DOMAIN};
1308         $ret->{TRUST_REALM} = $dcvars->{TRUST_REALM};
1309         $ret->{TRUST_DOMSID} = $dcvars->{TRUST_DOMSID};
1310
1311         return $ret;
1312 }
1313
1314 sub setup_ad_member_fips
1315 {
1316         my ($self,
1317             $prefix,
1318             $dcvars,
1319             $trustvars_f,
1320             $trustvars_e) = @_;
1321
1322         # If we didn't build with ADS, pretend this env was never available
1323         if (not $self->have_ads()) {
1324                 return "UNKNOWN";
1325         }
1326
1327         print "PROVISIONING AD FIPS MEMBER...";
1328
1329         return $self->provision_ad_member($prefix,
1330                                           "FIPSADMEMBER",
1331                                           $dcvars,
1332                                           $trustvars_f,
1333                                           $trustvars_e,
1334                                           1);
1335 }
1336
1337 sub setup_ad_member_offlogon
1338 {
1339         my ($self,
1340             $prefix,
1341             $dcvars,
1342             $trustvars_f,
1343             $trustvars_e) = @_;
1344
1345         # If we didn't build with ADS, pretend this env was never available
1346         if (not $self->have_ads()) {
1347                 return "UNKNOWN";
1348         }
1349
1350         print "PROVISIONING AD MEMBER OFFLINE LOGON...";
1351
1352         return $self->provision_ad_member($prefix,
1353                                           "OFFLINEADMEM",
1354                                           $dcvars,
1355                                           $trustvars_f,
1356                                           $trustvars_e,
1357                                           undef,
1358                                           1);
1359 }
1360
1361 sub setup_simpleserver
1362 {
1363         my ($self, $path) = @_;
1364
1365         print "PROVISIONING simple server...";
1366
1367         my $prefix_abs = abs_path($path);
1368
1369         my $simpleserver_options = "
1370         lanman auth = yes
1371         ntlm auth = yes
1372         vfs objects = xattr_tdb streams_depot
1373         change notify = no
1374         server smb encrypt = off
1375
1376 [vfs_aio_pthread]
1377         path = $prefix_abs/share
1378         read only = no
1379         vfs objects = aio_pthread
1380         aio_pthread:aio open = yes
1381         smbd:async dosmode = no
1382
1383 [vfs_aio_pthread_async_dosmode_default1]
1384         path = $prefix_abs/share
1385         read only = no
1386         vfs objects = aio_pthread
1387         store dos attributes = yes
1388         aio_pthread:aio open = yes
1389         smbd:async dosmode = yes
1390
1391 [vfs_aio_pthread_async_dosmode_default2]
1392         path = $prefix_abs/share
1393         read only = no
1394         vfs objects = aio_pthread xattr_tdb
1395         store dos attributes = yes
1396         aio_pthread:aio open = yes
1397         smbd:async dosmode = yes
1398
1399 [vfs_aio_pthread_async_dosmode_force_sync1]
1400         path = $prefix_abs/share
1401         read only = no
1402         vfs objects = aio_pthread
1403         store dos attributes = yes
1404         aio_pthread:aio open = yes
1405         smbd:async dosmode = yes
1406         # This simulates non linux systems
1407         smbd:force sync user path safe threadpool = yes
1408         smbd:force sync user chdir safe threadpool = yes
1409         smbd:force sync root path safe threadpool = yes
1410         smbd:force sync root chdir safe threadpool = yes
1411
1412 [vfs_aio_pthread_async_dosmode_force_sync2]
1413         path = $prefix_abs/share
1414         read only = no
1415         vfs objects = aio_pthread xattr_tdb
1416         store dos attributes = yes
1417         aio_pthread:aio open = yes
1418         smbd:async dosmode = yes
1419         # This simulates non linux systems
1420         smbd:force sync user path safe threadpool = yes
1421         smbd:force sync user chdir safe threadpool = yes
1422         smbd:force sync root path safe threadpool = yes
1423         smbd:force sync root chdir safe threadpool = yes
1424
1425 [vfs_aio_fork]
1426         path = $prefix_abs/share
1427         vfs objects = aio_fork
1428         read only = no
1429         vfs_aio_fork:erratic_testing_mode=yes
1430
1431 [dosmode]
1432         path = $prefix_abs/share
1433         vfs objects =
1434         store dos attributes = yes
1435         hide files = /hidefile/
1436         hide dot files = yes
1437
1438 [hidenewfiles]
1439         path = $prefix_abs/share
1440         hide new files timeout = 5
1441 ";
1442
1443         my $vars = $self->provision(
1444             prefix => $path,
1445             domain => "WORKGROUP",
1446             server => "LOCALSHARE4",
1447             password => "local4pass",
1448             extra_options => $simpleserver_options);
1449
1450         $vars or return undef;
1451
1452         if (not $self->check_or_start(
1453                 env_vars => $vars,
1454                 nmbd => "yes",
1455                 smbd => "yes")) {
1456                return undef;
1457         }
1458
1459         return $vars;
1460 }
1461
1462 sub create_file_chmod($$)
1463 {
1464     my ($name, $mode) = @_;
1465     my $fh;
1466
1467     unless (open($fh, '>', $name)) {
1468         warn("Unable to open $name");
1469         return undef;
1470     }
1471     chmod($mode, $fh);
1472 }
1473
1474 sub setup_fileserver
1475 {
1476         my ($self, $path, $more_conf, $server) = @_;
1477         my $prefix_abs = abs_path($path);
1478         my $srcdir_abs = abs_path($self->{srcdir});
1479
1480         print "PROVISIONING file server ...\n";
1481
1482         my @dirs = ();
1483
1484         mkdir($prefix_abs, 0777);
1485
1486         my $usershare_dir="$prefix_abs/lib/usershare";
1487
1488         mkdir("$prefix_abs/lib", 0755);
1489         remove_tree($usershare_dir);
1490         mkdir($usershare_dir, 01770);
1491
1492         my $share_dir="$prefix_abs/share";
1493
1494         # Create share directory structure
1495         my $lower_case_share_dir="$share_dir/lower-case";
1496         push(@dirs, $lower_case_share_dir);
1497
1498         my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
1499         push(@dirs, $lower_case_share_dir_30000);
1500
1501         my $dfree_share_dir="$share_dir/dfree";
1502         push(@dirs, $dfree_share_dir);
1503         push(@dirs, "$dfree_share_dir/subdir1");
1504         push(@dirs, "$dfree_share_dir/subdir2");
1505         push(@dirs, "$dfree_share_dir/subdir3");
1506
1507         my $quotadir_dir="$share_dir/quota";
1508         push(@dirs, $quotadir_dir);
1509
1510         my $valid_users_sharedir="$share_dir/valid_users";
1511         push(@dirs,$valid_users_sharedir);
1512
1513         my $offline_sharedir="$share_dir/offline";
1514         push(@dirs,$offline_sharedir);
1515
1516         my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
1517         push(@dirs, $force_user_valid_users_dir);
1518
1519         my $smbget_sharedir="$share_dir/smbget";
1520         push(@dirs,$smbget_sharedir);
1521
1522         my $tarmode_sharedir="$share_dir/tarmode";
1523         push(@dirs,$tarmode_sharedir);
1524
1525         my $tarmode2_sharedir="$share_dir/tarmode2";
1526         push(@dirs,$tarmode2_sharedir);
1527
1528         my $smbcacls_sharedir="$share_dir/smbcacls";
1529         push(@dirs,$smbcacls_sharedir);
1530
1531         my $usershare_sharedir="$share_dir/usershares";
1532         push(@dirs,$usershare_sharedir);
1533
1534         my $dropbox_sharedir="$share_dir/dropbox";
1535         push(@dirs,$dropbox_sharedir);
1536
1537         my $bad_iconv_sharedir="$share_dir/bad_iconv";
1538         push(@dirs, $bad_iconv_sharedir);
1539
1540         my $ip4 = Samba::get_ipv4_addr("FILESERVER");
1541         my $fileserver_options = "
1542         kernel change notify = yes
1543         rpc_server:mdssvc = embedded
1544         spotlight backend = elasticsearch
1545         elasticsearch:address = $ip4
1546         elasticsearch:port = 8080
1547         elasticsearch:mappings = $srcdir_abs/source3/rpc_server/mdssvc/elasticsearch_mappings.json
1548
1549         usershare path = $usershare_dir
1550         usershare max shares = 10
1551         usershare allow guests = yes
1552         usershare prefix allow list = $usershare_sharedir
1553
1554         get quota command = $prefix_abs/getset_quota.py
1555         set quota command = $prefix_abs/getset_quota.py
1556 [tarmode]
1557         path = $tarmode_sharedir
1558         comment = tar test share
1559         xattr_tdb:file = $prefix_abs/tarmode-xattr.tdb
1560 [tarmode2]
1561         path = $tarmode2_sharedir
1562         comment = tar test share
1563         xattr_tdb:file = $prefix_abs/tarmode2-xattr.tdb
1564 [spotlight]
1565         path = $share_dir
1566         spotlight = yes
1567         read only = no
1568 [no_spotlight]
1569         path = $share_dir
1570         spotlight = no
1571         read only = no
1572 [lowercase]
1573         path = $lower_case_share_dir
1574         comment = smb username is [%U]
1575         case sensitive = True
1576         default case = lower
1577         preserve case = no
1578         short preserve case = no
1579 [lowercase-30000]
1580         path = $lower_case_share_dir_30000
1581         comment = smb username is [%U]
1582         case sensitive = True
1583         default case = lower
1584         preserve case = no
1585         short preserve case = no
1586 [dfree]
1587         path = $dfree_share_dir
1588         comment = smb username is [%U]
1589         dfree command = $srcdir_abs/testprogs/blackbox/dfree.sh
1590 [valid-users-access]
1591         path = $valid_users_sharedir
1592         valid users = +userdup
1593 [offline]
1594         path = $offline_sharedir
1595         vfs objects = offline
1596
1597 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
1598 # RH BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
1599 [force_user_valid_users]
1600         path = $force_user_valid_users_dir
1601         comment = force user with valid users combination test share
1602         valid users = +force_user
1603         force user = force_user
1604         force group = everyone
1605         write list = force_user
1606
1607 [smbget]
1608         path = $smbget_sharedir
1609         comment = smb username is [%U]
1610         guest ok = yes
1611 [ign_sysacls]
1612         path = $share_dir
1613         comment = ignore system acls
1614         acl_xattr:ignore system acls = yes
1615 [inherit_owner]
1616         path = $share_dir
1617         comment = inherit owner
1618         inherit owner = yes
1619 [inherit_owner_u]
1620         path = $share_dir
1621         comment = inherit only unix owner
1622         inherit owner = unix only
1623         acl_xattr:ignore system acls = yes
1624 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=13690
1625 [force_group_test]
1626         path = $share_dir
1627         comment = force group test
1628 #       force group = everyone
1629
1630 [create_mode_664]
1631         path = $share_dir
1632         comment = smb username is [%U]
1633         create mask = 0644
1634         force create mode = 0664
1635         vfs objects = dirsort
1636
1637 [dropbox]
1638         path = $dropbox_sharedir
1639         comment = smb username is [%U]
1640         writeable = yes
1641         vfs objects =
1642
1643 [bad_iconv]
1644         path = $bad_iconv_sharedir
1645         comment = smb username is [%U]
1646         vfs objects =
1647
1648 [homes]
1649         comment = Home directories
1650         browseable = No
1651         read only = No
1652 ";
1653
1654         if (defined($more_conf)) {
1655                 $fileserver_options = $fileserver_options . $more_conf;
1656         }
1657         if (!defined($server)) {
1658                 $server = "FILESERVER";
1659         }
1660
1661         my $vars = $self->provision(
1662             prefix => $path,
1663             domain => "WORKGROUP",
1664             server => $server,
1665             password => "fileserver",
1666             extra_options => $fileserver_options,
1667             no_delete_prefix => 1);
1668
1669         $vars or return undef;
1670
1671         if (not $self->check_or_start(
1672                 env_vars => $vars,
1673                 nmbd => "yes",
1674                 smbd => "yes")) {
1675                return undef;
1676         }
1677
1678
1679         mkdir($_, 0777) foreach(@dirs);
1680
1681         ## Create case sensitive lower case share dir
1682         foreach my $file ('a'..'z') {
1683                 my $full_path = $lower_case_share_dir . '/' . $file;
1684                 open my $fh, '>', $full_path;
1685                 # Add some content to file
1686                 print $fh $full_path;
1687                 close $fh;
1688         }
1689
1690         for (my $file = 1; $file < 51; ++$file) {
1691                 my $full_path = $lower_case_share_dir . '/' . $file;
1692                 open my $fh, '>', $full_path;
1693                 # Add some content to file
1694                 print $fh $full_path;
1695                 close $fh;
1696         }
1697
1698         # Create content for 30000 share
1699         foreach my $file ('a'..'z') {
1700                 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
1701                 open my $fh, '>', $full_path;
1702                 # Add some content to file
1703                 print $fh $full_path;
1704                 close $fh;
1705         }
1706
1707         for (my $file = 1; $file < 30001; ++$file) {
1708                 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
1709                 open my $fh, '>', $full_path;
1710                 # Add some content to file
1711                 print $fh $full_path;
1712                 close $fh;
1713         }
1714
1715         ##
1716         ## create a listable file in valid_users_share
1717         ##
1718         create_file_chmod("$valid_users_sharedir/foo", 0644) or return undef;
1719
1720         ##
1721         ## create a valid utf8 filename which is invalid as a CP850 conversion
1722         ##
1723         create_file_chmod("$bad_iconv_sharedir/\xED\x9F\xBF", 0644) or return undef;
1724
1725         return $vars;
1726 }
1727
1728 sub setup_fileserver_smb1
1729 {
1730         my ($self, $path) = @_;
1731         my $prefix_abs = abs_path($path);
1732         my $conf = "
1733 [global]
1734         client min protocol = CORE
1735         server min protocol = LANMAN1
1736
1737 [hidenewfiles]
1738         path = $prefix_abs/share
1739         hide new files timeout = 5
1740 [vfs_aio_pthread]
1741         path = $prefix_abs/share
1742         read only = no
1743         vfs objects = aio_pthread
1744         aio_pthread:aio open = yes
1745         smbd:async dosmode = no
1746
1747 [vfs_aio_pthread_async_dosmode_default1]
1748         path = $prefix_abs/share
1749         read only = no
1750         vfs objects = aio_pthread
1751         store dos attributes = yes
1752         aio_pthread:aio open = yes
1753         smbd:async dosmode = yes
1754
1755 [vfs_aio_pthread_async_dosmode_default2]
1756         path = $prefix_abs/share
1757         read only = no
1758         vfs objects = aio_pthread xattr_tdb
1759         store dos attributes = yes
1760         aio_pthread:aio open = yes
1761         smbd:async dosmode = yes
1762
1763 [vfs_aio_pthread_async_dosmode_force_sync1]
1764         path = $prefix_abs/share
1765         read only = no
1766         vfs objects = aio_pthread
1767         store dos attributes = yes
1768         aio_pthread:aio open = yes
1769         smbd:async dosmode = yes
1770         # This simulates non linux systems
1771         smbd:force sync user path safe threadpool = yes
1772         smbd:force sync user chdir safe threadpool = yes
1773         smbd:force sync root path safe threadpool = yes
1774         smbd:force sync root chdir safe threadpool = yes
1775
1776 [vfs_aio_pthread_async_dosmode_force_sync2]
1777         path = $prefix_abs/share
1778         read only = no
1779         vfs objects = aio_pthread xattr_tdb
1780         store dos attributes = yes
1781         aio_pthread:aio open = yes
1782         smbd:async dosmode = yes
1783         # This simulates non linux systems
1784         smbd:force sync user path safe threadpool = yes
1785         smbd:force sync user chdir safe threadpool = yes
1786         smbd:force sync root path safe threadpool = yes
1787         smbd:force sync root chdir safe threadpool = yes
1788
1789 [vfs_aio_fork]
1790         path = $prefix_abs/share
1791         vfs objects = aio_fork
1792         read only = no
1793         vfs_aio_fork:erratic_testing_mode=yes
1794 ";
1795         return $self->setup_fileserver($path, $conf, "FILESERVERSMB1");
1796 }
1797
1798 sub setup_fileserver_smb1_done
1799 {
1800         my ($self, $path, $dep_env) = @_;
1801         return $self->return_alias_env($path, $dep_env);
1802 }
1803
1804 sub setup_ktest
1805 {
1806         my ($self, $prefix) = @_;
1807
1808         # If we didn't build with ADS, pretend this env was never available
1809         if (not $self->have_ads()) {
1810                 return "UNKNOWN";
1811         }
1812
1813         print "PROVISIONING server with security=ads...";
1814
1815         my $ktest_options = "
1816         workgroup = KTEST
1817         realm = ktest.samba.example.com
1818         security = ads
1819         username map = $prefix/lib/username.map
1820         server signing = required
1821         server min protocol = SMB3_00
1822         client max protocol = SMB3
1823
1824         # This disables NTLM auth against the local SAM, which
1825         # we use can then test this setting by.
1826         ntlm auth = disabled
1827 ";
1828
1829         my $ret = $self->provision(
1830             prefix => $prefix,
1831             domain => "KTEST",
1832             server => "LOCALKTEST6",
1833             password => "localktest6pass",
1834             extra_options => $ktest_options);
1835
1836         $ret or return undef;
1837
1838         my $ctx;
1839         my $prefix_abs = abs_path($prefix);
1840         $ctx = {};
1841         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
1842         $ctx->{domain} = "KTEST";
1843         $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
1844         $ctx->{dnsname} = lc($ctx->{realm});
1845         $ctx->{kdc_ipv4} = "0.0.0.0";
1846         $ctx->{kdc_ipv6} = "::";
1847         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
1848         Samba::mk_krb5_conf($ctx, "");
1849
1850         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
1851
1852         open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
1853         print USERMAP "
1854 $ret->{USERNAME} = KTEST\\Administrator
1855 ";
1856         close(USERMAP);
1857
1858 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
1859 #Samba4 DC with the same parameters as are being used here.  The
1860 #domain SID is S-1-5-21-1071277805-689288055-3486227160
1861         $ret->{SAMSID} = "S-1-5-21-1911091480-1468226576-2729736297";
1862         $ret->{DOMSID} = "S-1-5-21-1071277805-689288055-3486227160";
1863
1864         system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
1865         chmod 0600, "$prefix/private/secrets.tdb";
1866
1867 #Make sure there's no old ntdb file.
1868         system("rm -f $prefix/private/secrets.ntdb");
1869
1870 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
1871 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
1872 #
1873 #and having in krb5.conf:
1874 # ticket_lifetime = 799718400
1875 # renew_lifetime = 799718400
1876 #
1877 # The commands for the -2 keytab where were:
1878 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
1879 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
1880 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
1881 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
1882 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
1883 #
1884 # and then for the -3 keytab, I did
1885 #
1886 # net changetrustpw; kdestroy and the same again.
1887 #
1888 # This creates a credential cache with a very long lifetime (2036 at
1889 # at 2011-04), and shows that running 'net changetrustpw' does not
1890 # break existing logins (for the secrets.tdb method at least).
1891 #
1892
1893         $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
1894
1895         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
1896         chmod 0600, "$prefix/krb5_ccache-2";
1897
1898         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
1899         chmod 0600, "$prefix/krb5_ccache-3";
1900
1901         # We need world access to this share, as otherwise the domain
1902         # administrator from the AD domain provided by ktest can't
1903         # access the share for tests.
1904         chmod 0777, "$prefix/share";
1905
1906         if (not $self->check_or_start(
1907                 env_vars => $ret,
1908                 nmbd => "yes",
1909                 smbd => "yes")) {
1910                return undef;
1911         }
1912         return $ret;
1913 }
1914
1915 sub setup_maptoguest
1916 {
1917         my ($self, $path) = @_;
1918         my $prefix_abs = abs_path($path);
1919         my $libdir="$prefix_abs/lib";
1920         my $share_dir="$prefix_abs/share";
1921         my $errorinjectconf="$libdir/error_inject.conf";
1922
1923         print "PROVISIONING maptoguest...";
1924
1925         my $options = "
1926 map to guest = bad user
1927 ntlm auth = yes
1928
1929 [force_user_error_inject]
1930         path = $share_dir
1931         vfs objects = acl_xattr fake_acls xattr_tdb error_inject
1932         force user = user1
1933         include = $errorinjectconf
1934 ";
1935
1936         my $vars = $self->provision(
1937             prefix => $path,
1938             domain => "WORKGROUP",
1939             server => "maptoguest",
1940             password => "maptoguestpass",
1941             extra_options => $options);
1942
1943         $vars or return undef;
1944
1945         if (not $self->check_or_start(
1946                 env_vars => $vars,
1947                 nmbd => "yes",
1948                 smbd => "yes")) {
1949                return undef;
1950         }
1951
1952         return $vars;
1953 }
1954
1955 sub stop_sig_term($$) {
1956         my ($self, $pid) = @_;
1957         kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1958 }
1959
1960 sub stop_sig_kill($$) {
1961         my ($self, $pid) = @_;
1962         kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1963 }
1964
1965 sub write_pid($$$)
1966 {
1967         my ($env_vars, $app, $pid) = @_;
1968
1969         open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
1970         print PID $pid;
1971         close(PID);
1972 }
1973
1974 sub read_pid($$)
1975 {
1976         my ($env_vars, $app) = @_;
1977
1978         open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
1979         my $pid = <PID>;
1980         close(PID);
1981         return $pid;
1982 }
1983
1984 # builds up the cmd args to run an s3 binary (i.e. smbd, nmbd, etc)
1985 sub make_bin_cmd
1986 {
1987         my ($self, $binary, $env_vars, $options, $valgrind, $dont_log_stdout) = @_;
1988
1989         my @optargs = ("-d0");
1990         if (defined($options)) {
1991                 @optargs = split(/ /, $options);
1992         }
1993         my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1994
1995         if (defined($valgrind)) {
1996                 @preargs = split(/ /, $valgrind);
1997         }
1998         my @args = ("-F", "--no-process-group",
1999                     "--configfile=$env_vars->{SERVERCONFFILE}",
2000                     "-l", $env_vars->{LOGDIR});
2001
2002         if (not defined($dont_log_stdout)) {
2003                 push(@args, "--debug-stdout");
2004         }
2005         return (@preargs, $binary, @args, @optargs);
2006 }
2007
2008 sub check_or_start($$) {
2009         my ($self, %args) = @_;
2010         my $env_vars = $args{env_vars};
2011         my $nmbd = $args{nmbd} // "no";
2012         my $winbindd = $args{winbindd} // "no";
2013         my $smbd = $args{smbd} // "no";
2014         my $child_cleanup = $args{child_cleanup};
2015         my $skip_wait = $args{skip_wait} // 0;
2016
2017         my $STDIN_READER;
2018
2019         # use a pipe for stdin in the child processes. This allows
2020         # those processes to monitor the pipe for EOF to ensure they
2021         # exit when the test script exits
2022         pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
2023
2024         my $binary = Samba::bindir_path($self, "nmbd");
2025         my @full_cmd = $self->make_bin_cmd($binary, $env_vars,
2026                                            $ENV{NMBD_OPTIONS}, $ENV{NMBD_VALGRIND},
2027                                            $ENV{NMBD_DONT_LOG_STDOUT});
2028         my $nmbd_envs = Samba::get_env_for_process("nmbd", $env_vars);
2029         delete $nmbd_envs->{RESOLV_WRAPPER_CONF};
2030         delete $nmbd_envs->{RESOLV_WRAPPER_HOSTS};
2031
2032         # fork and exec() nmbd in the child process
2033         my $daemon_ctx = {
2034                 NAME => "nmbd",
2035                 BINARY_PATH => $binary,
2036                 FULL_CMD => [ @full_cmd ],
2037                 LOG_FILE => $env_vars->{NMBD_TEST_LOG},
2038                 PCAP_FILE => "env-$ENV{ENVNAME}-nmbd",
2039                 ENV_VARS => $nmbd_envs,
2040         };
2041         if ($nmbd ne "yes") {
2042                 $daemon_ctx->{SKIP_DAEMON} = 1;
2043         }
2044         my $pid = Samba::fork_and_exec(
2045             $self, $env_vars, $daemon_ctx, $STDIN_READER, $child_cleanup);
2046
2047         $env_vars->{NMBD_TL_PID} = $pid;
2048         write_pid($env_vars, "nmbd", $pid);
2049
2050         $binary = Samba::bindir_path($self, "winbindd");
2051         @full_cmd = $self->make_bin_cmd($binary, $env_vars,
2052                                          $ENV{WINBINDD_OPTIONS},
2053                                          $ENV{WINBINDD_VALGRIND},
2054                                          $ENV{WINBINDD_DONT_LOG_STDOUT});
2055
2056         # fork and exec() winbindd in the child process
2057         $daemon_ctx = {
2058                 NAME => "winbindd",
2059                 BINARY_PATH => $binary,
2060                 FULL_CMD => [ @full_cmd ],
2061                 LOG_FILE => $env_vars->{WINBINDD_TEST_LOG},
2062                 PCAP_FILE => "env-$ENV{ENVNAME}-winbindd",
2063         };
2064         if ($winbindd ne "yes") {
2065                 $daemon_ctx->{SKIP_DAEMON} = 1;
2066         }
2067
2068         $pid = Samba::fork_and_exec(
2069             $self, $env_vars, $daemon_ctx, $STDIN_READER, $child_cleanup);
2070
2071         $env_vars->{WINBINDD_TL_PID} = $pid;
2072         write_pid($env_vars, "winbindd", $pid);
2073
2074         $binary = Samba::bindir_path($self, "smbd");
2075         @full_cmd = $self->make_bin_cmd($binary, $env_vars,
2076                                          $ENV{SMBD_OPTIONS}, $ENV{SMBD_VALGRIND},
2077                                          $ENV{SMBD_DONT_LOG_STDOUT});
2078
2079         # fork and exec() smbd in the child process
2080         $daemon_ctx = {
2081                 NAME => "smbd",
2082                 BINARY_PATH => $binary,
2083                 FULL_CMD => [ @full_cmd ],
2084                 LOG_FILE => $env_vars->{SMBD_TEST_LOG},
2085                 PCAP_FILE => "env-$ENV{ENVNAME}-smbd",
2086         };
2087         if ($smbd ne "yes") {
2088                 $daemon_ctx->{SKIP_DAEMON} = 1;
2089         }
2090
2091         $pid = Samba::fork_and_exec(
2092             $self, $env_vars, $daemon_ctx, $STDIN_READER, $child_cleanup);
2093
2094         $env_vars->{SMBD_TL_PID} = $pid;
2095         write_pid($env_vars, "smbd", $pid);
2096
2097         # close the parent's read-end of the pipe
2098         close($STDIN_READER);
2099
2100         if ($skip_wait) {
2101                 return 1;
2102         }
2103
2104         return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
2105 }
2106
2107 sub createuser($$$$$)
2108 {
2109         my ($self, $username, $password, $conffile, $env) = @_;
2110         my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $username > /dev/null";
2111
2112         keys %$env;
2113         while(my($var, $val) = each %$env) {
2114                 $cmd = "$var=\"$val\" $cmd";
2115         }
2116
2117         unless (open(PWD, "|$cmd")) {
2118             warn("Unable to set password for $username account\n$cmd");
2119             return undef;
2120         }
2121         print PWD "$password\n$password\n";
2122         unless (close(PWD)) {
2123             warn("Unable to set password for $username account\n$cmd");
2124             return undef;
2125         }
2126 }
2127
2128 sub provision($$)
2129 {
2130         my ($self, %args) = @_;
2131
2132         my $prefix = $args{prefix};
2133         my $domain = $args{domain};
2134         my $realm = $args{realm};
2135         my $server = $args{server};
2136         my $password = $args{password};
2137         my $extra_options = $args{extra_options};
2138         my $resolv_conf = $args{resolv_conf};
2139         my $no_delete_prefix= $args{no_delete_prefix};
2140         my $netbios_name = $args{netbios_name} // $server;
2141         my $server_log_level = $ENV{SERVER_LOG_LEVEL} || 1;
2142
2143         ##
2144         ## setup the various environment variables we need
2145         ##
2146
2147         my $samsid = Samba::random_domain_sid();
2148         my $swiface = Samba::get_interface($server);
2149         my %ret = ();
2150         my %createuser_env = ();
2151         my $server_ip = Samba::get_ipv4_addr($server);
2152         my $server_ipv6 = Samba::get_ipv6_addr($server);
2153         my $dns_domain;
2154         if (defined($realm)) {
2155             $dns_domain = lc($realm);
2156         } else {
2157             $dns_domain = "samba.example.com";
2158         }
2159
2160         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
2161         chomp $unix_name;
2162         my $unix_uid = $>;
2163         my $unix_gids_str = $);
2164         my @unix_gids = split(" ", $unix_gids_str);
2165
2166         my $prefix_abs = abs_path($prefix);
2167         my $bindir_abs = abs_path($self->{bindir});
2168
2169         my @dirs = ();
2170
2171         my $shrdir=$args{share_dir} // "$prefix_abs/share";
2172         push(@dirs,$shrdir);
2173
2174         my $libdir="$prefix_abs/lib";
2175         push(@dirs,$libdir);
2176
2177         my $piddir="$prefix_abs/pid";
2178         push(@dirs,$piddir);
2179
2180         my $privatedir="$prefix_abs/private";
2181         push(@dirs,$privatedir);
2182
2183         my $cachedir = "$prefix_abs/cachedir";
2184         push(@dirs, $cachedir);
2185
2186         my $binddnsdir = "$prefix_abs/bind-dns";
2187         push(@dirs, $binddnsdir);
2188
2189         my $lockdir="$prefix_abs/lockdir";
2190         push(@dirs,$lockdir);
2191
2192         my $eventlogdir="$prefix_abs/lockdir/eventlog";
2193         push(@dirs,$eventlogdir);
2194
2195         my $logdir="$prefix_abs/logs";
2196         push(@dirs,$logdir);
2197
2198         my $driver32dir="$shrdir/W32X86";
2199         push(@dirs,$driver32dir);
2200
2201         my $driver64dir="$shrdir/x64";
2202         push(@dirs,$driver64dir);
2203
2204         my $driver40dir="$shrdir/WIN40";
2205         push(@dirs,$driver40dir);
2206
2207         my $ro_shrdir="$shrdir/root-tmp";
2208         push(@dirs,$ro_shrdir);
2209
2210         my $noperm_shrdir="$shrdir/noperm-tmp";
2211         push(@dirs,$noperm_shrdir);
2212
2213         my $msdfs_shrdir="$shrdir/msdfsshare";
2214         push(@dirs,$msdfs_shrdir);
2215
2216         my $msdfs_deeppath="$msdfs_shrdir/deeppath";
2217         push(@dirs,$msdfs_deeppath);
2218
2219         my $smbcacls_sharedir_dfs="$shrdir/smbcacls_sharedir_dfs";
2220         push(@dirs,$smbcacls_sharedir_dfs);
2221
2222         my $smbcacls_share="$shrdir/smbcacls_share";
2223         push(@dirs,$smbcacls_share);
2224
2225         my $smbcacls_share_testdir="$shrdir/smbcacls_share/smbcacls";
2226         push(@dirs,$smbcacls_share_testdir);
2227
2228         my $badnames_shrdir="$shrdir/badnames";
2229         push(@dirs,$badnames_shrdir);
2230
2231         my $lease1_shrdir="$shrdir/dynamic";
2232         push(@dirs,$lease1_shrdir);
2233
2234         my $manglenames_shrdir="$shrdir/manglenames";
2235         push(@dirs,$manglenames_shrdir);
2236
2237         my $widelinks_shrdir="$shrdir/widelinks";
2238         push(@dirs,$widelinks_shrdir);
2239
2240         my $widelinks_linkdir="$shrdir/widelinks_foo";
2241         push(@dirs,$widelinks_linkdir);
2242
2243         my $fsrvp_shrdir="$shrdir/fsrvp";
2244         push(@dirs,$fsrvp_shrdir);
2245
2246         my $shadow_tstdir="$shrdir/shadow";
2247         push(@dirs,$shadow_tstdir);
2248         my $shadow_mntdir="$shadow_tstdir/mount";
2249         push(@dirs,$shadow_mntdir);
2250         my $shadow_basedir="$shadow_mntdir/base";
2251         push(@dirs,$shadow_basedir);
2252         my $shadow_shrdir="$shadow_basedir/share";
2253         push(@dirs,$shadow_shrdir);
2254
2255         my $nosymlinks_shrdir="$shrdir/nosymlinks";
2256         push(@dirs,$nosymlinks_shrdir);
2257
2258         my $local_symlinks_shrdir="$shrdir/local_symlinks";
2259         push(@dirs,$local_symlinks_shrdir);
2260
2261         # this gets autocreated by winbindd
2262         my $wbsockdir="$prefix_abs/wbsock";
2263
2264         my $nmbdsockdir="$prefix_abs/nmbd";
2265         unlink($nmbdsockdir);
2266
2267         ## 
2268         ## create the test directory layout
2269         ##
2270         die ("prefix_abs = ''") if $prefix_abs eq "";
2271         die ("prefix_abs = '/'") if $prefix_abs eq "/";
2272
2273         mkdir($prefix_abs, 0777);
2274         print "CREATE TEST ENVIRONMENT IN '$prefix'...";
2275         if (not defined($no_delete_prefix) or not $no_delete_prefix) {
2276             system("rm -rf $prefix_abs/*");
2277         }
2278         mkdir($_, 0777) foreach(@dirs);
2279
2280         my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
2281
2282         ##
2283         ## lockdir and piddir must be 0755
2284         ##
2285         chmod 0755, $lockdir;
2286         chmod 0755, $piddir;
2287
2288
2289         ##
2290         ## Create a directory without permissions to enter
2291         ##
2292         chmod 0000, $noperm_shrdir;
2293
2294         ##
2295         ## create ro and msdfs share layout
2296         ##
2297
2298         chmod 0755, $ro_shrdir;
2299
2300         create_file_chmod("$ro_shrdir/unreadable_file", 0600) or return undef;
2301
2302         create_file_chmod("$ro_shrdir/msdfs-target", 0600) or return undef;
2303         symlink "msdfs:$server_ip\\ro-tmp,$server_ipv6\\ro-tmp",
2304                 "$msdfs_shrdir/msdfs-src1";
2305         symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
2306         symlink "msdfs:$server_ip\\smbcacls_sharedir_dfs,$server_ipv6\\smbcacls_sharedir_dfs",
2307                 "$msdfs_shrdir/smbcacls_sharedir_dfs";
2308
2309         ##
2310         ## create bad names in $badnames_shrdir
2311         ##
2312         ## (An invalid name, would be mangled to 8.3).
2313         create_file_chmod("$badnames_shrdir/\340|\231\216\377\177",
2314                           0600) or return undef;
2315
2316         ## (A bad name, would not be mangled to 8.3).
2317         create_file_chmod("$badnames_shrdir/\240\276\346\327\377\177",
2318                           0666) or return undef;
2319
2320         ## (A bad good name).
2321         create_file_chmod("$badnames_shrdir/blank.txt",
2322                           0666) or return undef;
2323
2324         ##
2325         ## create mangleable directory names in $manglenames_shrdir
2326         ##
2327         my $manglename_target = "$manglenames_shrdir/foo:bar";
2328         mkdir($manglename_target, 0777);
2329
2330         ##
2331         ## create symlinks for widelinks tests.
2332         ##
2333         my $widelinks_target = "$widelinks_linkdir/target";
2334         create_file_chmod("$widelinks_target", 0666) or return undef;
2335
2336         ##
2337         ## This link should get ACCESS_DENIED
2338         ##
2339         symlink "$widelinks_target", "$widelinks_shrdir/source";
2340         ##
2341         ## This link should be allowed
2342         ##
2343         symlink "$widelinks_shrdir", "$widelinks_shrdir/dot";
2344
2345         my $conffile="$libdir/server.conf";
2346         my $dfqconffile="$libdir/dfq.conf";
2347         my $errorinjectconf="$libdir/error_inject.conf";
2348         my $delayinjectconf="$libdir/delay_inject.conf";
2349         my $globalinjectconf="$libdir/global_inject.conf";
2350
2351         my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/third_party/nss_wrapper/nss_wrapper.pl";
2352         my $nss_wrapper_passwd = "$privatedir/passwd";
2353         my $nss_wrapper_group = "$privatedir/group";
2354         my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
2355         my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
2356
2357         my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
2358
2359         my $fake_snap_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/fake_snap.pl";
2360
2361         my @eventlog_list = ("dns server", "application");
2362
2363         ##
2364         ## calculate uids and gids
2365         ##
2366
2367         my ($max_uid, $max_gid);
2368         my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
2369         my ($uid_pdbtest_wkn);
2370         my ($uid_smbget);
2371         my ($uid_force_user);
2372         my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
2373         my ($gid_userdup, $gid_everyone);
2374         my ($gid_force_user);
2375         my ($uid_user1);
2376         my ($uid_user2);
2377         my ($uid_gooduser);
2378         my ($uid_eviluser);
2379         my ($uid_slashuser);
2380
2381         if ($unix_uid < 0xffff - 13) {
2382                 $max_uid = 0xffff;
2383         } else {
2384                 $max_uid = $unix_uid;
2385         }
2386
2387         $uid_root = $max_uid - 1;
2388         $uid_nobody = $max_uid - 2;
2389         $uid_pdbtest = $max_uid - 3;
2390         $uid_pdbtest2 = $max_uid - 4;
2391         $uid_userdup = $max_uid - 5;
2392         $uid_pdbtest_wkn = $max_uid - 6;
2393         $uid_force_user = $max_uid - 7;
2394         $uid_smbget = $max_uid - 8;
2395         $uid_user1 = $max_uid - 9;
2396         $uid_user2 = $max_uid - 10;
2397         $uid_gooduser = $max_uid - 11;
2398         $uid_eviluser = $max_uid - 12;
2399         $uid_slashuser = $max_uid - 13;
2400
2401         if ($unix_gids[0] < 0xffff - 8) {
2402                 $max_gid = 0xffff;
2403         } else {
2404                 $max_gid = $unix_gids[0];
2405         }
2406
2407         $gid_nobody = $max_gid - 1;
2408         $gid_nogroup = $max_gid - 2;
2409         $gid_root = $max_gid - 3;
2410         $gid_domusers = $max_gid - 4;
2411         $gid_domadmins = $max_gid - 5;
2412         $gid_userdup = $max_gid - 6;
2413         $gid_everyone = $max_gid - 7;
2414         $gid_force_user = $max_gid - 8;
2415
2416         ##
2417         ## create conffile
2418         ##
2419
2420         unless (open(CONF, ">$conffile")) {
2421                 warn("Unable to open $conffile");
2422                 return undef;
2423         }
2424
2425         my $interfaces = Samba::get_interfaces_config($server);
2426
2427         print CONF "
2428 [global]
2429         dcesrv:fuzz directory = $cachedir/fuzz
2430         netbios name = $netbios_name
2431         interfaces = $interfaces
2432         bind interfaces only = yes
2433         panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
2434         smbd:suicide mode = yes
2435         smbd:FSCTL_SMBTORTURE = yes
2436
2437         client min protocol = SMB2_02
2438         server min protocol = SMB2_02
2439
2440         server multi channel support = yes
2441
2442         workgroup = $domain
2443
2444         private dir = $privatedir
2445         binddns dir = $binddnsdir
2446         pid directory = $piddir
2447         lock directory = $lockdir
2448         log file = $logdir/log.\%m
2449         log level = $server_log_level
2450         debug pid = yes
2451         max log size = 0
2452
2453         state directory = $lockdir
2454         cache directory = $lockdir
2455
2456         passdb backend = tdbsam
2457
2458         time server = yes
2459
2460         add user script =               $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
2461         add group script =              $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action add --name %g
2462         add machine script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
2463         add user to group script =      $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type member --action add --member %u --name %g --group_path $nss_wrapper_group
2464         delete user script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
2465         delete group script =           $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action delete --name %g
2466         delete user from group script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type member --action delete --member %u --name %g --group_path $nss_wrapper_group
2467
2468         addprinter command =            $mod_printer_pl -a -s $conffile --
2469         deleteprinter command =         $mod_printer_pl -d -s $conffile --
2470
2471         eventlog list = application \"dns server\"
2472
2473         kernel oplocks = no
2474         kernel change notify = no
2475
2476         logging = file
2477         printing = bsd
2478         printcap name = /dev/null
2479
2480         winbindd socket directory = $wbsockdir
2481         nmbd:socket dir = $nmbdsockdir
2482         idmap config * : range = 100000-200000
2483         winbind enum users = yes
2484         winbind enum groups = yes
2485         winbind separator = /
2486         include system krb5 conf = no
2487
2488 #       min receivefile size = 4000
2489
2490         read only = no
2491
2492         smbd:sharedelay = 100000
2493         smbd:writetimeupdatedelay = 500000
2494         map hidden = no
2495         map system = no
2496         map readonly = no
2497         store dos attributes = yes
2498         create mask = 755
2499         dos filemode = yes
2500         strict rename = yes
2501         strict sync = yes
2502         mangled names = yes
2503         vfs objects = acl_xattr fake_acls xattr_tdb streams_depot time_audit full_audit
2504
2505         full_audit:syslog = no
2506         full_audit:success = none
2507         full_audit:failure = none
2508
2509         printing = vlp
2510         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
2511         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
2512         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
2513         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
2514         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
2515         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
2516         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
2517         lpq cache time = 0
2518         print notify backchannel = yes
2519
2520         ncalrpc dir = $prefix_abs/ncalrpc
2521
2522         # The samba3.blackbox.smbclient_s3 test uses this to test that
2523         # sending messages works, and that the %m sub works.
2524         message command = mv %s $shrdir/message.%m
2525
2526         # fsrvp server requires registry shares
2527         registry shares = yes
2528
2529         # Used by RPC SRVSVC tests
2530         add share command = $bindir_abs/smbaddshare
2531         change share command = $bindir_abs/smbchangeshare
2532         delete share command = $bindir_abs/smbdeleteshare
2533
2534         # fruit:copyfile is a global option
2535         fruit:copyfile = yes
2536
2537         #this does not mean that we use non-secure test env,
2538         #it just means we ALLOW one to be configured.
2539         allow insecure wide links = yes
2540
2541         include = $globalinjectconf
2542
2543         # Begin extra options
2544         $extra_options
2545         # End extra options
2546
2547         #Include user defined custom parameters if set
2548 ";
2549
2550         if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
2551                 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
2552         }
2553
2554         print CONF "
2555 [smbcacls_share]
2556         path = $smbcacls_share
2557         comment = smb username is [%U]
2558         msdfs root = yes
2559
2560 [smbcacls_sharedir_dfs]
2561         path = $smbcacls_sharedir_dfs
2562         comment = smb username is [%U]
2563 [tmp]
2564         path = $shrdir
2565         comment = smb username is [%U]
2566 [tmpsort]
2567         path = $shrdir
2568         comment = Load dirsort module
2569         vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
2570 [tmpenc]
2571         path = $shrdir
2572         comment = encrypt smb username is [%U]
2573         server smb encrypt = required
2574         vfs objects = dirsort
2575 [tmpguest]
2576         path = $shrdir
2577         guest ok = yes
2578 [guestonly]
2579         path = $shrdir
2580         guest only = yes
2581         guest ok = yes
2582 [forceuser]
2583         path = $shrdir
2584         force user = $unix_name
2585         guest ok = yes
2586 [forceuser_unixonly]
2587         comment = force a user with unix user SID and group SID
2588         path = $shrdir
2589         force user = pdbtest
2590         guest ok = yes
2591 [forceuser_wkngroup]
2592         comment = force a user with well-known group SID
2593         path = $shrdir
2594         force user = pdbtest_wkn
2595         guest ok = yes
2596 [forcegroup]
2597         path = $shrdir
2598         force group = nogroup
2599         guest ok = yes
2600 [ro-tmp]
2601         path = $ro_shrdir
2602         guest ok = yes
2603 [noperm]
2604         path = $noperm_shrdir
2605         wide links = yes
2606         guest ok = yes
2607 [write-list-tmp]
2608         path = $shrdir
2609         read only = yes
2610         write list = $unix_name
2611 [valid-users-tmp]
2612         path = $shrdir
2613         valid users = $unix_name
2614         access based share enum = yes
2615 [msdfs-share]
2616         path = $msdfs_shrdir
2617         msdfs root = yes
2618         msdfs shuffle referrals = yes
2619         guest ok = yes
2620 [hideunread]
2621         copy = tmp
2622         hide unreadable = yes
2623 [tmpcase]
2624         copy = tmp
2625         case sensitive = yes
2626 [hideunwrite]
2627         copy = tmp
2628         hide unwriteable files = yes
2629 [durable]
2630         copy = tmp
2631         kernel share modes = no
2632         kernel oplocks = no
2633         posix locking = no
2634 [fs_specific]
2635         copy = tmp
2636         $fs_specific_conf
2637 [print1]
2638         copy = tmp
2639         printable = yes
2640
2641 [print2]
2642         copy = print1
2643 [print3]
2644         copy = print1
2645         default devmode = no
2646
2647 [print_var_exp]
2648         copy = print1
2649         print command = $self->{srcdir}/source3/script/tests/printing/printing_var_exp_lpr_cmd.sh \"Windows user: %U\" \"UNIX user: %u\" \"Domain: %D\"
2650
2651 [lp]
2652         copy = print1
2653
2654 [nfs4acl_simple_40]
2655         path = $shrdir
2656         comment = smb username is [%U]
2657         nfs4:mode = simple
2658         nfs4acl_xattr:version = 40
2659         vfs objects = nfs4acl_xattr xattr_tdb
2660
2661 [nfs4acl_special_40]
2662         path = $shrdir
2663         comment = smb username is [%U]
2664         nfs4:mode = special
2665         nfs4acl_xattr:version = 40
2666         vfs objects = nfs4acl_xattr xattr_tdb
2667
2668 [nfs4acl_simple_41]
2669         path = $shrdir
2670         comment = smb username is [%U]
2671         nfs4:mode = simple
2672         vfs objects = nfs4acl_xattr xattr_tdb
2673
2674 [nfs4acl_xdr_40]
2675         path = $shrdir
2676         comment = smb username is [%U]
2677         vfs objects = nfs4acl_xattr xattr_tdb
2678         nfs4:mode = simple
2679         nfs4acl_xattr:encoding = xdr
2680         nfs4acl_xattr:version = 40
2681
2682 [nfs4acl_xdr_41]
2683         path = $shrdir
2684         comment = smb username is [%U]
2685         vfs objects = nfs4acl_xattr xattr_tdb
2686         nfs4:mode = simple
2687         nfs4acl_xattr:encoding = xdr
2688         nfs4acl_xattr:version = 41
2689
2690 [nfs4acl_nfs_40]
2691         path = $shrdir
2692         comment = smb username is [%U]
2693         vfs objects = nfs4acl_xattr xattr_tdb
2694         nfs4:mode = simple
2695         nfs4acl_xattr:encoding = nfs
2696         nfs4acl_xattr:version = 40
2697         nfs4acl_xattr:xattr_name = security.nfs4acl_xdr
2698
2699 [nfs4acl_nfs_41]
2700         path = $shrdir
2701         comment = smb username is [%U]
2702         vfs objects = nfs4acl_xattr xattr_tdb
2703         nfs4:mode = simple
2704         nfs4acl_xattr:encoding = nfs
2705         nfs4acl_xattr:version = 41
2706         nfs4acl_xattr:xattr_name = security.nfs4acl_xdr
2707
2708 [xcopy_share]
2709         path = $shrdir
2710         comment = smb username is [%U]
2711         create mask = 777
2712         force create mode = 777
2713 [posix_share]
2714         path = $shrdir
2715         comment = smb username is [%U]
2716         create mask = 0777
2717         force create mode = 0
2718         directory mask = 0777
2719         force directory mode = 0
2720         vfs objects = xattr_tdb streams_depot
2721 [aio]
2722         copy = durable
2723         aio read size = 1
2724         aio write size = 1
2725
2726 [print\$]
2727         copy = tmp
2728
2729 [vfs_fruit]
2730         path = $shrdir
2731         vfs objects = catia fruit streams_xattr acl_xattr xattr_tdb
2732         fruit:resource = file
2733         fruit:metadata = netatalk
2734         fruit:locking = netatalk
2735         fruit:encoding = native
2736         fruit:veto_appledouble = no
2737
2738 [vfs_fruit_xattr]
2739         path = $shrdir
2740         # This is used by vfs.fruit tests that require real fs xattr
2741         vfs objects = catia fruit streams_xattr acl_xattr
2742         fruit:resource = file
2743         fruit:metadata = netatalk
2744         fruit:locking = netatalk
2745         fruit:encoding = native
2746         fruit:veto_appledouble = no
2747
2748 [vfs_fruit_metadata_stream]
2749         path = $shrdir
2750         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
2751         fruit:resource = file
2752         fruit:metadata = stream
2753         fruit:veto_appledouble = no
2754
2755 [vfs_fruit_stream_depot]
2756         path = $shrdir
2757         vfs objects = fruit streams_depot acl_xattr xattr_tdb
2758         fruit:resource = stream
2759         fruit:metadata = stream
2760         fruit:veto_appledouble = no
2761
2762 [vfs_wo_fruit]
2763         path = $shrdir
2764         vfs objects = streams_xattr acl_xattr xattr_tdb
2765
2766 [vfs_wo_fruit_stream_depot]
2767         path = $shrdir
2768         vfs objects = streams_depot acl_xattr xattr_tdb
2769
2770 [vfs_fruit_timemachine]
2771         path = $shrdir
2772         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
2773         fruit:resource = file
2774         fruit:metadata = stream
2775         fruit:time machine = yes
2776         fruit:time machine max size = 32K
2777
2778 [vfs_fruit_wipe_intentionally_left_blank_rfork]
2779         path = $shrdir
2780         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
2781         fruit:resource = file
2782         fruit:metadata = stream
2783         fruit:wipe_intentionally_left_blank_rfork = true
2784         fruit:delete_empty_adfiles = false
2785         fruit:veto_appledouble = no
2786
2787 [vfs_fruit_delete_empty_adfiles]
2788         path = $shrdir
2789         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
2790         fruit:resource = file
2791         fruit:metadata = stream
2792         fruit:wipe_intentionally_left_blank_rfork = true
2793         fruit:delete_empty_adfiles = true
2794         fruit:veto_appledouble = no
2795
2796 [vfs_fruit_zero_fileid]
2797         path = $shrdir
2798         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
2799         fruit:resource = file
2800         fruit:metadata = stream
2801         fruit:zero_file_id=yes
2802
2803 [badname-tmp]
2804         path = $badnames_shrdir
2805         guest ok = yes
2806
2807 [manglenames_share]
2808         path = $manglenames_shrdir
2809         guest ok = yes
2810
2811 [dynamic_share]
2812         path = $shrdir/dynamic/%t
2813         guest ok = yes
2814         root preexec = mkdir %P
2815
2816 [widelinks_share]
2817         path = $widelinks_shrdir
2818         wide links = no
2819         guest ok = yes
2820
2821 [fsrvp_share]
2822         path = $fsrvp_shrdir
2823         comment = fake shapshots using rsync
2824         vfs objects = shell_snap shadow_copy2
2825         shell_snap:check path command = $fake_snap_pl --check
2826         shell_snap:create command = $fake_snap_pl --create
2827         shell_snap:delete command = $fake_snap_pl --delete
2828         # a relative path here fails, the snapshot dir is no longer found
2829         shadow:snapdir = $fsrvp_shrdir/.snapshots
2830
2831 [shadow1]
2832         path = $shadow_shrdir
2833         comment = previous versions snapshots under mount point
2834         vfs objects = shadow_copy2
2835         shadow:mountpoint = $shadow_mntdir
2836
2837 [shadow2]
2838         path = $shadow_shrdir
2839         comment = previous versions snapshots outside mount point
2840         vfs objects = shadow_copy2
2841         shadow:mountpoint = $shadow_mntdir
2842         shadow:snapdir = $shadow_tstdir/.snapshots
2843
2844 [shadow3]
2845         path = $shadow_shrdir
2846         comment = previous versions with subvolume snapshots, snapshots under base dir
2847         vfs objects = shadow_copy2
2848         shadow:mountpoint = $shadow_mntdir
2849         shadow:basedir = $shadow_basedir
2850         shadow:snapdir = $shadow_basedir/.snapshots
2851
2852 [shadow4]
2853         path = $shadow_shrdir
2854         comment = previous versions with subvolume snapshots, snapshots outside mount point
2855         vfs objects = shadow_copy2
2856         shadow:mountpoint = $shadow_mntdir
2857         shadow:basedir = $shadow_basedir
2858         shadow:snapdir = $shadow_tstdir/.snapshots
2859
2860 [shadow5]
2861         path = $shadow_shrdir
2862         comment = previous versions at volume root snapshots under mount point
2863         vfs objects = shadow_copy2
2864         shadow:mountpoint = $shadow_shrdir
2865
2866 [shadow6]
2867         path = $shadow_shrdir
2868         comment = previous versions at volume root snapshots outside mount point
2869         vfs objects = shadow_copy2
2870         shadow:mountpoint = $shadow_shrdir
2871         shadow:snapdir = $shadow_tstdir/.snapshots
2872
2873 [shadow7]
2874         path = $shadow_shrdir
2875         comment = previous versions snapshots everywhere
2876         vfs objects = shadow_copy2
2877         shadow:mountpoint = $shadow_mntdir
2878         shadow:snapdirseverywhere = yes
2879
2880 [shadow8]
2881         path = $shadow_shrdir
2882         comment = previous versions using snapsharepath
2883         vfs objects = shadow_copy2
2884         shadow:mountpoint = $shadow_mntdir
2885         shadow:snapdir = $shadow_tstdir/.snapshots
2886         shadow:snapsharepath = share
2887
2888 [shadow_fmt0]
2889         comment = Testing shadow:format with default option
2890         vfs object = shadow_copy2
2891         path = $shadow_shrdir
2892         read only = no
2893         guest ok = yes
2894         shadow:mountpoint = $shadow_mntdir
2895         shadow:basedir = $shadow_basedir
2896         shadow:snapdir = $shadow_basedir/.snapshots
2897         shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
2898
2899 [shadow_fmt1]
2900         comment = Testing shadow:format with only date component
2901         vfs object = shadow_copy2
2902         path = $shadow_shrdir
2903         read only = no
2904         guest ok = yes
2905         shadow:mountpoint = $shadow_mntdir
2906         shadow:basedir = $shadow_basedir
2907         shadow:snapdir = $shadow_basedir/.snapshots
2908         shadow:format = \@GMT-%Y-%m-%d
2909
2910 [shadow_fmt2]
2911         comment = Testing shadow:format with some hardcoded prefix
2912         vfs object = shadow_copy2
2913         path = $shadow_shrdir
2914         read only = no
2915         guest ok = yes
2916         shadow:mountpoint = $shadow_mntdir
2917         shadow:basedir = $shadow_basedir
2918         shadow:snapdir = $shadow_basedir/.snapshots
2919         shadow:format = snap\@GMT-%Y.%m.%d-%H.%M.%S
2920
2921 [shadow_fmt3]
2922         comment = Testing shadow:format with modified format
2923         vfs object = shadow_copy2
2924         path = $shadow_shrdir
2925         read only = no
2926         guest ok = yes
2927         shadow:mountpoint = $shadow_mntdir
2928         shadow:basedir = $shadow_basedir
2929         shadow:snapdir = $shadow_basedir/.snapshots
2930         shadow:format = \@GMT-%Y.%m.%d-%H_%M_%S-snap
2931
2932 [shadow_fmt4]
2933         comment = Testing shadow:snapprefix regex
2934         vfs object = shadow_copy2
2935         path = $shadow_shrdir
2936         read only = no
2937         guest ok = yes
2938         shadow:mountpoint = $shadow_mntdir
2939         shadow:basedir = $shadow_basedir
2940         shadow:snapdir = $shadow_basedir/.snapshots
2941         shadow:snapprefix = \^s[a-z]*p\$
2942         shadow:format = _GMT-%Y.%m.%d-%H.%M.%S
2943
2944 [shadow_fmt5]
2945         comment = Testing shadow:snapprefix with delim regex
2946         vfs object = shadow_copy2
2947         path = $shadow_shrdir
2948         read only = no
2949         guest ok = yes
2950         shadow:mountpoint = $shadow_mntdir
2951         shadow:basedir = $shadow_basedir
2952         shadow:snapdir = $shadow_basedir/.snapshots
2953         shadow:delimiter = \@GMT
2954         shadow:snapprefix = [a-z]*
2955         shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
2956
2957 [shadow_wl]
2958         path = $shadow_shrdir
2959         comment = previous versions with wide links allowed
2960         vfs objects = shadow_copy2
2961         shadow:mountpoint = $shadow_mntdir
2962         wide links = yes
2963
2964 [shadow_write]
2965         path = $shadow_tstdir
2966         comment = previous versions snapshots under mount point
2967         vfs objects = shadow_copy2 streams_xattr error_inject
2968         aio write size = 0
2969         error_inject:pwrite = EBADF
2970         shadow:mountpoint = $shadow_tstdir
2971
2972 [dfq]
2973         path = $shrdir/dfree
2974         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2975         admin users = $unix_name
2976         include = $dfqconffile
2977 [dfq_cache]
2978         path = $shrdir/dfree
2979         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2980         admin users = $unix_name
2981         include = $dfqconffile
2982         dfree cache time = 60
2983 [dfq_owner]
2984         path = $shrdir/dfree
2985         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2986         inherit owner = yes
2987         include = $dfqconffile
2988 [quotadir]
2989         path = $shrdir/quota
2990         admin users = $unix_name
2991
2992 [acl_xattr_ign_sysacl_posix]
2993         copy = tmp
2994         acl_xattr:ignore system acls = yes
2995         acl_xattr:default acl style = posix
2996 [acl_xattr_ign_sysacl_windows]
2997         copy = tmp
2998         acl_xattr:ignore system acls = yes
2999         acl_xattr:default acl style = windows
3000
3001 [mangle_illegal]
3002         copy = tmp
3003         mangled names = illegal
3004
3005 [nosymlinks]
3006         copy = tmp
3007         path = $nosymlinks_shrdir
3008         follow symlinks = no
3009
3010 [local_symlinks]
3011         copy = tmp
3012         path = $local_symlinks_shrdir
3013         follow symlinks = yes
3014
3015 [kernel_oplocks]
3016         copy = tmp
3017         kernel oplocks = yes
3018         vfs objects = streams_xattr xattr_tdb
3019
3020 [streams_xattr]
3021         copy = tmp
3022         vfs objects = streams_xattr xattr_tdb
3023
3024 [compound_find]
3025         copy = tmp
3026         smbd:find async delay usec = 10000
3027 [error_inject]
3028         copy = tmp
3029         vfs objects = error_inject
3030         include = $errorinjectconf
3031
3032 [delay_inject]
3033         copy = tmp
3034         vfs objects = delay_inject
3035         kernel share modes = no
3036         kernel oplocks = no
3037         posix locking = no
3038         include = $delayinjectconf
3039
3040 [aio_delay_inject]
3041         copy = tmp
3042         vfs objects = delay_inject
3043         delay_inject:pread_send = 2000
3044         delay_inject:pwrite_send = 2000
3045
3046 [brl_delay_inject1]
3047         copy = tmp
3048         vfs objects = delay_inject
3049         delay_inject:brl_lock_windows = 90
3050         delay_inject:brl_lock_windows_use_timer = yes
3051
3052 [brl_delay_inject2]
3053         copy = tmp
3054         vfs objects = delay_inject
3055         delay_inject:brl_lock_windows = 90
3056         delay_inject:brl_lock_windows_use_timer = no
3057
3058 [delete_readonly]
3059         path = $prefix_abs/share
3060         delete readonly = yes
3061
3062 [enc_desired]
3063         path = $prefix_abs/share
3064         vfs objects =
3065         server smb encrypt = desired
3066
3067 [enc_off]
3068         path = $prefix_abs/share
3069         vfs objects =
3070         server smb encrypt = off
3071
3072 [notify_priv]
3073         copy = tmp
3074         honor change notify privilege = yes
3075
3076 [acls_non_canonical]
3077         copy = tmp
3078         acl flag inherited canonicalization = no
3079         ";
3080
3081         close(CONF);
3082
3083         my $net = Samba::bindir_path($self, "net");
3084         my $cmd = "";
3085         $cmd .= "UID_WRAPPER_ROOT=1 ";
3086         $cmd .= "SMB_CONF_PATH=\"$conffile\" ";
3087         $cmd .= "$net setlocalsid $samsid";
3088
3089         my $net_ret = system($cmd);
3090         if ($net_ret != 0) {
3091             warn("net setlocalsid failed: $net_ret\n$cmd");
3092             return undef;
3093         }
3094
3095         unless (open(ERRORCONF, ">$errorinjectconf")) {
3096                 warn("Unable to open $errorinjectconf");
3097                 return undef;
3098         }
3099         close(ERRORCONF);
3100
3101         unless (open(DELAYCONF, ">$delayinjectconf")) {
3102                 warn("Unable to open $delayinjectconf");
3103                 return undef;
3104         }
3105         close(DELAYCONF);
3106
3107         unless (open(DFQCONF, ">$dfqconffile")) {
3108                 warn("Unable to open $dfqconffile");
3109                 return undef;
3110         }
3111         close(DFQCONF);
3112
3113         unless (open(DELAYCONF, ">$globalinjectconf")) {
3114                 warn("Unable to open $globalinjectconf");
3115                 return undef;
3116         }
3117         close(DELAYCONF);
3118
3119         ##
3120         ## create a test account
3121         ##
3122
3123         unless (open(PASSWD, ">$nss_wrapper_passwd")) {
3124            warn("Unable to open $nss_wrapper_passwd");
3125            return undef;
3126         } 
3127         print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
3128 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
3129 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
3130 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
3131 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
3132 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
3133 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
3134 smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
3135 user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
3136 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
3137 gooduser:x:$uid_gooduser:$gid_domusers:gooduser gecos:$prefix_abs:/bin/false
3138 eviluser:x:$uid_eviluser:$gid_domusers:eviluser gecos::/bin/false
3139 slashuser:x:$uid_slashuser:$gid_domusers:slashuser gecos:/:/bin/false
3140 ";
3141         if ($unix_uid != 0) {
3142                 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
3143 ";
3144         }
3145         close(PASSWD);
3146
3147         unless (open(GROUP, ">$nss_wrapper_group")) {
3148              warn("Unable to open $nss_wrapper_group");
3149              return undef;
3150         }
3151         print GROUP "nobody:x:$gid_nobody:
3152 nogroup:x:$gid_nogroup:nobody
3153 $unix_name-group:x:$unix_gids[0]:
3154 domusers:X:$gid_domusers:
3155 domadmins:X:$gid_domadmins:
3156 userdup:x:$gid_userdup:$unix_name
3157 everyone:x:$gid_everyone:
3158 force_user:x:$gid_force_user:
3159 ";
3160         if ($unix_gids[0] != 0) {
3161                 print GROUP "root:x:$gid_root:
3162 ";
3163         }
3164
3165         close(GROUP);
3166
3167         ## hosts
3168         my $hostname = lc($server);
3169         unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
3170                 warn("Unable to open $nss_wrapper_hosts");
3171                 return undef;
3172         }
3173         print HOSTS "${server_ip} ${hostname}.${dns_domain} ${hostname}\n";
3174         print HOSTS "${server_ipv6} ${hostname}.${dns_domain} ${hostname}\n";
3175         close(HOSTS);
3176
3177         $resolv_conf = "$privatedir/no_resolv.conf" unless defined($resolv_conf);
3178
3179         foreach my $evlog (@eventlog_list) {
3180                 my $evlogtdb = "$eventlogdir/$evlog.tdb";
3181                 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
3182                 close(EVENTLOG);
3183         }
3184
3185         $createuser_env{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
3186         $createuser_env{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
3187         $createuser_env{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
3188         $createuser_env{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
3189         if ($ENV{SAMBA_DNS_FAKING}) {
3190                 $createuser_env{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
3191         } else {
3192                 $createuser_env{RESOLV_WRAPPER_CONF} = $resolv_conf;
3193         }
3194         $createuser_env{RESOLV_CONF} = $resolv_conf;
3195
3196         createuser($self, $unix_name, $password, $conffile, \%createuser_env) || die("Unable to create user");
3197         createuser($self, "force_user", $password, $conffile, \%createuser_env) || die("Unable to create force_user");
3198         createuser($self, "smbget_user", $password, $conffile, \%createuser_env) || die("Unable to create smbget_user");
3199         createuser($self, "user1", $password, $conffile, \%createuser_env) || die("Unable to create user1");
3200         createuser($self, "user2", $password, $conffile, \%createuser_env) || die("Unable to create user2");
3201         createuser($self, "gooduser", $password, $conffile, \%createuser_env) || die("Unable to create gooduser");
3202         createuser($self, "eviluser", $password, $conffile, \%createuser_env) || die("Unable to create eviluser");
3203         createuser($self, "slashuser", $password, $conffile, \%createuser_env) || die("Unable to create slashuser");
3204
3205         open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
3206         print DNS_UPDATE_LIST "A $server. $server_ip\n";
3207         print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
3208         close(DNS_UPDATE_LIST);
3209
3210         print "DONE\n";
3211
3212         $ret{SERVER_IP} = $server_ip;
3213         $ret{SERVER_IPV6} = $server_ipv6;
3214         $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
3215         $ret{NMBD_TEST_LOG_POS} = 0;
3216         $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
3217         $ret{WINBINDD_TEST_LOG_POS} = 0;
3218         $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
3219         $ret{SMBD_TEST_LOG_POS} = 0;
3220         $ret{SERVERCONFFILE} = $conffile;
3221         $ret{TESTENV_DIR} = $prefix_abs;
3222         $ret{CONFIGURATION} ="--configfile=$conffile";
3223         $ret{LOCK_DIR} = $lockdir;
3224         $ret{SERVER} = $server;
3225         $ret{USERNAME} = $unix_name;
3226         $ret{USERID} = $unix_uid;
3227         $ret{DOMAIN} = $domain;
3228         $ret{SAMSID} = $samsid;
3229         $ret{NETBIOSNAME} = $server;
3230         $ret{PASSWORD} = $password;
3231         $ret{PIDDIR} = $piddir;
3232         $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
3233         $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
3234         $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
3235         $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
3236         $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
3237         $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
3238         $ret{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
3239         $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
3240         $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
3241         if ($ENV{SAMBA_DNS_FAKING}) {
3242                 $ret{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
3243         } else {
3244                 $ret{RESOLV_WRAPPER_CONF} = $resolv_conf;
3245         }
3246         $ret{RESOLV_CONF} = $resolv_conf;
3247         $ret{LOCAL_PATH} = "$shrdir";
3248         $ret{LOGDIR} = $logdir;
3249
3250         #
3251         # Avoid hitting system krb5.conf -
3252         # An env that needs Kerberos will reset this to the real
3253         # value.
3254         #
3255         $ret{KRB5_CONFIG} = abs_path($prefix) . "/no_krb5.conf";
3256
3257         # Define KRB5CCNAME for each environment we set up
3258         $ret{KRB5_CCACHE} = abs_path($prefix) . "/krb5ccache";
3259         $ENV{KRB5CCNAME} = $ret{KRB5_CCACHE};
3260
3261         return \%ret;
3262 }
3263
3264 sub wait_for_start($$$$$)
3265 {
3266         my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
3267         my $cmd;
3268         my $netcmd;
3269         my $ret;
3270
3271         if ($nmbd eq "yes") {
3272                 my $count = 0;
3273
3274                 # give time for nbt server to register its names
3275                 print "checking for nmbd\n";
3276
3277                 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
3278                 my $nmblookup = Samba::bindir_path($self, "nmblookup");
3279
3280                 do {
3281                         $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
3282                         if ($ret != 0) {
3283                                 sleep(1);
3284                         } else {
3285                                 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
3286                                 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
3287                                 system("$nmblookup $envvars->{CONFIGURATION} -U 10.255.255.255 __SAMBA__");
3288                                 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
3289                         }
3290                         $count++;
3291                 } while ($ret != 0 && $count < 10);
3292                 if ($count == 10) {
3293                         print "NMBD not reachable after 10 retries\n";
3294                         teardown_env($self, $envvars);
3295                         return 0;
3296                 }
3297         }
3298
3299         if ($winbindd eq "yes") {
3300             print "checking for winbindd\n";
3301             my $count = 0;
3302             $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
3303             $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
3304             $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
3305             $cmd .= Samba::bindir_path($self, "wbinfo") . " --ping-dc";
3306
3307             do {
3308                 $ret = system($cmd);
3309                 if ($ret != 0) {
3310                     sleep(1);
3311                 }
3312                 $count++;
3313             } while ($ret != 0 && $count < 20);
3314             if ($count == 20) {
3315                 print "WINBINDD not reachable after 20 seconds\n";
3316                 teardown_env($self, $envvars);
3317                 return 0;
3318             }
3319         }
3320
3321         if ($smbd eq "yes") {
3322             # make sure smbd is also up set
3323             print "wait for smbd\n";
3324
3325             my $count = 0;
3326             do {
3327                 if (defined($envvars->{GNUTLS_FORCE_FIPS_MODE})) {
3328                         # We don't have NTLM in FIPS mode, so lets use
3329                         # smbcontrol instead of smbclient.
3330                         $cmd = Samba::bindir_path($self, "smbcontrol");
3331                         $cmd .= " $envvars->{CONFIGURATION}";
3332                         $cmd .= " smbd ping";
3333                 } else {
3334                         # This uses NTLM which is not available in FIPS
3335                         $cmd = Samba::bindir_path($self, "smbclient");
3336                         $cmd .= " $envvars->{CONFIGURATION}";
3337                         $cmd .= " -L $envvars->{SERVER}";
3338                         $cmd .= " -U%";
3339                         $cmd .= " -I $envvars->{SERVER_IP}";
3340                         $cmd .= " -p 139";
3341                 }
3342
3343                 $ret = system($cmd);
3344                 if ($ret != 0) {
3345                     sleep(1);
3346                 }
3347                 $count++
3348             } while ($ret != 0 && $count < 20);
3349             if ($count == 20) {
3350                 print "SMBD failed to start up in a reasonable time (20sec)\n";
3351                 teardown_env($self, $envvars);
3352                 return 0;
3353             }
3354         }
3355
3356         # Ensure we have domain users mapped.
3357         $netcmd = "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
3358         $netcmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
3359         $netcmd .= "UID_WRAPPER_ROOT='1' ";
3360         $netcmd .= Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} ";
3361
3362         $cmd = $netcmd . "groupmap delete ntgroup=domusers";
3363         $ret = system($cmd);
3364
3365         $cmd = $netcmd . "groupmap add rid=513 unixgroup=domusers type=domain";
3366         $ret = system($cmd);
3367         if ($ret != 0) {
3368                 print("\"$cmd\" failed\n");
3369                 return 1;
3370         }
3371
3372         $cmd = $netcmd . "groupmap delete ntgroup=domadmins";
3373         $ret = system($cmd);
3374
3375         $cmd = $netcmd . "groupmap add rid=512 unixgroup=domadmins type=domain";
3376         $ret = system($cmd);
3377         if ($ret != 0) {
3378                 print("\"$cmd\" failed\n");
3379                 return 1;
3380         }
3381
3382         $cmd = $netcmd . "groupmap delete ntgroup=everyone";
3383         $ret = system($cmd);
3384
3385         $cmd = $netcmd . "groupmap add sid=S-1-1-0 unixgroup=everyone type=builtin";
3386         $ret = system($cmd);
3387         if ($ret != 0) {
3388                 print("\"$cmd\" failed\n");
3389                 return 1;
3390         }
3391
3392         # note: creating builtin groups requires winbindd for the
3393         # unix id allocator
3394         my $create_builtin_users = "no";
3395         if ($winbindd eq "yes") {
3396                 $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
3397                 $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
3398                 $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
3399                 $cmd .= Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545";
3400                 my $wbinfo_out = qx($cmd 2>&1);
3401                 if ($? != 0) {
3402                         # wbinfo doesn't give us a better error code then
3403                         # WBC_ERR_DOMAIN_NOT_FOUND, but at least that's
3404                         # different then WBC_ERR_WINBIND_NOT_AVAILABLE
3405                         if ($wbinfo_out !~ /WBC_ERR_DOMAIN_NOT_FOUND/) {
3406                                 print("Failed to run \"wbinfo --sid-to-gid=S-1-5-32-545\": $wbinfo_out");
3407                                 teardown_env($self, $envvars);
3408                                 return 0;
3409                         }
3410                         $create_builtin_users = "yes";
3411                 }
3412         }
3413         if ($create_builtin_users eq "yes") {
3414             $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
3415             $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
3416             $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
3417             $cmd .= Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} ";
3418             $cmd .= "sam createbuiltingroup Users";
3419             $ret = system($cmd);
3420             if ($ret != 0) {
3421                 print "Failed to create BUILTIN\\Users group\n";
3422                 teardown_env($self, $envvars);
3423                 return 0;
3424             }
3425
3426             $cmd = Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} ";
3427             $cmd .= "cache del IDMAP/SID2XID/S-1-5-32-545";
3428             system($cmd);
3429
3430             $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
3431             $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
3432             $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
3433             $cmd .= Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545";
3434             $ret = system($cmd);
3435             if ($ret != 0) {
3436                 print "Missing \"BUILTIN\\Users\", did net sam createbuiltingroup Users fail?\n";
3437                 teardown_env($self, $envvars);
3438                 return 0;
3439             }
3440         }
3441
3442         print $self->getlog_env($envvars);
3443
3444         return 1;
3445 }
3446
3447 ##
3448 ## provision and start of ctdb
3449 ##
3450 sub setup_ctdb($$)
3451 {
3452         my ($self, $prefix) = @_;
3453         my $num_nodes = 3;
3454
3455         my $data = $self->provision_ctdb($prefix, $num_nodes);
3456         $data or return undef;
3457
3458         my $rc = $self->check_or_start_ctdb($data);
3459         if (not $rc) {
3460                 print("check_or_start_ctdb() failed\n");
3461                 return undef;
3462         }
3463
3464         $rc = $self->wait_for_start_ctdb($data);
3465         if (not $rc) {
3466                 print "Cluster startup failed\n";
3467                 return undef;
3468         }
3469
3470         return $data;
3471 }
3472
3473 sub provision_ctdb($$$$)
3474 {
3475         my ($self, $prefix, $num_nodes, $no_delete_prefix) = @_;
3476         my $rc;
3477
3478         print "PROVISIONING CTDB...\n";
3479
3480         my $prefix_abs = abs_path($prefix);
3481
3482         #
3483         # check / create directories:
3484         #
3485         die ("prefix_abs = ''") if $prefix_abs eq "";
3486         die ("prefix_abs = '/'") if $prefix_abs eq "/";
3487
3488         mkdir ($prefix_abs, 0777);
3489
3490         print "CREATE CTDB TEST ENVIRONMENT in '$prefix_abs'...\n";
3491
3492         if (not defined($no_delete_prefix) or not $no_delete_prefix) {
3493                 system("rm -rf $prefix_abs/*");
3494         }
3495
3496         #
3497         # Per-node data
3498         #
3499         my @nodes = ();
3500         for (my $i = 0; $i < $num_nodes; $i++) {
3501                 my %node = ();
3502                 my $server_name = "ctdb${i}";
3503                 my $pub_iface = Samba::get_interface($server_name);
3504                 my $ip = Samba::get_ipv4_addr($server_name);
3505
3506                 $node{NODE_NUMBER} = "$i";
3507                 $node{SERVER_NAME} = "$server_name";
3508                 $node{SOCKET_WRAPPER_DEFAULT_IFACE} = "$pub_iface";
3509                 $node{IP} = "$ip";
3510
3511                 push(@nodes, \%node);
3512         }
3513
3514         #
3515         # nodes
3516         #
3517         my $nodes_file = "$prefix/nodes.in";
3518         unless (open(NODES, ">$nodes_file")) {
3519                 warn("Unable to open nodesfile '$nodes_file'");
3520                 return undef;
3521         }
3522         for (my $i = 0; $i < $num_nodes; $i++) {
3523                 my $ip = $nodes[$i]->{IP};
3524                 print NODES "${ip}\n";
3525         }
3526         close(NODES);
3527
3528         #
3529         # local_daemons.sh setup
3530         #
3531         # Socket wrapper setup is done by selftest.pl, so don't use
3532         # the CTDB-specific setup
3533         #
3534         my $cmd;
3535         $cmd .= "ctdb/tests/local_daemons.sh " . $prefix_abs . " setup";
3536         $cmd .= " -n " . $num_nodes;
3537         $cmd .= " -N " . $nodes_file;
3538         # CTDB should not attempt to manage public addresses -
3539         # clients should just connect to CTDB private addresses
3540         $cmd .= " -P " . "/dev/null";
3541
3542         my $ret = system($cmd);
3543         if ($ret != 0) {
3544                 print("\"$cmd\" failed\n");
3545                 return undef;
3546         }
3547
3548         #
3549         # Unix domain socket and node directory for each daemon
3550         #
3551         for (my $i = 0; $i < $num_nodes; $i++) {
3552                 my ($cmd, $ret, $out);
3553
3554                 my $cmd_prefix = "ctdb/tests/local_daemons.sh ${prefix_abs}";
3555
3556                 #
3557                 # socket
3558                 #
3559
3560                 $cmd = "${cmd_prefix} print-socket ${i}";
3561
3562                 $out = `$cmd`;
3563                 $ret = $?;
3564                 if ($ret != 0) {
3565                     print("\"$cmd\" failed\n");
3566                     return undef;
3567                 }
3568                 chomp $out;
3569                 $nodes[$i]->{SOCKET_FILE} = "$out";
3570
3571                 #
3572                 # node directory
3573                 #
3574
3575                 $cmd = "${cmd_prefix} onnode ${i} 'echo \$CTDB_BASE'";
3576
3577                 $out = `$cmd`;
3578                 $ret = $?;
3579                 if ($ret != 0) {
3580                     print("\"$cmd\" failed\n");
3581                     return undef;
3582                 }
3583                 chomp $out;
3584                 $nodes[$i]->{NODE_PREFIX} = "$out";
3585         }
3586
3587         my %ret = ();
3588
3589         $ret{CTDB_PREFIX} = "$prefix";
3590         $ret{NUM_NODES} = $num_nodes;
3591         $ret{CTDB_NODES} = \@nodes;
3592         $ret{CTDB_NODES_FILE} = $nodes_file;
3593
3594         return \%ret;
3595 }
3596
3597 sub check_or_start_ctdb($$) {
3598         my ($self, $data) = @_;
3599
3600         my $prefix = $data->{CTDB_PREFIX};
3601         my $num_nodes = $data->{NUM_NODES};
3602         my $nodes = $data->{CTDB_NODES};
3603         my $STDIN_READER;
3604
3605         # Share a single stdin pipe for all nodes
3606         pipe($STDIN_READER, $data->{CTDB_STDIN_PIPE});
3607
3608         for (my $i = 0; $i < $num_nodes; $i++) {
3609                 my $node = $nodes->[$i];
3610
3611                 $node->{STDIN_PIPE} = $data->{CTDB_STDIN_PIPE};
3612
3613                 my $cmd = "ctdb/tests/local_daemons.sh";
3614                 my @full_cmd = ("$cmd", "$prefix", "start", "$i");
3615                 my $daemon_ctx = {
3616                         NAME => "ctdbd",
3617                         BINARY_PATH => $cmd,
3618                         FULL_CMD => [ @full_cmd ],
3619                         TEE_STDOUT => 1,
3620                         LOG_FILE => "/dev/null",
3621                         ENV_VARS => {},
3622                 };
3623
3624                 print "STARTING CTDBD (node ${i})\n";
3625
3626                 # This does magic with $STDIN_READER, so use it
3627                 my $ret = Samba::fork_and_exec($self,
3628                                                $node,
3629                                                $daemon_ctx,
3630                                                $STDIN_READER);
3631
3632                 if ($ret == 0) {
3633                         print("\"$cmd\" failed\n");
3634                         teardown_env_ctdb($self, $data);
3635                         return 0;
3636                 }
3637         }
3638
3639         close($STDIN_READER);
3640
3641         return 1;
3642 }
3643
3644 sub wait_for_start_ctdb($$)
3645 {
3646         my ($self, $data) = @_;
3647
3648         my $prefix = $data->{CTDB_PREFIX};
3649
3650         print "Wait for ctdbd...\n";
3651
3652         my $ctdb = Samba::bindir_path($self, "ctdb");
3653         my $cmd;
3654         $cmd .= "ctdb/tests/local_daemons.sh ${prefix} onnode all";
3655         $cmd .= " ${ctdb} nodestatus all 2>&1";
3656
3657         my $count = 0;
3658         my $wait_seconds = 60;
3659         my $out;
3660
3661         until ($count > $wait_seconds) {
3662                 $out = `$cmd`;
3663                 my $ret = $?;
3664                 if ($ret == 0) {
3665                         print "\ncluster became healthy\n";
3666                         last;
3667                 }
3668                 print "Waiting for CTDB...\n";
3669                 sleep(1);
3670                 $count++;
3671         }
3672
3673         if ($count > $wait_seconds) {
3674                 print "\nGiving up to wait for CTDB...\n";
3675                 print "${out}\n\n";
3676                 print "CTDB log:\n";
3677                 $cmd = "ctdb/tests/local_daemons.sh ${prefix} print-log all >&2";
3678                 system($cmd);
3679                 teardown_env_ctdb($self, $data);
3680                 return 0;
3681         }
3682
3683         print "\nCTDB initialized\n";
3684
3685         return 1;
3686 }
3687
3688 1;