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