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