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