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