bcbf0addf2bcbb13541072c1c203a638a23a31dc
[nivanova/samba-autobuild/.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 package Samba3;
7
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12 use target::Samba;
13 use File::Path 'remove_tree';
14
15 sub have_ads($) {
16         my ($self) = @_;
17         my $found_ads = 0;
18         my $smbd_build_options = Samba::bindir_path($self, "smbd") . " -b|";
19         open(IN, $smbd_build_options) or die("Unable to run $smbd_build_options: $!");
20
21         while (<IN>) {
22                 if (/WITH_ADS/) {
23                        $found_ads = 1;
24                 }
25         }
26         close IN;
27
28         # If we were not built with ADS support, pretend we were never even available
29         print "smbd does not have ADS support\n" unless $found_ads;
30         return $found_ads;
31 }
32
33 # return smb.conf parameters applicable to @path, based on the underlying
34 # filesystem type
35 sub get_fs_specific_conf($$)
36 {
37         my ($self, $path) = @_;
38         my $mods = "";
39         my $stat_out = `stat --file-system $path` or return "";
40
41         if ($stat_out =~ m/Type:\s+btrfs/) {
42                 $mods .= "streams_xattr btrfs";
43         }
44
45         if ($mods) {
46                 return "vfs objects = $mods";
47         }
48
49         return undef;
50 }
51
52 sub new($$) {
53         my ($classname, $bindir, $srcdir, $server_maxtime) = @_;
54         my $self = { vars => {},
55                      bindir => $bindir,
56                      srcdir => $srcdir,
57                      server_maxtime => $server_maxtime
58         };
59         bless $self;
60         return $self;
61 }
62
63 sub teardown_env($$)
64 {
65         my ($self, $envvars) = @_;
66         my $count = 0;
67
68         # This should cause smbd to terminate gracefully
69         close($envvars->{STDIN_PIPE});
70
71         my $smbdpid = $envvars->{SMBD_TL_PID};
72         my $nmbdpid = $envvars->{NMBD_TL_PID};
73         my $winbinddpid = $envvars->{WINBINDD_TL_PID};
74
75         # This should give it time to write out the gcov data
76         until ($count > 20) {
77             my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
78             my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
79             my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
80             if ($smbdchild == -1
81                 && $nmbdchild == -1
82                 && $winbinddchild == -1) {
83                 last;
84             }
85             sleep(1);
86             $count++;
87         }
88
89         if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
90             return;
91         }
92
93         $self->stop_sig_term($smbdpid);
94         $self->stop_sig_term($nmbdpid);
95         $self->stop_sig_term($winbinddpid);
96
97         $count = 0;
98         until ($count > 10) {
99             my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
100             my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
101             my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
102             if ($smbdchild == -1
103                 && $nmbdchild == -1
104                 && $winbinddchild == -1) {
105                 last;
106             }
107             sleep(1);
108             $count++;
109         }
110
111         if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
112             return;
113         }
114
115         warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
116         $self->stop_sig_kill($smbdpid);
117         $self->stop_sig_kill($nmbdpid);
118         $self->stop_sig_kill($winbinddpid);
119
120         return 0;
121 }
122
123 sub getlog_env_app($$$)
124 {
125         my ($self, $envvars, $name) = @_;
126
127         my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
128         my $out = $title;
129
130         open(LOG, "<".$envvars->{$name."_TEST_LOG"});
131
132         seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
133         while (<LOG>) {
134                 $out .= $_;
135         }
136         $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
137         close(LOG);
138
139         return "" if $out eq $title;
140  
141         return $out;
142 }
143
144 sub getlog_env($$)
145 {
146         my ($self, $envvars) = @_;
147         my $ret = "";
148
149         $ret .= $self->getlog_env_app($envvars, "SMBD");
150         $ret .= $self->getlog_env_app($envvars, "NMBD");
151         $ret .= $self->getlog_env_app($envvars, "WINBINDD");
152
153         return $ret;
154 }
155
156 sub check_env($$)
157 {
158         my ($self, $envvars) = @_;
159
160         my $childpid = waitpid(-1, WNOHANG);
161
162         # TODO ...
163         return 1;
164 }
165
166 # Declare the environments Samba3 makes available.
167 # To be set up, they will be called as
168 #   samba3->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
169 %Samba3::ENV_DEPS = (
170         # name              => [dep_1, dep_2, ...],
171         nt4_dc              => [],
172         nt4_dc_schannel     => [],
173
174         simpleserver        => [],
175         fileserver          => [],
176         maptoguest          => [],
177         ktest               => [],
178
179         nt4_member          => ["nt4_dc"],
180
181         ad_member           => ["ad_dc"],
182         ad_member_rfc2307   => ["ad_dc_ntvfs"],
183         ad_member_idmap_rid => ["ad_dc"],
184         ad_member_idmap_ad  => ["ad_dc"],
185 );
186
187 sub setup_nt4_dc
188 {
189         my ($self, $path) = @_;
190
191         print "PROVISIONING NT4 DC...";
192
193         my $nt4_dc_options = "
194         domain master = yes
195         domain logons = yes
196         lanman auth = yes
197         ntlm auth = yes
198         raw NTLMv2 auth = yes
199         server schannel = auto
200
201         rpc_server:epmapper = external
202         rpc_server:spoolss = external
203         rpc_server:lsarpc = external
204         rpc_server:samr = external
205         rpc_server:netlogon = external
206         rpc_server:register_embedded_np = yes
207         rpc_server:FssagentRpc = external
208
209         rpc_daemon:epmd = fork
210         rpc_daemon:spoolssd = fork
211         rpc_daemon:lsasd = fork
212         rpc_daemon:fssd = fork
213         fss: sequence timeout = 1
214         check parent directory delete on close = yes
215 ";
216
217         my $vars = $self->provision($path, "SAMBA-TEST",
218                                     "LOCALNT4DC2",
219                                     "localntdc2pass",
220                                     $nt4_dc_options);
221
222         $vars or return undef;
223
224         if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
225                return undef;
226         }
227
228         $vars->{DOMSID} = $vars->{SAMSID};
229         $vars->{DC_SERVER} = $vars->{SERVER};
230         $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
231         $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
232         $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
233         $vars->{DC_USERNAME} = $vars->{USERNAME};
234         $vars->{DC_PASSWORD} = $vars->{PASSWORD};
235
236         return $vars;
237 }
238
239 sub setup_nt4_dc_schannel
240 {
241         my ($self, $path) = @_;
242
243         print "PROVISIONING NT4 DC WITH SERVER SCHANNEL ...";
244
245         my $pdc_options = "
246         domain master = yes
247         domain logons = yes
248         lanman auth = yes
249
250         rpc_server:epmapper = external
251         rpc_server:spoolss = external
252         rpc_server:lsarpc = external
253         rpc_server:samr = external
254         rpc_server:netlogon = external
255         rpc_server:register_embedded_np = yes
256
257         rpc_daemon:epmd = fork
258         rpc_daemon:spoolssd = fork
259         rpc_daemon:lsasd = fork
260
261         server schannel = yes
262         # used to reproduce bug #12772
263         server max protocol = SMB2_02
264 ";
265
266         my $vars = $self->provision($path, "NT4SCHANNEL",
267                                     "LOCALNT4DC9",
268                                     "localntdc9pass",
269                                     $pdc_options);
270
271         $vars or return undef;
272
273         if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
274                return undef;
275         }
276
277         $vars->{DOMSID} = $vars->{SAMSID};
278         $vars->{DC_SERVER} = $vars->{SERVER};
279         $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
280         $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
281         $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
282         $vars->{DC_USERNAME} = $vars->{USERNAME};
283         $vars->{DC_PASSWORD} = $vars->{PASSWORD};
284
285         return $vars;
286 }
287
288 sub setup_nt4_member
289 {
290         my ($self, $prefix, $nt4_dc_vars) = @_;
291         my $count = 0;
292         my $rc;
293
294         print "PROVISIONING MEMBER...";
295
296         my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
297         $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
298
299         my $member_options = "
300         security = domain
301         dbwrap_tdb_mutexes:* = yes
302         ${require_mutexes}
303 ";
304         my $ret = $self->provision($prefix, $nt4_dc_vars->{DOMAIN},
305                                    "LOCALNT4MEMBER3",
306                                    "localnt4member3pass",
307                                    $member_options);
308
309         $ret or return undef;
310
311         my $nmblookup = Samba::bindir_path($self, "nmblookup");
312         do {
313                 print "Waiting for the LOGON SERVER registration ...\n";
314                 $rc = system("$nmblookup $ret->{CONFIGURATION} $ret->{DOMAIN}\#1c");
315                 if ($rc != 0) {
316                         sleep(1);
317                 }
318                 $count++;
319         } while ($rc != 0 && $count < 10);
320         if ($count == 10) {
321                 print "NMBD not reachable after 10 retries\n";
322                 teardown_env($self, $ret);
323                 return 0;
324         }
325
326         my $net = Samba::bindir_path($self, "net");
327         my $cmd = "";
328         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
329         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
330         $cmd .= "$net rpc join $ret->{CONFIGURATION} $nt4_dc_vars->{DOMAIN} member";
331         $cmd .= " -U$nt4_dc_vars->{USERNAME}\%$nt4_dc_vars->{PASSWORD}";
332
333         if (system($cmd) != 0) {
334             warn("Join failed\n$cmd");
335             return undef;
336         }
337
338         my $cmd = "";
339         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
340         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
341         $cmd .= "$net $ret->{CONFIGURATION} primarytrust dumpinfo | grep -q 'REDACTED SECRET VALUES'";
342
343         if (system($cmd) != 0) {
344             warn("check failed\n$cmd");
345             return undef;
346         }
347
348         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
349                return undef;
350         }
351
352         $ret->{DOMSID} = $nt4_dc_vars->{DOMSID};
353         $ret->{DC_SERVER} = $nt4_dc_vars->{SERVER};
354         $ret->{DC_SERVER_IP} = $nt4_dc_vars->{SERVER_IP};
355         $ret->{DC_SERVER_IPV6} = $nt4_dc_vars->{SERVER_IPV6};
356         $ret->{DC_NETBIOSNAME} = $nt4_dc_vars->{NETBIOSNAME};
357         $ret->{DC_USERNAME} = $nt4_dc_vars->{USERNAME};
358         $ret->{DC_PASSWORD} = $nt4_dc_vars->{PASSWORD};
359
360         return $ret;
361 }
362
363 sub setup_ad_member
364 {
365         my ($self, $prefix, $dcvars) = @_;
366
367         my $prefix_abs = abs_path($prefix);
368         my @dirs = ();
369
370         # If we didn't build with ADS, pretend this env was never available
371         if (not $self->have_ads()) {
372                 return "UNKNOWN";
373         }
374
375         print "PROVISIONING S3 AD MEMBER...";
376
377         mkdir($prefix_abs, 0777);
378
379         my $share_dir="$prefix_abs/share";
380         push(@dirs, $share_dir);
381
382         my $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}";
383         push(@dirs, $substitution_path);
384
385         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/U_alice";
386         push(@dirs, $substitution_path);
387
388         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/U_alice/G_domain users";
389         push(@dirs, $substitution_path);
390
391         # Using '/' as the winbind separator is a bad idea ...
392         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}";
393         push(@dirs, $substitution_path);
394
395         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice";
396         push(@dirs, $substitution_path);
397
398         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice/g_$dcvars->{DOMAIN}";
399         push(@dirs, $substitution_path);
400
401         $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice/g_$dcvars->{DOMAIN}/domain users";
402         push(@dirs, $substitution_path);
403
404         my $member_options = "
405         security = ads
406         workgroup = $dcvars->{DOMAIN}
407         realm = $dcvars->{REALM}
408         netbios aliases = foo bar
409         template homedir = /home/%D/%G/%U
410
411 [sub_dug]
412         path = $share_dir/D_%D/U_%U/G_%G
413         writeable = yes
414
415 [sub_dug2]
416         path = $share_dir/D_%D/u_%u/g_%g
417         writeable = yes
418
419 ";
420
421         my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
422                                    "LOCALADMEMBER",
423                                    "loCalMemberPass",
424                                    $member_options,
425                                    $dcvars->{SERVER_IP},
426                                    $dcvars->{SERVER_IPV6});
427
428         $ret or return undef;
429
430         mkdir($_, 0777) foreach(@dirs);
431
432         close(USERMAP);
433         $ret->{DOMAIN} = $dcvars->{DOMAIN};
434         $ret->{REALM} = $dcvars->{REALM};
435         $ret->{DOMSID} = $dcvars->{DOMSID};
436
437         my $ctx;
438         $ctx = {};
439         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
440         $ctx->{domain} = $dcvars->{DOMAIN};
441         $ctx->{realm} = $dcvars->{REALM};
442         $ctx->{dnsname} = lc($dcvars->{REALM});
443         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
444         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
445         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
446         Samba::mk_krb5_conf($ctx, "");
447
448         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
449
450         my $net = Samba::bindir_path($self, "net");
451         my $cmd = "";
452         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
453         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
454                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
455         } else {
456                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
457         }
458         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
459         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
460         $cmd .= "$net join $ret->{CONFIGURATION}";
461         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
462
463         if (system($cmd) != 0) {
464             warn("Join failed\n$cmd");
465             return undef;
466         }
467
468         # We need world access to this share, as otherwise the domain
469         # administrator from the AD domain provided by Samba4 can't
470         # access the share for tests.
471         chmod 0777, "$prefix/share";
472
473         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
474                 return undef;
475         }
476
477         $ret->{DC_SERVER} = $dcvars->{SERVER};
478         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
479         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
480         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
481         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
482         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
483
484         return $ret;
485 }
486
487 sub setup_ad_member_rfc2307
488 {
489         my ($self, $prefix, $dcvars) = @_;
490
491         # If we didn't build with ADS, pretend this env was never available
492         if (not $self->have_ads()) {
493                 return "UNKNOWN";
494         }
495
496         print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
497
498         my $member_options = "
499         security = ads
500         workgroup = $dcvars->{DOMAIN}
501         realm = $dcvars->{REALM}
502         idmap cache time = 0
503         idmap negative cache time = 0
504         idmap config * : backend = autorid
505         idmap config * : range = 1000000-1999999
506         idmap config * : rangesize = 100000
507         idmap config $dcvars->{DOMAIN} : backend = rfc2307
508         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
509         idmap config $dcvars->{DOMAIN} : ldap_server = ad
510         idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
511         idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
512
513         password server = $dcvars->{SERVER}
514 ";
515
516         my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
517                                    "RFC2307MEMBER",
518                                    "loCalMemberPass",
519                                    $member_options,
520                                    $dcvars->{SERVER_IP},
521                                    $dcvars->{SERVER_IPV6});
522
523         $ret or return undef;
524
525         close(USERMAP);
526         $ret->{DOMAIN} = $dcvars->{DOMAIN};
527         $ret->{REALM} = $dcvars->{REALM};
528         $ret->{DOMSID} = $dcvars->{DOMSID};
529
530         my $ctx;
531         my $prefix_abs = abs_path($prefix);
532         $ctx = {};
533         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
534         $ctx->{domain} = $dcvars->{DOMAIN};
535         $ctx->{realm} = $dcvars->{REALM};
536         $ctx->{dnsname} = lc($dcvars->{REALM});
537         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
538         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
539         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
540         Samba::mk_krb5_conf($ctx, "");
541
542         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
543
544         my $net = Samba::bindir_path($self, "net");
545         my $cmd = "";
546         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
547         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
548                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
549         } else {
550                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
551         }
552         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
553         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
554         $cmd .= "$net join $ret->{CONFIGURATION}";
555         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
556
557         if (system($cmd) != 0) {
558             warn("Join failed\n$cmd");
559             return undef;
560         }
561
562         # We need world access to this share, as otherwise the domain
563         # administrator from the AD domain provided by Samba4 can't
564         # access the share for tests.
565         chmod 0777, "$prefix/share";
566
567         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
568                 return undef;
569         }
570
571         $ret->{DC_SERVER} = $dcvars->{SERVER};
572         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
573         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
574         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
575         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
576         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
577
578         return $ret;
579 }
580
581 sub setup_ad_member_idmap_rid
582 {
583         my ($self, $prefix, $dcvars) = @_;
584
585         # If we didn't build with ADS, pretend this env was never available
586         if (not $self->have_ads()) {
587                 return "UNKNOWN";
588         }
589
590         print "PROVISIONING S3 AD MEMBER WITH idmap_rid config...";
591
592         my $member_options = "
593         security = ads
594         workgroup = $dcvars->{DOMAIN}
595         realm = $dcvars->{REALM}
596         idmap config * : backend = tdb
597         idmap config * : range = 1000000-1999999
598         idmap config $dcvars->{DOMAIN} : backend = rid
599         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
600 ";
601
602         my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
603                                    "IDMAPRIDMEMBER",
604                                    "loCalMemberPass",
605                                    $member_options,
606                                    $dcvars->{SERVER_IP},
607                                    $dcvars->{SERVER_IPV6});
608
609         $ret or return undef;
610
611         close(USERMAP);
612         $ret->{DOMAIN} = $dcvars->{DOMAIN};
613         $ret->{REALM} = $dcvars->{REALM};
614         $ret->{DOMSID} = $dcvars->{DOMSID};
615
616         my $ctx;
617         my $prefix_abs = abs_path($prefix);
618         $ctx = {};
619         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
620         $ctx->{domain} = $dcvars->{DOMAIN};
621         $ctx->{realm} = $dcvars->{REALM};
622         $ctx->{dnsname} = lc($dcvars->{REALM});
623         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
624         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
625         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
626         Samba::mk_krb5_conf($ctx, "");
627
628         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
629
630         my $net = Samba::bindir_path($self, "net");
631         my $cmd = "";
632         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
633         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
634                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
635         } else {
636                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
637         }
638         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
639         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
640         $cmd .= "$net join $ret->{CONFIGURATION}";
641         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
642
643         if (system($cmd) != 0) {
644             warn("Join failed\n$cmd");
645             return undef;
646         }
647
648         # We need world access to this share, as otherwise the domain
649         # administrator from the AD domain provided by Samba4 can't
650         # access the share for tests.
651         chmod 0777, "$prefix/share";
652
653         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
654                 return undef;
655         }
656
657         $ret->{DC_SERVER} = $dcvars->{SERVER};
658         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
659         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
660         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
661         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
662         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
663
664         return $ret;
665 }
666
667 sub setup_ad_member_idmap_ad
668 {
669         my ($self, $prefix, $dcvars) = @_;
670
671         # If we didn't build with ADS, pretend this env was never available
672         if (not $self->have_ads()) {
673                 return "UNKNOWN";
674         }
675
676         print "PROVISIONING S3 AD MEMBER WITH idmap_ad config...";
677
678         my $member_options = "
679         security = ads
680         workgroup = $dcvars->{DOMAIN}
681         realm = $dcvars->{REALM}
682         password server = $dcvars->{SERVER}
683         idmap config * : backend = tdb
684         idmap config * : range = 1000000-1999999
685         idmap config $dcvars->{DOMAIN} : backend = ad
686         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
687 ";
688
689         my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
690                                    "IDMAPADMEMBER",
691                                    "loCalMemberPass",
692                                    $member_options,
693                                    $dcvars->{SERVER_IP},
694                                    $dcvars->{SERVER_IPV6});
695
696         $ret or return undef;
697
698         close(USERMAP);
699         $ret->{DOMAIN} = $dcvars->{DOMAIN};
700         $ret->{REALM} = $dcvars->{REALM};
701         $ret->{DOMSID} = $dcvars->{DOMSID};
702
703         my $ctx;
704         my $prefix_abs = abs_path($prefix);
705         $ctx = {};
706         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
707         $ctx->{domain} = $dcvars->{DOMAIN};
708         $ctx->{realm} = $dcvars->{REALM};
709         $ctx->{dnsname} = lc($dcvars->{REALM});
710         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
711         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
712         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
713         Samba::mk_krb5_conf($ctx, "");
714
715         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
716
717         my $net = Samba::bindir_path($self, "net");
718         my $cmd = "";
719         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
720         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
721                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
722         } else {
723                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
724         }
725         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
726         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
727         $cmd .= "$net join $ret->{CONFIGURATION}";
728         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
729
730         if (system($cmd) != 0) {
731             warn("Join failed\n$cmd");
732             return undef;
733         }
734
735         # We need world access to this share, as otherwise the domain
736         # administrator from the AD domain provided by Samba4 can't
737         # access the share for tests.
738         chmod 0777, "$prefix/share";
739
740         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
741                 return undef;
742         }
743
744         $ret->{DC_SERVER} = $dcvars->{SERVER};
745         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
746         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
747         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
748         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
749         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
750
751         return $ret;
752 }
753
754 sub setup_simpleserver
755 {
756         my ($self, $path) = @_;
757
758         print "PROVISIONING simple server...";
759
760         my $prefix_abs = abs_path($path);
761
762         my $simpleserver_options = "
763         lanman auth = yes
764         ntlm auth = yes
765         vfs objects = xattr_tdb streams_depot
766         change notify = no
767         smb encrypt = off
768
769 [vfs_aio_pthread]
770         path = $prefix_abs/share
771         read only = no
772         vfs objects = aio_pthread
773         aio_pthread:aio open = yes
774         smbd:async dosmode = no
775
776 [vfs_aio_pthread_async_dosmode_default1]
777         path = $prefix_abs/share
778         read only = no
779         vfs objects = aio_pthread
780         store dos attributes = yes
781         aio_pthread:aio open = yes
782         smbd:async dosmode = yes
783
784 [vfs_aio_pthread_async_dosmode_default2]
785         path = $prefix_abs/share
786         read only = no
787         vfs objects = aio_pthread xattr_tdb
788         store dos attributes = yes
789         aio_pthread:aio open = yes
790         smbd:async dosmode = yes
791
792 [vfs_aio_pthread_async_dosmode_force_sync1]
793         path = $prefix_abs/share
794         read only = no
795         vfs objects = aio_pthread
796         store dos attributes = yes
797         aio_pthread:aio open = yes
798         smbd:async dosmode = yes
799         # This simulates non linux systems
800         smbd:force sync user path safe threadpool = yes
801         smbd:force sync user chdir safe threadpool = yes
802         smbd:force sync root path safe threadpool = yes
803         smbd:force sync root chdir safe threadpool = yes
804
805 [vfs_aio_pthread_async_dosmode_force_sync2]
806         path = $prefix_abs/share
807         read only = no
808         vfs objects = aio_pthread xattr_tdb
809         store dos attributes = yes
810         aio_pthread:aio open = yes
811         smbd:async dosmode = yes
812         # This simulates non linux systems
813         smbd:force sync user path safe threadpool = yes
814         smbd:force sync user chdir safe threadpool = yes
815         smbd:force sync root path safe threadpool = yes
816         smbd:force sync root chdir safe threadpool = yes
817
818 [vfs_aio_fork]
819         path = $prefix_abs/share
820         vfs objects = aio_fork
821         read only = no
822         vfs_aio_fork:erratic_testing_mode=yes
823
824 [dosmode]
825         path = $prefix_abs/share
826         vfs objects =
827         store dos attributes = yes
828         hide files = /hidefile/
829         hide dot files = yes
830
831 [enc_desired]
832         path = $prefix_abs/share
833         vfs objects =
834         smb encrypt = desired
835 ";
836
837         my $vars = $self->provision($path, "WORKGROUP",
838                                     "LOCALSHARE4",
839                                     "local4pass",
840                                     $simpleserver_options);
841
842         $vars or return undef;
843
844         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
845                return undef;
846         }
847
848         return $vars;
849 }
850
851 sub setup_fileserver
852 {
853         my ($self, $path) = @_;
854         my $prefix_abs = abs_path($path);
855         my $srcdir_abs = abs_path($self->{srcdir});
856
857         print "PROVISIONING file server ...\n";
858
859         my @dirs = ();
860
861         mkdir($prefix_abs, 0777);
862
863         my $usershare_dir="$prefix_abs/lib/usershare";
864
865         mkdir("$prefix_abs/lib", 0755);
866         remove_tree($usershare_dir);
867         mkdir($usershare_dir, 01770);
868
869         my $share_dir="$prefix_abs/share";
870
871         # Create share directory structure
872         my $lower_case_share_dir="$share_dir/lower-case";
873         push(@dirs, $lower_case_share_dir);
874
875         my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
876         push(@dirs, $lower_case_share_dir_30000);
877
878         my $dfree_share_dir="$share_dir/dfree";
879         push(@dirs, $dfree_share_dir);
880         push(@dirs, "$dfree_share_dir/subdir1");
881         push(@dirs, "$dfree_share_dir/subdir2");
882         push(@dirs, "$dfree_share_dir/subdir3");
883
884         my $quotadir_dir="$share_dir/quota";
885         push(@dirs, $quotadir_dir);
886
887         my $valid_users_sharedir="$share_dir/valid_users";
888         push(@dirs,$valid_users_sharedir);
889
890         my $offline_sharedir="$share_dir/offline";
891         push(@dirs,$offline_sharedir);
892
893         my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
894         push(@dirs, $force_user_valid_users_dir);
895
896         my $smbget_sharedir="$share_dir/smbget";
897         push(@dirs,$smbget_sharedir);
898
899         my $tarmode_sharedir="$share_dir/tarmode";
900         push(@dirs,$tarmode_sharedir);
901
902         my $usershare_sharedir="$share_dir/usershares";
903         push(@dirs,$usershare_sharedir);
904
905         my $fileserver_options = "
906         kernel change notify = yes
907
908         usershare path = $usershare_dir
909         usershare max shares = 10
910         usershare allow guests = yes
911         usershare prefix allow list = $usershare_sharedir
912
913         get quota command = $prefix_abs/getset_quota.py
914         set quota command = $prefix_abs/getset_quota.py
915 [lowercase]
916         path = $lower_case_share_dir
917         comment = smb username is [%U]
918         case sensitive = True
919         default case = lower
920         preserve case = no
921         short preserve case = no
922 [lowercase-30000]
923         path = $lower_case_share_dir_30000
924         comment = smb username is [%U]
925         case sensitive = True
926         default case = lower
927         preserve case = no
928         short preserve case = no
929 [dfree]
930         path = $dfree_share_dir
931         comment = smb username is [%U]
932         dfree command = $srcdir_abs/testprogs/blackbox/dfree.sh
933 [valid-users-access]
934         path = $valid_users_sharedir
935         valid users = +userdup
936 [offline]
937         path = $offline_sharedir
938         vfs objects = offline
939
940 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
941 # RH BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
942 [force_user_valid_users]
943         path = $force_user_valid_users_dir
944         comment = force user with valid users combination test share
945         valid users = +force_user
946         force user = force_user
947         force group = everyone
948         write list = force_user
949
950 [smbget]
951         path = $smbget_sharedir
952         comment = smb username is [%U]
953         guest ok = yes
954 [ign_sysacls]
955         path = $share_dir
956         comment = ignore system acls
957         acl_xattr:ignore system acls = yes
958 [inherit_owner]
959         path = $share_dir
960         comment = inherit owner
961         inherit owner = yes
962 [inherit_owner_u]
963         path = $share_dir
964         comment = inherit only unix owner
965         inherit owner = unix only
966         acl_xattr:ignore system acls = yes
967 ";
968
969         my $vars = $self->provision($path, "WORKGROUP",
970                                     "FILESERVER",
971                                     "fileserver",
972                                     $fileserver_options,
973                                     undef,
974                                     undef,
975                                     1);
976
977         $vars or return undef;
978
979         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
980                return undef;
981         }
982
983
984         mkdir($_, 0777) foreach(@dirs);
985
986         ## Create case sensitive lower case share dir
987         foreach my $file ('a'..'z') {
988                 my $full_path = $lower_case_share_dir . '/' . $file;
989                 open my $fh, '>', $full_path;
990                 # Add some content to file
991                 print $fh $full_path;
992                 close $fh;
993         }
994
995         for (my $file = 1; $file < 51; ++$file) {
996                 my $full_path = $lower_case_share_dir . '/' . $file;
997                 open my $fh, '>', $full_path;
998                 # Add some content to file
999                 print $fh $full_path;
1000                 close $fh;
1001         }
1002
1003         # Create content for 30000 share
1004         foreach my $file ('a'..'z') {
1005                 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
1006                 open my $fh, '>', $full_path;
1007                 # Add some content to file
1008                 print $fh $full_path;
1009                 close $fh;
1010         }
1011
1012         for (my $file = 1; $file < 30001; ++$file) {
1013                 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
1014                 open my $fh, '>', $full_path;
1015                 # Add some content to file
1016                 print $fh $full_path;
1017                 close $fh;
1018         }
1019
1020         ##
1021         ## create a listable file in valid_users_share
1022         ##
1023         my $valid_users_target = "$valid_users_sharedir/foo";
1024         unless (open(VALID_USERS_TARGET, ">$valid_users_target")) {
1025                 warn("Unable to open $valid_users_target");
1026                 return undef;
1027         }
1028         close(VALID_USERS_TARGET);
1029         chmod 0644, $valid_users_target;
1030
1031         return $vars;
1032 }
1033
1034 sub setup_ktest
1035 {
1036         my ($self, $prefix) = @_;
1037
1038         # If we didn't build with ADS, pretend this env was never available
1039         if (not $self->have_ads()) {
1040                 return "UNKNOWN";
1041         }
1042
1043         print "PROVISIONING server with security=ads...";
1044
1045         my $ktest_options = "
1046         workgroup = KTEST
1047         realm = ktest.samba.example.com
1048         security = ads
1049         username map = $prefix/lib/username.map
1050         server signing = required
1051         server min protocol = SMB3_00
1052         client max protocol = SMB3
1053
1054         # This disables NTLM auth against the local SAM, which
1055         # we use can then test this setting by.
1056         ntlm auth = disabled
1057 ";
1058
1059         my $ret = $self->provision($prefix, "KTEST",
1060                                    "LOCALKTEST6",
1061                                    "localktest6pass",
1062                                    $ktest_options);
1063
1064         $ret or return undef;
1065
1066         my $ctx;
1067         my $prefix_abs = abs_path($prefix);
1068         $ctx = {};
1069         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
1070         $ctx->{domain} = "KTEST";
1071         $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
1072         $ctx->{dnsname} = lc($ctx->{realm});
1073         $ctx->{kdc_ipv4} = "0.0.0.0";
1074         $ctx->{kdc_ipv6} = "::";
1075         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
1076         Samba::mk_krb5_conf($ctx, "");
1077
1078         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
1079
1080         open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
1081         print USERMAP "
1082 $ret->{USERNAME} = KTEST\\Administrator
1083 ";
1084         close(USERMAP);
1085
1086 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
1087 #Samba4 DC with the same parameters as are being used here.  The
1088 #domain SID is S-1-5-21-1071277805-689288055-3486227160
1089         $ret->{SAMSID} = "S-1-5-21-1911091480-1468226576-2729736297";
1090         $ret->{DOMSID} = "S-1-5-21-1071277805-689288055-3486227160";
1091
1092         system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
1093         chmod 0600, "$prefix/private/secrets.tdb";
1094
1095 #Make sure there's no old ntdb file.
1096         system("rm -f $prefix/private/secrets.ntdb");
1097
1098 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
1099 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
1100 #
1101 #and having in krb5.conf:
1102 # ticket_lifetime = 799718400
1103 # renew_lifetime = 799718400
1104 #
1105 # The commands for the -2 keytab where were:
1106 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
1107 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
1108 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
1109 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
1110 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
1111 #
1112 # and then for the -3 keytab, I did
1113 #
1114 # net changetrustpw; kdestroy and the same again.
1115 #
1116 # This creates a credential cache with a very long lifetime (2036 at
1117 # at 2011-04), and shows that running 'net changetrustpw' does not
1118 # break existing logins (for the secrets.tdb method at least).
1119 #
1120
1121         $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
1122
1123         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
1124         chmod 0600, "$prefix/krb5_ccache-2";
1125
1126         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
1127         chmod 0600, "$prefix/krb5_ccache-3";
1128
1129         # We need world access to this share, as otherwise the domain
1130         # administrator from the AD domain provided by ktest can't
1131         # access the share for tests.
1132         chmod 0777, "$prefix/share";
1133
1134         if (not $self->check_or_start($ret, "yes", "no", "yes")) {
1135                return undef;
1136         }
1137         return $ret;
1138 }
1139
1140 sub setup_maptoguest
1141 {
1142         my ($self, $path) = @_;
1143
1144         print "PROVISIONING maptoguest...";
1145
1146         my $options = "
1147 map to guest = bad user
1148 ntlm auth = yes
1149 ";
1150
1151         my $vars = $self->provision($path, "WORKGROUP",
1152                                     "maptoguest",
1153                                     "maptoguestpass",
1154                                     $options);
1155
1156         $vars or return undef;
1157
1158         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
1159                return undef;
1160         }
1161
1162         return $vars;
1163 }
1164
1165 sub stop_sig_term($$) {
1166         my ($self, $pid) = @_;
1167         kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1168 }
1169
1170 sub stop_sig_kill($$) {
1171         my ($self, $pid) = @_;
1172         kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1173 }
1174
1175 sub write_pid($$$)
1176 {
1177         my ($env_vars, $app, $pid) = @_;
1178
1179         open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
1180         print PID $pid;
1181         close(PID);
1182 }
1183
1184 sub read_pid($$)
1185 {
1186         my ($env_vars, $app) = @_;
1187
1188         open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
1189         my $pid = <PID>;
1190         close(PID);
1191         return $pid;
1192 }
1193
1194 sub check_or_start($$$$$) {
1195         my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
1196
1197         # use a pipe for stdin in the child processes. This allows
1198         # those processes to monitor the pipe for EOF to ensure they
1199         # exit when the test script exits
1200         pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
1201
1202         unlink($env_vars->{NMBD_TEST_LOG});
1203         print "STARTING NMBD...";
1204         my $pid = fork();
1205         if ($pid == 0) {
1206                 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
1207                 open STDERR, '>&STDOUT';
1208
1209                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1210
1211                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1212                 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.nmbd";
1213                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1214                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1215
1216                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1217                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1218                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1219                 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1220                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1221                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1222                 $ENV{UID_WRAPPER_ROOT} = "1";
1223
1224                 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
1225
1226                 if ($nmbd ne "yes") {
1227                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1228                                 my $signame = shift;
1229                                 print("Skip nmbd received signal $signame");
1230                                 exit 0;
1231                         };
1232                         sleep($self->{server_maxtime});
1233                         exit 0;
1234                 }
1235
1236                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
1237                 my @optargs = ("-d0");
1238                 if (defined($ENV{NMBD_OPTIONS})) {
1239                         @optargs = split(/ /, $ENV{NMBD_OPTIONS});
1240                 }
1241                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1242                 if(defined($ENV{NMBD_VALGRIND})) { 
1243                         @preargs = split(/ /, $ENV{NMBD_VALGRIND});
1244                 }
1245                 my @args = ("-F", "--no-process-group",
1246                             "-s", $env_vars->{SERVERCONFFILE},
1247                             "-l", $env_vars->{LOGDIR});
1248                 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
1249                         push(@args, "--log-stdout");
1250                 }
1251
1252                 close($env_vars->{STDIN_PIPE});
1253                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1254
1255                 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1256                         or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1257         }
1258         $env_vars->{NMBD_TL_PID} = $pid;
1259         write_pid($env_vars, "nmbd", $pid);
1260         print "DONE\n";
1261
1262         unlink($env_vars->{WINBINDD_TEST_LOG});
1263         print "STARTING WINBINDD...";
1264         $pid = fork();
1265         if ($pid == 0) {
1266                 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
1267                 open STDERR, '>&STDOUT';
1268
1269                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1270
1271                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1272                 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.winbindd";
1273                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1274                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1275
1276                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1277                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1278                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1279                 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1280                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1281                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1282                 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1283                         $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1284                 } else {
1285                         $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1286                 }
1287                 $ENV{UID_WRAPPER_ROOT} = "1";
1288
1289                 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
1290
1291                 if ($winbindd ne "yes") {
1292                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1293                                 my $signame = shift;
1294                                 print("Skip winbindd received signal $signame");
1295                                 exit 0;
1296                         };
1297                         sleep($self->{server_maxtime});
1298                         exit 0;
1299                 }
1300
1301                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
1302                 my @optargs = ("-d0");
1303                 if (defined($ENV{WINBINDD_OPTIONS})) {
1304                         @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
1305                 }
1306                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1307                 if(defined($ENV{WINBINDD_VALGRIND})) {
1308                         @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
1309                 }
1310                 my @args = ("-F", "--no-process-group",
1311                             "-s", $env_vars->{SERVERCONFFILE},
1312                             "-l", $env_vars->{LOGDIR});
1313                 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
1314                         push(@args, "--stdout");
1315                 }
1316
1317                 close($env_vars->{STDIN_PIPE});
1318                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1319
1320                 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1321                         or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1322         }
1323         $env_vars->{WINBINDD_TL_PID} = $pid;
1324         write_pid($env_vars, "winbindd", $pid);
1325         print "DONE\n";
1326
1327         unlink($env_vars->{SMBD_TEST_LOG});
1328         print "STARTING SMBD...";
1329         $pid = fork();
1330         if ($pid == 0) {
1331                 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
1332                 open STDERR, '>&STDOUT';
1333
1334                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1335
1336                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1337                 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.smbd";
1338                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1339                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1340
1341                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1342                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1343                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1344                 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1345                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1346                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1347                 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1348                         $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1349                 } else {
1350                         $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1351                 }
1352                 $ENV{UID_WRAPPER_ROOT} = "1";
1353
1354                 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
1355
1356                 if ($smbd ne "yes") {
1357                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1358                                 my $signame = shift;
1359                                 print("Skip smbd received signal $signame");
1360                                 exit 0;
1361                         };
1362                         sleep($self->{server_maxtime});
1363                         exit 0;
1364                 }
1365
1366                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
1367                 my @optargs = ("-d0");
1368                 if (defined($ENV{SMBD_OPTIONS})) {
1369                         @optargs = split(/ /, $ENV{SMBD_OPTIONS});
1370                 }
1371                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1372                 if(defined($ENV{SMBD_VALGRIND})) {
1373                         @preargs = split(/ /,$ENV{SMBD_VALGRIND});
1374                 }
1375                 my @args = ("-F", "--no-process-group",
1376                             "-s", $env_vars->{SERVERCONFFILE},
1377                             "-l", $env_vars->{LOGDIR});
1378                 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
1379                         push(@args, "--log-stdout");
1380                 }
1381
1382                 close($env_vars->{STDIN_PIPE});
1383                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1384
1385                 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1386                         or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1387         }
1388         $env_vars->{SMBD_TL_PID} = $pid;
1389         write_pid($env_vars, "smbd", $pid);
1390         print "DONE\n";
1391
1392         close(STDIN_READER);
1393
1394         return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
1395 }
1396
1397 sub createuser($$$$$)
1398 {
1399         my ($self, $username, $password, $conffile, $env) = @_;
1400         my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $username > /dev/null";
1401
1402         keys %$env;
1403         while(my($var, $val) = each %$env) {
1404                 $cmd = "$var=\"$val\" $cmd";
1405         }
1406
1407         unless (open(PWD, "|$cmd")) {
1408             warn("Unable to set password for $username account\n$cmd");
1409             return undef;
1410         }
1411         print PWD "$password\n$password\n";
1412         unless (close(PWD)) {
1413             warn("Unable to set password for $username account\n$cmd");
1414             return undef;
1415         }
1416 }
1417
1418 sub provision($$$$$$$$$)
1419 {
1420         my ($self, $prefix, $domain, $server, $password, $extra_options, $dc_server_ip, $dc_server_ipv6, $no_delete_prefix) = @_;
1421
1422         ##
1423         ## setup the various environment variables we need
1424         ##
1425
1426         my $samsid = Samba::random_domain_sid();
1427         my $swiface = Samba::get_interface($server);
1428         my %ret = ();
1429         my %createuser_env = ();
1430         my $server_ip = "127.0.0.$swiface";
1431         my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
1432
1433         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
1434         chomp $unix_name;
1435         my $unix_uid = $>;
1436         my $unix_gids_str = $);
1437         my @unix_gids = split(" ", $unix_gids_str);
1438
1439         my $prefix_abs = abs_path($prefix);
1440         my $bindir_abs = abs_path($self->{bindir});
1441
1442         my @dirs = ();
1443
1444         my $shrdir="$prefix_abs/share";
1445         push(@dirs,$shrdir);
1446
1447         my $libdir="$prefix_abs/lib";
1448         push(@dirs,$libdir);
1449
1450         my $piddir="$prefix_abs/pid";
1451         push(@dirs,$piddir);
1452
1453         my $privatedir="$prefix_abs/private";
1454         push(@dirs,$privatedir);
1455
1456         my $binddnsdir = "$prefix_abs/bind-dns";
1457         push(@dirs, $binddnsdir);
1458
1459         my $lockdir="$prefix_abs/lockdir";
1460         push(@dirs,$lockdir);
1461
1462         my $eventlogdir="$prefix_abs/lockdir/eventlog";
1463         push(@dirs,$eventlogdir);
1464
1465         my $logdir="$prefix_abs/logs";
1466         push(@dirs,$logdir);
1467
1468         my $driver32dir="$shrdir/W32X86";
1469         push(@dirs,$driver32dir);
1470
1471         my $driver64dir="$shrdir/x64";
1472         push(@dirs,$driver64dir);
1473
1474         my $driver40dir="$shrdir/WIN40";
1475         push(@dirs,$driver40dir);
1476
1477         my $ro_shrdir="$shrdir/root-tmp";
1478         push(@dirs,$ro_shrdir);
1479
1480         my $msdfs_shrdir="$shrdir/msdfsshare";
1481         push(@dirs,$msdfs_shrdir);
1482
1483         my $msdfs_deeppath="$msdfs_shrdir/deeppath";
1484         push(@dirs,$msdfs_deeppath);
1485
1486         my $badnames_shrdir="$shrdir/badnames";
1487         push(@dirs,$badnames_shrdir);
1488
1489         my $lease1_shrdir="$shrdir/SMB2_10";
1490         push(@dirs,$lease1_shrdir);
1491
1492         my $lease2_shrdir="$shrdir/SMB3_00";
1493         push(@dirs,$lease2_shrdir);
1494
1495         my $manglenames_shrdir="$shrdir/manglenames";
1496         push(@dirs,$manglenames_shrdir);
1497
1498         my $widelinks_shrdir="$shrdir/widelinks";
1499         push(@dirs,$widelinks_shrdir);
1500
1501         my $widelinks_linkdir="$shrdir/widelinks_foo";
1502         push(@dirs,$widelinks_linkdir);
1503
1504         my $shadow_tstdir="$shrdir/shadow";
1505         push(@dirs,$shadow_tstdir);
1506         my $shadow_mntdir="$shadow_tstdir/mount";
1507         push(@dirs,$shadow_mntdir);
1508         my $shadow_basedir="$shadow_mntdir/base";
1509         push(@dirs,$shadow_basedir);
1510         my $shadow_shrdir="$shadow_basedir/share";
1511         push(@dirs,$shadow_shrdir);
1512
1513         my $nosymlinks_shrdir="$shrdir/nosymlinks";
1514         push(@dirs,$nosymlinks_shrdir);
1515
1516         my $local_symlinks_shrdir="$shrdir/local_symlinks";
1517         push(@dirs,$local_symlinks_shrdir);
1518
1519         # this gets autocreated by winbindd
1520         my $wbsockdir="$prefix_abs/winbindd";
1521
1522         my $nmbdsockdir="$prefix_abs/nmbd";
1523         unlink($nmbdsockdir);
1524
1525         ## 
1526         ## create the test directory layout
1527         ##
1528         die ("prefix_abs = ''") if $prefix_abs eq "";
1529         die ("prefix_abs = '/'") if $prefix_abs eq "/";
1530
1531         mkdir($prefix_abs, 0777);
1532         print "CREATE TEST ENVIRONMENT IN '$prefix'...";
1533         if (not defined($no_delete_prefix) or not $no_delete_prefix) {
1534             system("rm -rf $prefix_abs/*");
1535         }
1536         mkdir($_, 0777) foreach(@dirs);
1537
1538         my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
1539
1540         ##
1541         ## lockdir and piddir must be 0755
1542         ##
1543         chmod 0755, $lockdir;
1544         chmod 0755, $piddir;
1545
1546
1547         ##
1548         ## create ro and msdfs share layout
1549         ##
1550
1551         chmod 0755, $ro_shrdir;
1552         my $unreadable_file = "$ro_shrdir/unreadable_file";
1553         unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
1554                 warn("Unable to open $unreadable_file");
1555                 return undef;
1556         }
1557         close(UNREADABLE_FILE);
1558         chmod 0600, $unreadable_file;
1559
1560         my $msdfs_target = "$ro_shrdir/msdfs-target";
1561         unless (open(MSDFS_TARGET, ">$msdfs_target")) {
1562                 warn("Unable to open $msdfs_target");
1563                 return undef;
1564         }
1565         close(MSDFS_TARGET);
1566         chmod 0666, $msdfs_target;
1567         symlink "msdfs:$server_ip\\ro-tmp,$server_ipv6\\ro-tmp",
1568                 "$msdfs_shrdir/msdfs-src1";
1569         symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
1570
1571         ##
1572         ## create bad names in $badnames_shrdir
1573         ##
1574         ## (An invalid name, would be mangled to 8.3).
1575         my $badname_target = "$badnames_shrdir/\340|\231\216\377\177";
1576         unless (open(BADNAME_TARGET, ">$badname_target")) {
1577                 warn("Unable to open $badname_target");
1578                 return undef;
1579         }
1580         close(BADNAME_TARGET);
1581         chmod 0666, $badname_target;
1582
1583         ## (A bad name, would not be mangled to 8.3).
1584         my $badname_target = "$badnames_shrdir/\240\276\346\327\377\177";
1585         unless (open(BADNAME_TARGET, ">$badname_target")) {
1586                 warn("Unable to open $badname_target");
1587                 return undef;
1588         }
1589         close(BADNAME_TARGET);
1590         chmod 0666, $badname_target;
1591
1592         ## (A bad good name).
1593         my $badname_target = "$badnames_shrdir/blank.txt";
1594         unless (open(BADNAME_TARGET, ">$badname_target")) {
1595                 warn("Unable to open $badname_target");
1596                 return undef;
1597         }
1598         close(BADNAME_TARGET);
1599         chmod 0666, $badname_target;
1600
1601         ##
1602         ## create mangleable directory names in $manglenames_shrdir
1603         ##
1604         my $manglename_target = "$manglenames_shrdir/foo:bar";
1605         mkdir($manglename_target, 0777);
1606
1607         ##
1608         ## create symlinks for widelinks tests.
1609         ##
1610         my $widelinks_target = "$widelinks_linkdir/target";
1611         unless (open(WIDELINKS_TARGET, ">$widelinks_target")) {
1612                 warn("Unable to open $widelinks_target");
1613                 return undef;
1614         }
1615         close(WIDELINKS_TARGET);
1616         chmod 0666, $widelinks_target;
1617         ##
1618         ## This link should get ACCESS_DENIED
1619         ##
1620         symlink "$widelinks_target", "$widelinks_shrdir/source";
1621         ##
1622         ## This link should be allowed
1623         ##
1624         symlink "$widelinks_shrdir", "$widelinks_shrdir/dot";
1625
1626         my $conffile="$libdir/server.conf";
1627         my $dfqconffile="$libdir/dfq.conf";
1628
1629         my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/third_party/nss_wrapper/nss_wrapper.pl";
1630         my $nss_wrapper_passwd = "$privatedir/passwd";
1631         my $nss_wrapper_group = "$privatedir/group";
1632         my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
1633         my $resolv_conf = "$privatedir/resolv.conf";
1634         my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
1635
1636         my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
1637
1638         my $fake_snap_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/fake_snap.pl";
1639
1640         my @eventlog_list = ("dns server", "application");
1641
1642         ##
1643         ## calculate uids and gids
1644         ##
1645
1646         my ($max_uid, $max_gid);
1647         my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
1648         my ($uid_pdbtest_wkn);
1649         my ($uid_smbget);
1650         my ($uid_force_user);
1651         my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
1652         my ($gid_userdup, $gid_everyone);
1653         my ($gid_force_user);
1654         my ($uid_user1);
1655         my ($uid_user2);
1656
1657         if ($unix_uid < 0xffff - 10) {
1658                 $max_uid = 0xffff;
1659         } else {
1660                 $max_uid = $unix_uid;
1661         }
1662
1663         $uid_root = $max_uid - 1;
1664         $uid_nobody = $max_uid - 2;
1665         $uid_pdbtest = $max_uid - 3;
1666         $uid_pdbtest2 = $max_uid - 4;
1667         $uid_userdup = $max_uid - 5;
1668         $uid_pdbtest_wkn = $max_uid - 6;
1669         $uid_force_user = $max_uid - 7;
1670         $uid_smbget = $max_uid - 8;
1671         $uid_user1 = $max_uid - 9;
1672         $uid_user2 = $max_uid - 10;
1673
1674         if ($unix_gids[0] < 0xffff - 8) {
1675                 $max_gid = 0xffff;
1676         } else {
1677                 $max_gid = $unix_gids[0];
1678         }
1679
1680         $gid_nobody = $max_gid - 1;
1681         $gid_nogroup = $max_gid - 2;
1682         $gid_root = $max_gid - 3;
1683         $gid_domusers = $max_gid - 4;
1684         $gid_domadmins = $max_gid - 5;
1685         $gid_userdup = $max_gid - 6;
1686         $gid_everyone = $max_gid - 7;
1687         $gid_force_user = $max_gid - 8;
1688
1689         ##
1690         ## create conffile
1691         ##
1692
1693         unless (open(CONF, ">$conffile")) {
1694                 warn("Unable to open $conffile");
1695                 return undef;
1696         }
1697         print CONF "
1698 [global]
1699         netbios name = $server
1700         interfaces = $server_ip/8 $server_ipv6/64
1701         bind interfaces only = yes
1702         panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
1703         smbd:suicide mode = yes
1704
1705         workgroup = $domain
1706
1707         private dir = $privatedir
1708         binddns dir = $binddnsdir
1709         pid directory = $piddir
1710         lock directory = $lockdir
1711         log file = $logdir/log.\%m
1712         log level = 1
1713         debug pid = yes
1714         max log size = 0
1715
1716         state directory = $lockdir
1717         cache directory = $lockdir
1718
1719         passdb backend = tdbsam
1720
1721         time server = yes
1722
1723         add user script =               $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1724         add group script =              $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action add --name %g
1725         add machine script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1726         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
1727         delete user script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1728         delete group script =           $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action delete --name %g
1729         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
1730
1731         addprinter command =            $mod_printer_pl -a -s $conffile --
1732         deleteprinter command =         $mod_printer_pl -d -s $conffile --
1733
1734         eventlog list = application \"dns server\"
1735
1736         kernel oplocks = no
1737         kernel change notify = no
1738
1739         logging = file
1740         printing = bsd
1741         printcap name = /dev/null
1742
1743         winbindd socket directory = $wbsockdir
1744         nmbd:socket dir = $nmbdsockdir
1745         idmap config * : range = 100000-200000
1746         winbind enum users = yes
1747         winbind enum groups = yes
1748         winbind separator = /
1749         include system krb5 conf = no
1750
1751 #       min receivefile size = 4000
1752
1753         read only = no
1754
1755         smbd:sharedelay = 100000
1756         smbd:writetimeupdatedelay = 500000
1757         map hidden = no
1758         map system = no
1759         map readonly = no
1760         store dos attributes = yes
1761         create mask = 755
1762         dos filemode = yes
1763         strict rename = yes
1764         strict sync = yes
1765         vfs objects = acl_xattr fake_acls xattr_tdb streams_depot time_audit full_audit
1766
1767         full_audit:syslog = no
1768         full_audit:success = none
1769         full_audit:failure = none
1770
1771         printing = vlp
1772         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1773         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1774         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1775         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1776         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1777         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1778         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1779         lpq cache time = 0
1780         print notify backchannel = yes
1781
1782         ncalrpc dir = $prefix_abs/ncalrpc
1783
1784         # The samba3.blackbox.smbclient_s3 test uses this to test that
1785         # sending messages works, and that the %m sub works.
1786         message command = mv %s $shrdir/message.%m
1787
1788         # fsrvp server requires registry shares
1789         registry shares = yes
1790
1791         # Used by RPC SRVSVC tests
1792         add share command = $bindir_abs/smbaddshare
1793         change share command = $bindir_abs/smbchangeshare
1794         delete share command = $bindir_abs/smbdeleteshare
1795
1796         # fruit:copyfile is a global option
1797         fruit:copyfile = yes
1798
1799         #this does not mean that we use non-secure test env,
1800         #it just means we ALLOW one to be configured.
1801         allow insecure wide links = yes
1802
1803         # Begin extra options
1804         $extra_options
1805         # End extra options
1806
1807         #Include user defined custom parameters if set
1808 ";
1809
1810         if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1811                 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1812         }
1813
1814         print CONF "
1815 [tmp]
1816         path = $shrdir
1817         comment = smb username is [%U]
1818 [tmpsort]
1819         path = $shrdir
1820         comment = Load dirsort module
1821         vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1822 [tmpenc]
1823         path = $shrdir
1824         comment = encrypt smb username is [%U]
1825         smb encrypt = required
1826         vfs objects = dirsort
1827 [tmpguest]
1828         path = $shrdir
1829         guest ok = yes
1830 [guestonly]
1831         path = $shrdir
1832         guest only = yes
1833         guest ok = yes
1834 [forceuser]
1835         path = $shrdir
1836         force user = $unix_name
1837         guest ok = yes
1838 [forceuser_unixonly]
1839         comment = force a user with unix user SID and group SID
1840         path = $shrdir
1841         force user = pdbtest
1842         guest ok = yes
1843 [forceuser_wkngroup]
1844         comment = force a user with well-known group SID
1845         path = $shrdir
1846         force user = pdbtest_wkn
1847         guest ok = yes
1848 [forcegroup]
1849         path = $shrdir
1850         force group = nogroup
1851         guest ok = yes
1852 [ro-tmp]
1853         path = $ro_shrdir
1854         guest ok = yes
1855 [write-list-tmp]
1856         path = $shrdir
1857         read only = yes
1858         write list = $unix_name
1859 [valid-users-tmp]
1860         path = $shrdir
1861         valid users = $unix_name
1862         access based share enum = yes
1863 [msdfs-share]
1864         path = $msdfs_shrdir
1865         msdfs root = yes
1866         msdfs shuffle referrals = yes
1867         guest ok = yes
1868 [hideunread]
1869         copy = tmp
1870         hide unreadable = yes
1871 [tmpcase]
1872         copy = tmp
1873         case sensitive = yes
1874 [hideunwrite]
1875         copy = tmp
1876         hide unwriteable files = yes
1877 [durable]
1878         copy = tmp
1879         kernel share modes = no
1880         kernel oplocks = no
1881         posix locking = no
1882 [fs_specific]
1883         copy = tmp
1884         $fs_specific_conf
1885 [print1]
1886         copy = tmp
1887         printable = yes
1888
1889 [print2]
1890         copy = print1
1891 [print3]
1892         copy = print1
1893         default devmode = no
1894 [lp]
1895         copy = print1
1896
1897 [nfs4acl_simple_40]
1898         path = $shrdir
1899         comment = smb username is [%U]
1900         nfs4:mode = simple
1901         nfs4acl_xattr:version = 40
1902         vfs objects = nfs4acl_xattr xattr_tdb
1903
1904 [nfs4acl_special_40]
1905         path = $shrdir
1906         comment = smb username is [%U]
1907         nfs4:mode = special
1908         nfs4acl_xattr:version = 40
1909         vfs objects = nfs4acl_xattr xattr_tdb
1910
1911 [nfs4acl_simple_41]
1912         path = $shrdir
1913         comment = smb username is [%U]
1914         nfs4:mode = simple
1915         vfs objects = nfs4acl_xattr xattr_tdb
1916
1917 [nfs4acl_xdr_40]
1918         path = $shrdir
1919         comment = smb username is [%U]
1920         vfs objects = nfs4acl_xattr xattr_tdb
1921         nfs4:mode = simple
1922         nfs4acl_xattr:encoding = xdr
1923         nfs4acl_xattr:version = 40
1924
1925 [nfs4acl_xdr_41]
1926         path = $shrdir
1927         comment = smb username is [%U]
1928         vfs objects = nfs4acl_xattr xattr_tdb
1929         nfs4:mode = simple
1930         nfs4acl_xattr:encoding = xdr
1931         nfs4acl_xattr:version = 41
1932
1933 [xcopy_share]
1934         path = $shrdir
1935         comment = smb username is [%U]
1936         create mask = 777
1937         force create mode = 777
1938 [posix_share]
1939         path = $shrdir
1940         comment = smb username is [%U]
1941         create mask = 0777
1942         force create mode = 0
1943         directory mask = 0777
1944         force directory mode = 0
1945         vfs objects = xattr_tdb streams_depot
1946 [aio]
1947         copy = tmp
1948         aio read size = 1
1949         aio write size = 1
1950
1951 [print\$]
1952         copy = tmp
1953
1954 [vfs_fruit]
1955         path = $shrdir
1956         vfs objects = catia fruit streams_xattr acl_xattr xattr_tdb
1957         fruit:resource = file
1958         fruit:metadata = netatalk
1959         fruit:locking = netatalk
1960         fruit:encoding = native
1961         fruit:veto_appledouble = no
1962
1963 [vfs_fruit_xattr]
1964         path = $shrdir
1965         # This is used by vfs.fruit tests that require real fs xattr
1966         vfs objects = catia fruit streams_xattr acl_xattr
1967         fruit:resource = file
1968         fruit:metadata = netatalk
1969         fruit:locking = netatalk
1970         fruit:encoding = native
1971         fruit:veto_appledouble = no
1972
1973 [vfs_fruit_metadata_stream]
1974         path = $shrdir
1975         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
1976         fruit:resource = file
1977         fruit:metadata = stream
1978         fruit:veto_appledouble = no
1979
1980 [vfs_fruit_stream_depot]
1981         path = $shrdir
1982         vfs objects = fruit streams_depot acl_xattr xattr_tdb
1983         fruit:resource = stream
1984         fruit:metadata = stream
1985         fruit:veto_appledouble = no
1986
1987 [vfs_wo_fruit]
1988         path = $shrdir
1989         vfs objects = streams_xattr acl_xattr xattr_tdb
1990
1991 [vfs_wo_fruit_stream_depot]
1992         path = $shrdir
1993         vfs objects = streams_depot acl_xattr xattr_tdb
1994
1995 [vfs_fruit_timemachine]
1996         path = $shrdir
1997         vfs objects = fruit streams_xattr acl_xattr xattr_tdb
1998         fruit:resource = file
1999         fruit:metadata = stream
2000         fruit:time machine = yes
2001         fruit:time machine max size = 32K
2002
2003 [badname-tmp]
2004         path = $badnames_shrdir
2005         guest ok = yes
2006
2007 [manglenames_share]
2008         path = $manglenames_shrdir
2009         guest ok = yes
2010
2011 [dynamic_share]
2012         path = $shrdir/%R
2013         guest ok = yes
2014
2015 [widelinks_share]
2016         path = $widelinks_shrdir
2017         wide links = no
2018         guest ok = yes
2019
2020 [fsrvp_share]
2021         path = $shrdir
2022         comment = fake shapshots using rsync
2023         vfs objects = shell_snap shadow_copy2
2024         shell_snap:check path command = $fake_snap_pl --check
2025         shell_snap:create command = $fake_snap_pl --create
2026         shell_snap:delete command = $fake_snap_pl --delete
2027         # a relative path here fails, the snapshot dir is no longer found
2028         shadow:snapdir = $shrdir/.snapshots
2029
2030 [shadow1]
2031         path = $shadow_shrdir
2032         comment = previous versions snapshots under mount point
2033         vfs objects = shadow_copy2
2034         shadow:mountpoint = $shadow_mntdir
2035
2036 [shadow2]
2037         path = $shadow_shrdir
2038         comment = previous versions snapshots outside mount point
2039         vfs objects = shadow_copy2
2040         shadow:mountpoint = $shadow_mntdir
2041         shadow:snapdir = $shadow_tstdir/.snapshots
2042
2043 [shadow3]
2044         path = $shadow_shrdir
2045         comment = previous versions with subvolume snapshots, snapshots under base dir
2046         vfs objects = shadow_copy2
2047         shadow:mountpoint = $shadow_mntdir
2048         shadow:basedir = $shadow_basedir
2049         shadow:snapdir = $shadow_basedir/.snapshots
2050
2051 [shadow4]
2052         path = $shadow_shrdir
2053         comment = previous versions with subvolume snapshots, snapshots outside mount point
2054         vfs objects = shadow_copy2
2055         shadow:mountpoint = $shadow_mntdir
2056         shadow:basedir = $shadow_basedir
2057         shadow:snapdir = $shadow_tstdir/.snapshots
2058
2059 [shadow5]
2060         path = $shadow_shrdir
2061         comment = previous versions at volume root snapshots under mount point
2062         vfs objects = shadow_copy2
2063         shadow:mountpoint = $shadow_shrdir
2064
2065 [shadow6]
2066         path = $shadow_shrdir
2067         comment = previous versions at volume root snapshots outside mount point
2068         vfs objects = shadow_copy2
2069         shadow:mountpoint = $shadow_shrdir
2070         shadow:snapdir = $shadow_tstdir/.snapshots
2071
2072 [shadow7]
2073         path = $shadow_shrdir
2074         comment = previous versions snapshots everywhere
2075         vfs objects = shadow_copy2
2076         shadow:mountpoint = $shadow_mntdir
2077         shadow:snapdirseverywhere = yes
2078
2079 [shadow8]
2080         path = $shadow_shrdir
2081         comment = previous versions using snapsharepath
2082         vfs objects = shadow_copy2
2083         shadow:mountpoint = $shadow_mntdir
2084         shadow:snapdir = $shadow_tstdir/.snapshots
2085         shadow:snapsharepath = share
2086
2087 [shadow_fmt0]
2088         comment = Testing shadow:format with default option
2089         vfs object = shadow_copy2
2090         path = $shadow_shrdir
2091         read only = no
2092         guest ok = yes
2093         shadow:mountpoint = $shadow_mntdir
2094         shadow:basedir = $shadow_basedir
2095         shadow:snapdir = $shadow_basedir/.snapshots
2096         shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
2097
2098 [shadow_fmt1]
2099         comment = Testing shadow:format with only date component
2100         vfs object = shadow_copy2
2101         path = $shadow_shrdir
2102         read only = no
2103         guest ok = yes
2104         shadow:mountpoint = $shadow_mntdir
2105         shadow:basedir = $shadow_basedir
2106         shadow:snapdir = $shadow_basedir/.snapshots
2107         shadow:format = \@GMT-%Y-%m-%d
2108
2109 [shadow_fmt2]
2110         comment = Testing shadow:format with some hardcoded prefix
2111         vfs object = shadow_copy2
2112         path = $shadow_shrdir
2113         read only = no
2114         guest ok = yes
2115         shadow:mountpoint = $shadow_mntdir
2116         shadow:basedir = $shadow_basedir
2117         shadow:snapdir = $shadow_basedir/.snapshots
2118         shadow:format = snap\@GMT-%Y.%m.%d-%H.%M.%S
2119
2120 [shadow_fmt3]
2121         comment = Testing shadow:format with modified format
2122         vfs object = shadow_copy2
2123         path = $shadow_shrdir
2124         read only = no
2125         guest ok = yes
2126         shadow:mountpoint = $shadow_mntdir
2127         shadow:basedir = $shadow_basedir
2128         shadow:snapdir = $shadow_basedir/.snapshots
2129         shadow:format = \@GMT-%Y.%m.%d-%H_%M_%S-snap
2130
2131 [shadow_fmt4]
2132         comment = Testing shadow:snapprefix regex
2133         vfs object = shadow_copy2
2134         path = $shadow_shrdir
2135         read only = no
2136         guest ok = yes
2137         shadow:mountpoint = $shadow_mntdir
2138         shadow:basedir = $shadow_basedir
2139         shadow:snapdir = $shadow_basedir/.snapshots
2140         shadow:snapprefix = \^s[a-z]*p\$
2141         shadow:format = _GMT-%Y.%m.%d-%H.%M.%S
2142
2143 [shadow_fmt5]
2144         comment = Testing shadow:snapprefix with delim regex
2145         vfs object = shadow_copy2
2146         path = $shadow_shrdir
2147         read only = no
2148         guest ok = yes
2149         shadow:mountpoint = $shadow_mntdir
2150         shadow:basedir = $shadow_basedir
2151         shadow:snapdir = $shadow_basedir/.snapshots
2152         shadow:delimiter = \@GMT
2153         shadow:snapprefix = [a-z]*
2154         shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
2155
2156 [shadow_wl]
2157         path = $shadow_shrdir
2158         comment = previous versions with wide links allowed
2159         vfs objects = shadow_copy2
2160         shadow:mountpoint = $shadow_mntdir
2161         wide links = yes
2162 [dfq]
2163         path = $shrdir/dfree
2164         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2165         admin users = $unix_name
2166         include = $dfqconffile
2167 [dfq_cache]
2168         path = $shrdir/dfree
2169         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2170         admin users = $unix_name
2171         include = $dfqconffile
2172         dfree cache time = 60
2173 [dfq_owner]
2174         path = $shrdir/dfree
2175         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2176         inherit owner = yes
2177         include = $dfqconffile
2178 [quotadir]
2179         path = $shrdir/quota
2180         admin users = $unix_name
2181
2182 [acl_xattr_ign_sysacl_posix]
2183         copy = tmp
2184         acl_xattr:ignore system acls = yes
2185         acl_xattr:default acl style = posix
2186 [acl_xattr_ign_sysacl_windows]
2187         copy = tmp
2188         acl_xattr:ignore system acls = yes
2189         acl_xattr:default acl style = windows
2190
2191 [mangle_illegal]
2192         copy = tmp
2193         mangled names = illegal
2194
2195 [nosymlinks]
2196         copy = tmp
2197         path = $nosymlinks_shrdir
2198         follow symlinks = no
2199
2200 [local_symlinks]
2201         copy = tmp
2202         path = $local_symlinks_shrdir
2203         follow symlinks = yes
2204
2205 [kernel_oplocks]
2206         copy = tmp
2207         kernel oplocks = yes
2208         vfs objects = streams_xattr xattr_tdb
2209
2210 [streams_xattr]
2211         copy = tmp
2212         vfs objects = streams_xattr xattr_tdb
2213
2214 [compound_find]
2215         copy = tmp
2216         smbd:find async delay usec = 10000
2217 [error_inject]
2218         copy = tmp
2219         vfs objects = error_inject
2220         include = $libdir/error_inject.conf
2221
2222 [delay_inject]
2223         copy = tmp
2224         vfs objects = delay_inject
2225         kernel share modes = no
2226         kernel oplocks = no
2227         posix locking = no
2228         include = $libdir/delay_inject.conf
2229         ";
2230         close(CONF);
2231
2232         my $net = Samba::bindir_path($self, "net");
2233         my $cmd = "";
2234         $cmd .= "SMB_CONF_PATH=\"$conffile\" ";
2235         $cmd .= "$net setlocalsid $samsid";
2236
2237         if (system($cmd) != 0) {
2238             warn("Join failed\n$cmd");
2239             return undef;
2240         }
2241
2242         unless (open(DFQCONF, ">$dfqconffile")) {
2243                 warn("Unable to open $dfqconffile");
2244                 return undef;
2245         }
2246         close(DFQCONF);
2247
2248         ##
2249         ## create a test account
2250         ##
2251
2252         unless (open(PASSWD, ">$nss_wrapper_passwd")) {
2253            warn("Unable to open $nss_wrapper_passwd");
2254            return undef;
2255         } 
2256         print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
2257 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
2258 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
2259 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
2260 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
2261 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
2262 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
2263 smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
2264 user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
2265 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
2266 ";
2267         if ($unix_uid != 0) {
2268                 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
2269 ";
2270         }
2271         close(PASSWD);
2272
2273         unless (open(GROUP, ">$nss_wrapper_group")) {
2274              warn("Unable to open $nss_wrapper_group");
2275              return undef;
2276         }
2277         print GROUP "nobody:x:$gid_nobody:
2278 nogroup:x:$gid_nogroup:nobody
2279 $unix_name-group:x:$unix_gids[0]:
2280 domusers:X:$gid_domusers:
2281 domadmins:X:$gid_domadmins:
2282 userdup:x:$gid_userdup:$unix_name
2283 everyone:x:$gid_everyone:
2284 force_user:x:$gid_force_user:
2285 ";
2286         if ($unix_gids[0] != 0) {
2287                 print GROUP "root:x:$gid_root:
2288 ";
2289         }
2290
2291         close(GROUP);
2292
2293         ## hosts
2294         my $hostname = lc($server);
2295         unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
2296                 warn("Unable to open $nss_wrapper_hosts");
2297                 return undef;
2298         }
2299         print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n";
2300         print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n";
2301         close(HOSTS);
2302
2303         ## hosts
2304         unless (open(RESOLV_CONF, ">$resolv_conf")) {
2305                 warn("Unable to open $resolv_conf");
2306                 return undef;
2307         }
2308         if (defined($dc_server_ip) or defined($dc_server_ipv6)) {
2309                 if (defined($dc_server_ip)) {
2310                         print RESOLV_CONF "nameserver $dc_server_ip\n";
2311                 }
2312                 if (defined($dc_server_ipv6)) {
2313                         print RESOLV_CONF "nameserver $dc_server_ipv6\n";
2314                 }
2315         } else {
2316                 print RESOLV_CONF "nameserver ${server_ip}\n";
2317                 print RESOLV_CONF "nameserver ${server_ipv6}\n";
2318         }
2319         close(RESOLV_CONF);
2320
2321         foreach my $evlog (@eventlog_list) {
2322                 my $evlogtdb = "$eventlogdir/$evlog.tdb";
2323                 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
2324                 close(EVENTLOG);
2325         }
2326
2327         $createuser_env{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
2328         $createuser_env{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
2329         $createuser_env{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
2330         $createuser_env{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
2331         if ($ENV{SAMBA_DNS_FAKING}) {
2332                 $createuser_env{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
2333         } else {
2334                 $createuser_env{RESOLV_WRAPPER_CONF} = $resolv_conf;
2335         }
2336
2337         createuser($self, $unix_name, $password, $conffile, \%createuser_env) || die("Unable to create user");
2338         createuser($self, "force_user", $password, $conffile, \%createuser_env) || die("Unable to create force_user");
2339         createuser($self, "smbget_user", $password, $conffile, \%createuser_env) || die("Unable to create smbget_user");
2340         createuser($self, "user1", $password, $conffile, \%createuser_env) || die("Unable to create user1");
2341         createuser($self, "user2", $password, $conffile, \%createuser_env) || die("Unable to create user2");
2342
2343         open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
2344         print DNS_UPDATE_LIST "A $server. $server_ip\n";
2345         print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
2346         close(DNS_UPDATE_LIST);
2347
2348         print "DONE\n";
2349
2350         $ret{SERVER_IP} = $server_ip;
2351         $ret{SERVER_IPV6} = $server_ipv6;
2352         $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
2353         $ret{NMBD_TEST_LOG_POS} = 0;
2354         $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
2355         $ret{WINBINDD_TEST_LOG_POS} = 0;
2356         $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
2357         $ret{SMBD_TEST_LOG_POS} = 0;
2358         $ret{SERVERCONFFILE} = $conffile;
2359         $ret{CONFIGURATION} ="-s $conffile";
2360         $ret{LOCK_DIR} = $lockdir;
2361         $ret{SERVER} = $server;
2362         $ret{USERNAME} = $unix_name;
2363         $ret{USERID} = $unix_uid;
2364         $ret{DOMAIN} = $domain;
2365         $ret{SAMSID} = $samsid;
2366         $ret{NETBIOSNAME} = $server;
2367         $ret{PASSWORD} = $password;
2368         $ret{PIDDIR} = $piddir;
2369         $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
2370         $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
2371         $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
2372         $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
2373         $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
2374         $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
2375         $ret{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
2376         $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
2377         $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
2378         if ($ENV{SAMBA_DNS_FAKING}) {
2379                 $ret{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
2380         } else {
2381                 $ret{RESOLV_WRAPPER_CONF} = $resolv_conf;
2382         }
2383         $ret{LOCAL_PATH} = "$shrdir";
2384         $ret{LOGDIR} = $logdir;
2385
2386         #
2387         # Avoid hitting system krb5.conf -
2388         # An env that needs Kerberos will reset this to the real
2389         # value.
2390         #
2391         $ret{KRB5_CONFIG} = abs_path($prefix) . "/no_krb5.conf";
2392
2393         # Define KRB5CCNAME for each environment we set up
2394         $ret{KRB5_CCACHE} = abs_path($prefix) . "/krb5ccache";
2395         $ENV{KRB5CCNAME} = $ret{KRB5_CCACHE};
2396
2397         return \%ret;
2398 }
2399
2400 sub wait_for_start($$$$$)
2401 {
2402         my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
2403         my $cmd;
2404         my $netcmd;
2405         my $ret;
2406
2407         if ($nmbd eq "yes") {
2408                 my $count = 0;
2409
2410                 # give time for nbt server to register its names
2411                 print "checking for nmbd\n";
2412
2413                 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
2414                 my $nmblookup = Samba::bindir_path($self, "nmblookup");
2415
2416                 do {
2417                         $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
2418                         if ($ret != 0) {
2419                                 sleep(1);
2420                         } else {
2421                                 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
2422                                 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
2423                                 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
2424                                 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
2425                         }
2426                         $count++;
2427                 } while ($ret != 0 && $count < 10);
2428                 if ($count == 10) {
2429                         print "NMBD not reachable after 10 retries\n";
2430                         teardown_env($self, $envvars);
2431                         return 0;
2432                 }
2433         }
2434
2435         if ($winbindd eq "yes") {
2436             print "checking for winbindd\n";
2437             my $count = 0;
2438             $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
2439             $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
2440             $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
2441             $cmd .= Samba::bindir_path($self, "wbinfo") . " --ping-dc";
2442
2443             do {
2444                 if ($ret != 0) {
2445                     $ret = system($cmd);
2446                     sleep(1);
2447                 }
2448                 $count++;
2449             } while ($ret != 0 && $count < 20);
2450             if ($count == 20) {
2451                 print "WINBINDD not reachable after 20 seconds\n";
2452                 teardown_env($self, $envvars);
2453                 return 0;
2454             }
2455         }
2456
2457         if ($smbd eq "yes") {
2458             # make sure smbd is also up set
2459             print "wait for smbd\n";
2460
2461             my $count = 0;
2462             do {
2463                 $ret = system(Samba::bindir_path($self, "smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
2464                 if ($ret != 0) {
2465                     sleep(1);
2466                 }
2467                 $count++
2468             } while ($ret != 0 && $count < 20);
2469             if ($count == 20) {
2470                 print "SMBD failed to start up in a reasonable time (20sec)\n";
2471                 teardown_env($self, $envvars);
2472                 return 0;
2473             }
2474         }
2475
2476         # Ensure we have domain users mapped.
2477         $netcmd = "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
2478         $netcmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
2479         $netcmd .= Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} ";
2480
2481         $cmd = $netcmd . "groupmap delete ntgroup=domusers";
2482         $ret = system($cmd);
2483
2484         $cmd = $netcmd . "groupmap add rid=513 unixgroup=domusers type=domain";
2485         $ret = system($cmd);
2486         if ($ret != 0) {
2487                 print("\"$cmd\" failed\n");
2488                 return 1;
2489         }
2490
2491         $cmd = $netcmd . "groupmap delete ntgroup=domadmins";
2492         $ret = system($cmd);
2493
2494         $cmd = $netcmd . "groupmap add rid=512 unixgroup=domadmins type=domain";
2495         $ret = system($cmd);
2496         if ($ret != 0) {
2497                 print("\"$cmd\" failed\n");
2498                 return 1;
2499         }
2500
2501         $cmd = $netcmd . "groupmap delete ntgroup=everyone";
2502         $ret = system($cmd);
2503
2504         $cmd = $netcmd . "groupmap add sid=S-1-1-0 unixgroup=everyone type=builtin";
2505         $ret = system($cmd);
2506         if ($ret != 0) {
2507                 print("\"$cmd\" failed\n");
2508                 return 1;
2509         }
2510
2511         # note: creating builtin groups requires winbindd for the
2512         # unix id allocator
2513         my $create_builtin_users = "no";
2514         if ($winbindd eq "yes") {
2515                 $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
2516                 $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
2517                 $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
2518                 $cmd .= Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545";
2519                 my $wbinfo_out = qx($cmd 2>&1);
2520                 if ($? != 0) {
2521                         # wbinfo doesn't give us a better error code then
2522                         # WBC_ERR_DOMAIN_NOT_FOUND, but at least that's
2523                         # different then WBC_ERR_WINBIND_NOT_AVAILABLE
2524                         if ($wbinfo_out !~ /WBC_ERR_DOMAIN_NOT_FOUND/) {
2525                                 print("Failed to run \"wbinfo --sid-to-gid=S-1-5-32-545\": $wbinfo_out");
2526                                 teardown_env($self, $envvars);
2527                                 return 0;
2528                         }
2529                         $create_builtin_users = "yes";
2530                 }
2531         }
2532         if ($create_builtin_users eq "yes") {
2533             $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
2534             $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
2535             $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
2536             $cmd .= Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} ";
2537             $cmd .= "sam createbuiltingroup Users";
2538             $ret = system($cmd);
2539             if ($ret != 0) {
2540                 print "Failed to create BUILTIN\\Users group\n";
2541                 teardown_env($self, $envvars);
2542                 return 0;
2543             }
2544
2545             $cmd = Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} ";
2546             $cmd .= "cache del IDMAP/SID2XID/S-1-5-32-545";
2547             system($cmd);
2548
2549             $cmd = "SELFTEST_WINBINDD_SOCKET_DIR='$envvars->{SELFTEST_WINBINDD_SOCKET_DIR}' ";
2550             $cmd .= "NSS_WRAPPER_PASSWD='$envvars->{NSS_WRAPPER_PASSWD}' ";
2551             $cmd .= "NSS_WRAPPER_GROUP='$envvars->{NSS_WRAPPER_GROUP}' ";
2552             $cmd .= Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545";
2553             $ret = system($cmd);
2554             if ($ret != 0) {
2555                 print "Missing \"BUILTIN\\Users\", did net sam createbuiltingroup Users fail?\n";
2556                 teardown_env($self, $envvars);
2557                 return 0;
2558             }
2559         }
2560
2561         print $self->getlog_env($envvars);
2562
2563         return 1;
2564 }
2565
2566 1;