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