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