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