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