selftest: Remove unsued variables WINBINDD_PRIV_PIPE_DIR and wbsockprivdir
[kai/samba-autobuild/.git] / selftest / target / Samba3.pm
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
5
6 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 .= "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,
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,
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,
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_SAMBADOMAIN";
389         push(@dirs, $substitution_path);
390
391         $substitution_path = "$share_dir/D_SAMBADOMAIN/U_alice";
392         push(@dirs, $substitution_path);
393
394         $substitution_path = "$share_dir/D_SAMBADOMAIN/U_alice/G_domain users";
395         push(@dirs, $substitution_path);
396
397         my $member_options = "
398         security = ads
399         workgroup = $dcvars->{DOMAIN}
400         realm = $dcvars->{REALM}
401         netbios aliases = foo bar
402
403 [subDUG]
404         path = $share_dir/D_%D/U_%U/G_%G
405         writeable = yes
406
407 ";
408
409         my $ret = $self->provision($prefix,
410                                    "LOCALADMEMBER",
411                                    "loCalMemberPass",
412                                    $member_options,
413                                    $dcvars->{SERVER_IP},
414                                    $dcvars->{SERVER_IPV6});
415
416         $ret or return undef;
417
418         mkdir($_, 0777) foreach(@dirs);
419
420         close(USERMAP);
421         $ret->{DOMAIN} = $dcvars->{DOMAIN};
422         $ret->{REALM} = $dcvars->{REALM};
423
424         my $ctx;
425         $ctx = {};
426         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
427         $ctx->{domain} = $dcvars->{DOMAIN};
428         $ctx->{realm} = $dcvars->{REALM};
429         $ctx->{dnsname} = lc($dcvars->{REALM});
430         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
431         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
432         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
433         Samba::mk_krb5_conf($ctx, "");
434
435         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
436
437         my $net = Samba::bindir_path($self, "net");
438         my $cmd = "";
439         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
440         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
441                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
442         } else {
443                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
444         }
445         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
446         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
447         $cmd .= "$net join $ret->{CONFIGURATION}";
448         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
449
450         if (system($cmd) != 0) {
451             warn("Join failed\n$cmd");
452             return undef;
453         }
454
455         # We need world access to this share, as otherwise the domain
456         # administrator from the AD domain provided by Samba4 can't
457         # access the share for tests.
458         chmod 0777, "$prefix/share";
459
460         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
461                 return undef;
462         }
463
464         $ret->{DC_SERVER} = $dcvars->{SERVER};
465         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
466         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
467         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
468         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
469         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
470
471         # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
472         $ret->{target} = $self;
473
474         return $ret;
475 }
476
477 sub setup_admember_rfc2307($$$$)
478 {
479         my ($self, $prefix, $dcvars) = @_;
480
481         # If we didn't build with ADS, pretend this env was never available
482         if (not $self->have_ads()) {
483                 return "UNKNOWN";
484         }
485
486         print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
487
488         my $member_options = "
489         security = ads
490         workgroup = $dcvars->{DOMAIN}
491         realm = $dcvars->{REALM}
492         idmap config * : backend = autorid
493         idmap config * : range = 1000000-1999999
494         idmap config * : rangesize = 100000
495         idmap config $dcvars->{DOMAIN} : backend = rfc2307
496         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
497         idmap config $dcvars->{DOMAIN} : ldap_server = ad
498         idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
499         idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
500 ";
501
502         my $ret = $self->provision($prefix,
503                                    "RFC2307MEMBER",
504                                    "loCalMemberPass",
505                                    $member_options,
506                                    $dcvars->{SERVER_IP},
507                                    $dcvars->{SERVER_IPV6});
508
509         $ret or return undef;
510
511         close(USERMAP);
512         $ret->{DOMAIN} = $dcvars->{DOMAIN};
513         $ret->{REALM} = $dcvars->{REALM};
514
515         my $ctx;
516         my $prefix_abs = abs_path($prefix);
517         $ctx = {};
518         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
519         $ctx->{domain} = $dcvars->{DOMAIN};
520         $ctx->{realm} = $dcvars->{REALM};
521         $ctx->{dnsname} = lc($dcvars->{REALM});
522         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
523         $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
524         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
525         Samba::mk_krb5_conf($ctx, "");
526
527         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
528
529         my $net = Samba::bindir_path($self, "net");
530         my $cmd = "";
531         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
532         if (defined($ret->{RESOLV_WRAPPER_CONF})) {
533                 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
534         } else {
535                 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
536         }
537         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
538         $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
539         $cmd .= "$net join $ret->{CONFIGURATION}";
540         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
541
542         if (system($cmd) != 0) {
543             warn("Join failed\n$cmd");
544             return undef;
545         }
546
547         # We need world access to this share, as otherwise the domain
548         # administrator from the AD domain provided by Samba4 can't
549         # access the share for tests.
550         chmod 0777, "$prefix/share";
551
552         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
553                 return undef;
554         }
555
556         $ret->{DC_SERVER} = $dcvars->{SERVER};
557         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
558         $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
559         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
560         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
561         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
562
563         # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
564         $ret->{target} = $self;
565
566         return $ret;
567 }
568
569 sub setup_simpleserver($$)
570 {
571         my ($self, $path) = @_;
572
573         print "PROVISIONING simple server...";
574
575         my $prefix_abs = abs_path($path);
576
577         my $simpleserver_options = "
578         lanman auth = yes
579         ntlm auth = yes
580         vfs objects = xattr_tdb streams_depot time_audit full_audit
581         change notify = no
582
583         full_audit:syslog = no
584         full_audit:success = none
585         full_audit:failure = none
586
587 [vfs_aio_fork]
588         path = $prefix_abs/share
589         vfs objects = aio_fork
590         read only = no
591         vfs_aio_fork:erratic_testing_mode=yes
592
593 [dosmode]
594         path = $prefix_abs/share
595         vfs objects =
596         store dos attributes = yes
597         hide files = /hidefile/
598         hide dot files = yes
599 ";
600
601         my $vars = $self->provision($path,
602                                     "LOCALSHARE4",
603                                     "local4pass",
604                                     $simpleserver_options);
605
606         $vars or return undef;
607
608         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
609                return undef;
610         }
611
612         $self->{vars}->{simpleserver} = $vars;
613
614         return $vars;
615 }
616
617 sub setup_fileserver($$)
618 {
619         my ($self, $path) = @_;
620         my $prefix_abs = abs_path($path);
621         my $srcdir_abs = abs_path($self->{srcdir});
622
623         print "PROVISIONING file server ...\n";
624
625         my @dirs = ();
626
627         mkdir($prefix_abs, 0777);
628
629         my $share_dir="$prefix_abs/share";
630
631         # Create share directory structure
632         my $lower_case_share_dir="$share_dir/lower-case";
633         push(@dirs, $lower_case_share_dir);
634
635         my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
636         push(@dirs, $lower_case_share_dir_30000);
637
638         my $dfree_share_dir="$share_dir/dfree";
639         push(@dirs, $dfree_share_dir);
640         push(@dirs, "$dfree_share_dir/subdir1");
641         push(@dirs, "$dfree_share_dir/subdir2");
642         push(@dirs, "$dfree_share_dir/subdir3");
643
644         my $valid_users_sharedir="$share_dir/valid_users";
645         push(@dirs,$valid_users_sharedir);
646
647         my $offline_sharedir="$share_dir/offline";
648         push(@dirs,$offline_sharedir);
649
650         my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
651         push(@dirs, $force_user_valid_users_dir);
652
653         my $smbget_sharedir="$share_dir/smbget";
654         push(@dirs,$smbget_sharedir);
655
656         my $fileserver_options = "
657 [lowercase]
658         path = $lower_case_share_dir
659         comment = smb username is [%U]
660         case sensitive = True
661         default case = lower
662         preserve case = no
663         short preserve case = no
664 [lowercase-30000]
665         path = $lower_case_share_dir_30000
666         comment = smb username is [%U]
667         case sensitive = True
668         default case = lower
669         preserve case = no
670         short preserve case = no
671 [dfree]
672         path = $dfree_share_dir
673         comment = smb username is [%U]
674         dfree command = $srcdir_abs/testprogs/blackbox/dfree.sh
675 [valid-users-access]
676         path = $valid_users_sharedir
677         valid users = +userdup
678 [offline]
679         path = $offline_sharedir
680         vfs objects = offline
681
682 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
683 # RH BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
684 [force_user_valid_users]
685         path = $force_user_valid_users_dir
686         comment = force user with valid users combination test share
687         valid users = +force_user
688         force user = force_user
689         force group = everyone
690         write list = force_user
691
692 [smbget]
693         path = $smbget_sharedir
694         comment = smb username is [%U]
695         guest ok = yes
696 [ign_sysacls]
697         path = $share_dir
698         comment = ignore system acls
699         acl_xattr:ignore system acls = yes
700 [inherit_owner]
701         path = $share_dir
702         comment = inherit owner
703         inherit owner = yes
704 [inherit_owner_u]
705         path = $share_dir
706         comment = inherit only unix owner
707         inherit owner = unix only
708         acl_xattr:ignore system acls = yes
709 ";
710
711         my $vars = $self->provision($path,
712                                     "FILESERVER",
713                                     "fileserver",
714                                     $fileserver_options,
715                                     undef,
716                                     undef,
717                                     1);
718
719         $vars or return undef;
720
721         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
722                return undef;
723         }
724
725         $self->{vars}->{fileserver} = $vars;
726
727         mkdir($_, 0777) foreach(@dirs);
728
729         ## Create case sensitive lower case share dir
730         foreach my $file ('a'..'z') {
731                 my $full_path = $lower_case_share_dir . '/' . $file;
732                 open my $fh, '>', $full_path;
733                 # Add some content to file
734                 print $fh $full_path;
735                 close $fh;
736         }
737
738         for (my $file = 1; $file < 51; ++$file) {
739                 my $full_path = $lower_case_share_dir . '/' . $file;
740                 open my $fh, '>', $full_path;
741                 # Add some content to file
742                 print $fh $full_path;
743                 close $fh;
744         }
745
746         # Create content for 30000 share
747         foreach my $file ('a'..'z') {
748                 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
749                 open my $fh, '>', $full_path;
750                 # Add some content to file
751                 print $fh $full_path;
752                 close $fh;
753         }
754
755         for (my $file = 1; $file < 30001; ++$file) {
756                 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
757                 open my $fh, '>', $full_path;
758                 # Add some content to file
759                 print $fh $full_path;
760                 close $fh;
761         }
762
763         ##
764         ## create a listable file in valid_users_share
765         ##
766         my $valid_users_target = "$valid_users_sharedir/foo";
767         unless (open(VALID_USERS_TARGET, ">$valid_users_target")) {
768                 warn("Unable to open $valid_users_target");
769                 return undef;
770         }
771         close(VALID_USERS_TARGET);
772         chmod 0644, $valid_users_target;
773
774         return $vars;
775 }
776
777 sub setup_ktest($$$)
778 {
779         my ($self, $prefix) = @_;
780
781         # If we didn't build with ADS, pretend this env was never available
782         if (not $self->have_ads()) {
783                 return "UNKNOWN";
784         }
785
786         print "PROVISIONING server with security=ads...";
787
788         my $ktest_options = "
789         workgroup = KTEST
790         realm = ktest.samba.example.com
791         security = ads
792         username map = $prefix/lib/username.map
793         server signing = required
794 ";
795
796         my $ret = $self->provision($prefix,
797                                    "LOCALKTEST6",
798                                    "localktest6pass",
799                                    $ktest_options);
800
801         $ret or return undef;
802
803         my $ctx;
804         my $prefix_abs = abs_path($prefix);
805         $ctx = {};
806         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
807         $ctx->{domain} = "KTEST";
808         $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
809         $ctx->{dnsname} = lc($ctx->{realm});
810         $ctx->{kdc_ipv4} = "0.0.0.0";
811         $ctx->{kdc_ipv6} = "::";
812         $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
813         Samba::mk_krb5_conf($ctx, "");
814
815         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
816
817         open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
818         print USERMAP "
819 $ret->{USERNAME} = KTEST\\Administrator
820 ";
821         close(USERMAP);
822
823 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
824 #Samba4 DC with the same parameters as are being used here.  The
825 #domain SID is S-1-5-21-1071277805-689288055-3486227160
826
827         system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
828         chmod 0600, "$prefix/private/secrets.tdb";
829
830 #Make sure there's no old ntdb file.
831         system("rm -f $prefix/private/secrets.ntdb");
832
833 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
834 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
835 #
836 #and having in krb5.conf:
837 # ticket_lifetime = 799718400
838 # renew_lifetime = 799718400
839 #
840 # The commands for the -2 keytab where were:
841 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
842 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
843 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
844 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
845 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
846 #
847 # and then for the -3 keytab, I did
848 #
849 # net changetrustpw; kdestroy and the same again.
850 #
851 # This creates a credential cache with a very long lifetime (2036 at
852 # at 2011-04), and shows that running 'net changetrustpw' does not
853 # break existing logins (for the secrets.tdb method at least).
854 #
855
856         $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
857
858         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
859         chmod 0600, "$prefix/krb5_ccache-2";
860
861         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
862         chmod 0600, "$prefix/krb5_ccache-3";
863
864         # We need world access to this share, as otherwise the domain
865         # administrator from the AD domain provided by ktest can't
866         # access the share for tests.
867         chmod 0777, "$prefix/share";
868
869         if (not $self->check_or_start($ret, "yes", "no", "yes")) {
870                return undef;
871         }
872         return $ret;
873 }
874
875 sub setup_maptoguest($$)
876 {
877         my ($self, $path) = @_;
878
879         print "PROVISIONING maptoguest...";
880
881         my $options = "
882 map to guest = bad user
883 ntlm auth = yes
884 ";
885
886         my $vars = $self->provision($path,
887                                     "maptoguest",
888                                     "maptoguestpass",
889                                     $options);
890
891         $vars or return undef;
892
893         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
894                return undef;
895         }
896
897         $self->{vars}->{s3maptoguest} = $vars;
898
899         return $vars;
900 }
901
902 sub stop_sig_term($$) {
903         my ($self, $pid) = @_;
904         kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
905 }
906
907 sub stop_sig_kill($$) {
908         my ($self, $pid) = @_;
909         kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
910 }
911
912 sub write_pid($$$)
913 {
914         my ($env_vars, $app, $pid) = @_;
915
916         open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
917         print PID $pid;
918         close(PID);
919 }
920
921 sub read_pid($$)
922 {
923         my ($env_vars, $app) = @_;
924
925         open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
926         my $pid = <PID>;
927         close(PID);
928         return $pid;
929 }
930
931 sub check_or_start($$$$$) {
932         my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
933
934         # use a pipe for stdin in the child processes. This allows
935         # those processes to monitor the pipe for EOF to ensure they
936         # exit when the test script exits
937         pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
938
939         unlink($env_vars->{NMBD_TEST_LOG});
940         print "STARTING NMBD...";
941         my $pid = fork();
942         if ($pid == 0) {
943                 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
944                 open STDERR, '>&STDOUT';
945
946                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
947
948                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
949                 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.nmbd";
950                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
951                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
952
953                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
954                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
955                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
956                 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
957                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
958                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
959                 $ENV{UID_WRAPPER_ROOT} = "1";
960
961                 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
962
963                 if ($nmbd ne "yes") {
964                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
965                                 my $signame = shift;
966                                 print("Skip nmbd received signal $signame");
967                                 exit 0;
968                         };
969                         sleep($self->{server_maxtime});
970                         exit 0;
971                 }
972
973                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
974                 my @optargs = ("-d0");
975                 if (defined($ENV{NMBD_OPTIONS})) {
976                         @optargs = split(/ /, $ENV{NMBD_OPTIONS});
977                 }
978                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
979                 if(defined($ENV{NMBD_VALGRIND})) { 
980                         @preargs = split(/ /, $ENV{NMBD_VALGRIND});
981                 }
982                 my @args = ("-F", "--no-process-group",
983                             "-s", $env_vars->{SERVERCONFFILE},
984                             "-l", $env_vars->{LOGDIR});
985                 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
986                         push(@args, "--log-stdout");
987                 }
988
989                 close($env_vars->{STDIN_PIPE});
990                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
991
992                 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
993                         or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
994         }
995         $env_vars->{NMBD_TL_PID} = $pid;
996         write_pid($env_vars, "nmbd", $pid);
997         print "DONE\n";
998
999         unlink($env_vars->{WINBINDD_TEST_LOG});
1000         print "STARTING WINBINDD...";
1001         $pid = fork();
1002         if ($pid == 0) {
1003                 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
1004                 open STDERR, '>&STDOUT';
1005
1006                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1007
1008                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1009                 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.winbindd";
1010                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1011                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1012
1013                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1014                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1015                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1016                 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1017                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1018                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1019                 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1020                         $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1021                 } else {
1022                         $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1023                 }
1024                 $ENV{UID_WRAPPER_ROOT} = "1";
1025
1026                 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
1027
1028                 if ($winbindd ne "yes") {
1029                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1030                                 my $signame = shift;
1031                                 print("Skip winbindd received signal $signame");
1032                                 exit 0;
1033                         };
1034                         sleep($self->{server_maxtime});
1035                         exit 0;
1036                 }
1037
1038                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
1039                 my @optargs = ("-d0");
1040                 if (defined($ENV{WINBINDD_OPTIONS})) {
1041                         @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
1042                 }
1043                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1044                 if(defined($ENV{WINBINDD_VALGRIND})) {
1045                         @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
1046                 }
1047                 my @args = ("-F", "--no-process-group",
1048                             "-s", $env_vars->{SERVERCONFFILE},
1049                             "-l", $env_vars->{LOGDIR});
1050                 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
1051                         push(@args, "--stdout");
1052                 }
1053
1054                 close($env_vars->{STDIN_PIPE});
1055                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1056
1057                 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1058                         or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1059         }
1060         $env_vars->{WINBINDD_TL_PID} = $pid;
1061         write_pid($env_vars, "winbindd", $pid);
1062         print "DONE\n";
1063
1064         unlink($env_vars->{SMBD_TEST_LOG});
1065         print "STARTING SMBD...";
1066         $pid = fork();
1067         if ($pid == 0) {
1068                 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
1069                 open STDERR, '>&STDOUT';
1070
1071                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1072
1073                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1074                 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.smbd";
1075                 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1076                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1077
1078                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1079                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1080                 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1081                 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1082                 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1083                 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1084                 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1085                         $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1086                 } else {
1087                         $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1088                 }
1089                 $ENV{UID_WRAPPER_ROOT} = "1";
1090
1091                 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
1092
1093                 if ($smbd ne "yes") {
1094                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1095                                 my $signame = shift;
1096                                 print("Skip smbd received signal $signame");
1097                                 exit 0;
1098                         };
1099                         sleep($self->{server_maxtime});
1100                         exit 0;
1101                 }
1102
1103                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
1104                 my @optargs = ("-d0");
1105                 if (defined($ENV{SMBD_OPTIONS})) {
1106                         @optargs = split(/ /, $ENV{SMBD_OPTIONS});
1107                 }
1108                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1109                 if(defined($ENV{SMBD_VALGRIND})) {
1110                         @preargs = split(/ /,$ENV{SMBD_VALGRIND});
1111                 }
1112                 my @args = ("-F", "--no-process-group",
1113                             "-s", $env_vars->{SERVERCONFFILE},
1114                             "-l", $env_vars->{LOGDIR});
1115                 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
1116                         push(@args, "--log-stdout");
1117                 }
1118
1119                 close($env_vars->{STDIN_PIPE});
1120                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1121
1122                 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1123                         or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1124         }
1125         $env_vars->{SMBD_TL_PID} = $pid;
1126         write_pid($env_vars, "smbd", $pid);
1127         print "DONE\n";
1128
1129         close(STDIN_READER);
1130
1131         return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
1132 }
1133
1134 sub createuser($$$$)
1135 {
1136         my ($self, $username, $password, $conffile) = @_;
1137         my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $username > /dev/null";
1138         unless (open(PWD, "|$cmd")) {
1139             warn("Unable to set password for $username account\n$cmd");
1140             return undef;
1141         }
1142         print PWD "$password\n$password\n";
1143         unless (close(PWD)) {
1144             warn("Unable to set password for $username account\n$cmd");
1145             return undef;
1146         }
1147 }
1148
1149 sub provision($$$$$$$$)
1150 {
1151         my ($self, $prefix, $server, $password, $extra_options, $dc_server_ip, $dc_server_ipv6, $no_delete_prefix) = @_;
1152
1153         ##
1154         ## setup the various environment variables we need
1155         ##
1156
1157         my $swiface = Samba::get_interface($server);
1158         my %ret = ();
1159         my $server_ip = "127.0.0.$swiface";
1160         my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
1161         my $domain = "SAMBA-TEST";
1162
1163         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
1164         chomp $unix_name;
1165         my $unix_uid = $>;
1166         my $unix_gids_str = $);
1167         my @unix_gids = split(" ", $unix_gids_str);
1168
1169         my $prefix_abs = abs_path($prefix);
1170         my $bindir_abs = abs_path($self->{bindir});
1171
1172         my @dirs = ();
1173
1174         my $shrdir="$prefix_abs/share";
1175         push(@dirs,$shrdir);
1176
1177         my $libdir="$prefix_abs/lib";
1178         push(@dirs,$libdir);
1179
1180         my $piddir="$prefix_abs/pid";
1181         push(@dirs,$piddir);
1182
1183         my $privatedir="$prefix_abs/private";
1184         push(@dirs,$privatedir);
1185
1186         my $lockdir="$prefix_abs/lockdir";
1187         push(@dirs,$lockdir);
1188
1189         my $eventlogdir="$prefix_abs/lockdir/eventlog";
1190         push(@dirs,$eventlogdir);
1191
1192         my $logdir="$prefix_abs/logs";
1193         push(@dirs,$logdir);
1194
1195         my $driver32dir="$shrdir/W32X86";
1196         push(@dirs,$driver32dir);
1197
1198         my $driver64dir="$shrdir/x64";
1199         push(@dirs,$driver64dir);
1200
1201         my $driver40dir="$shrdir/WIN40";
1202         push(@dirs,$driver40dir);
1203
1204         my $ro_shrdir="$shrdir/root-tmp";
1205         push(@dirs,$ro_shrdir);
1206
1207         my $msdfs_shrdir="$shrdir/msdfsshare";
1208         push(@dirs,$msdfs_shrdir);
1209
1210         my $msdfs_deeppath="$msdfs_shrdir/deeppath";
1211         push(@dirs,$msdfs_deeppath);
1212
1213         my $badnames_shrdir="$shrdir/badnames";
1214         push(@dirs,$badnames_shrdir);
1215
1216         my $lease1_shrdir="$shrdir/SMB2_10";
1217         push(@dirs,$lease1_shrdir);
1218
1219         my $lease2_shrdir="$shrdir/SMB3_00";
1220         push(@dirs,$lease2_shrdir);
1221
1222         my $manglenames_shrdir="$shrdir/manglenames";
1223         push(@dirs,$manglenames_shrdir);
1224
1225         my $widelinks_shrdir="$shrdir/widelinks";
1226         push(@dirs,$widelinks_shrdir);
1227
1228         my $widelinks_linkdir="$shrdir/widelinks_foo";
1229         push(@dirs,$widelinks_linkdir);
1230
1231         my $shadow_tstdir="$shrdir/shadow";
1232         push(@dirs,$shadow_tstdir);
1233         my $shadow_mntdir="$shadow_tstdir/mount";
1234         push(@dirs,$shadow_mntdir);
1235         my $shadow_basedir="$shadow_mntdir/base";
1236         push(@dirs,$shadow_basedir);
1237         my $shadow_shrdir="$shadow_basedir/share";
1238         push(@dirs,$shadow_shrdir);
1239
1240         # this gets autocreated by winbindd
1241         my $wbsockdir="$prefix_abs/winbindd";
1242
1243         my $nmbdsockdir="$prefix_abs/nmbd";
1244         unlink($nmbdsockdir);
1245
1246         ## 
1247         ## create the test directory layout
1248         ##
1249         die ("prefix_abs = ''") if $prefix_abs eq "";
1250         die ("prefix_abs = '/'") if $prefix_abs eq "/";
1251
1252         mkdir($prefix_abs, 0777);
1253         print "CREATE TEST ENVIRONMENT IN '$prefix'...";
1254         if (not defined($no_delete_prefix) or not $no_delete_prefix) {
1255             system("rm -rf $prefix_abs/*");
1256         }
1257         mkdir($_, 0777) foreach(@dirs);
1258
1259         my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
1260
1261         ##
1262         ## lockdir and piddir must be 0755
1263         ##
1264         chmod 0755, $lockdir;
1265         chmod 0755, $piddir;
1266
1267
1268         ##
1269         ## create ro and msdfs share layout
1270         ##
1271
1272         chmod 0755, $ro_shrdir;
1273         my $unreadable_file = "$ro_shrdir/unreadable_file";
1274         unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
1275                 warn("Unable to open $unreadable_file");
1276                 return undef;
1277         }
1278         close(UNREADABLE_FILE);
1279         chmod 0600, $unreadable_file;
1280
1281         my $msdfs_target = "$ro_shrdir/msdfs-target";
1282         unless (open(MSDFS_TARGET, ">$msdfs_target")) {
1283                 warn("Unable to open $msdfs_target");
1284                 return undef;
1285         }
1286         close(MSDFS_TARGET);
1287         chmod 0666, $msdfs_target;
1288         symlink "msdfs:$server_ip\\ro-tmp,$server_ipv6\\ro-tmp",
1289                 "$msdfs_shrdir/msdfs-src1";
1290         symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
1291
1292         ##
1293         ## create bad names in $badnames_shrdir
1294         ##
1295         ## (An invalid name, would be mangled to 8.3).
1296         my $badname_target = "$badnames_shrdir/\340|\231\216\377\177";
1297         unless (open(BADNAME_TARGET, ">$badname_target")) {
1298                 warn("Unable to open $badname_target");
1299                 return undef;
1300         }
1301         close(BADNAME_TARGET);
1302         chmod 0666, $badname_target;
1303
1304         ## (A bad name, would not be mangled to 8.3).
1305         my $badname_target = "$badnames_shrdir/\240\276\346\327\377\177";
1306         unless (open(BADNAME_TARGET, ">$badname_target")) {
1307                 warn("Unable to open $badname_target");
1308                 return undef;
1309         }
1310         close(BADNAME_TARGET);
1311         chmod 0666, $badname_target;
1312
1313         ## (A bad good name).
1314         my $badname_target = "$badnames_shrdir/blank.txt";
1315         unless (open(BADNAME_TARGET, ">$badname_target")) {
1316                 warn("Unable to open $badname_target");
1317                 return undef;
1318         }
1319         close(BADNAME_TARGET);
1320         chmod 0666, $badname_target;
1321
1322         ##
1323         ## create mangleable directory names in $manglenames_shrdir
1324         ##
1325         my $manglename_target = "$manglenames_shrdir/foo:bar";
1326         mkdir($manglename_target, 0777);
1327
1328         ##
1329         ## create symlinks for widelinks tests.
1330         ##
1331         my $widelinks_target = "$widelinks_linkdir/target";
1332         unless (open(WIDELINKS_TARGET, ">$widelinks_target")) {
1333                 warn("Unable to open $widelinks_target");
1334                 return undef;
1335         }
1336         close(WIDELINKS_TARGET);
1337         chmod 0666, $widelinks_target;
1338         ##
1339         ## This link should get ACCESS_DENIED
1340         ##
1341         symlink "$widelinks_target", "$widelinks_shrdir/source";
1342         ##
1343         ## This link should be allowed
1344         ##
1345         symlink "$widelinks_shrdir", "$widelinks_shrdir/dot";
1346
1347         my $conffile="$libdir/server.conf";
1348         my $dfqconffile="$libdir/dfq.conf";
1349
1350         my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
1351         my $nss_wrapper_passwd = "$privatedir/passwd";
1352         my $nss_wrapper_group = "$privatedir/group";
1353         my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
1354         my $resolv_conf = "$privatedir/resolv.conf";
1355         my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
1356
1357         my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
1358
1359         my $fake_snap_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/fake_snap.pl";
1360
1361         my @eventlog_list = ("dns server", "application");
1362
1363         ##
1364         ## calculate uids and gids
1365         ##
1366
1367         my ($max_uid, $max_gid);
1368         my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
1369         my ($uid_pdbtest_wkn);
1370         my ($uid_smbget);
1371         my ($uid_force_user);
1372         my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
1373         my ($gid_userdup, $gid_everyone);
1374         my ($gid_force_user);
1375         my ($uid_user1);
1376         my ($uid_user2);
1377
1378         if ($unix_uid < 0xffff - 10) {
1379                 $max_uid = 0xffff;
1380         } else {
1381                 $max_uid = $unix_uid;
1382         }
1383
1384         $uid_root = $max_uid - 1;
1385         $uid_nobody = $max_uid - 2;
1386         $uid_pdbtest = $max_uid - 3;
1387         $uid_pdbtest2 = $max_uid - 4;
1388         $uid_userdup = $max_uid - 5;
1389         $uid_pdbtest_wkn = $max_uid - 6;
1390         $uid_force_user = $max_uid - 7;
1391         $uid_smbget = $max_uid - 8;
1392         $uid_user1 = $max_uid - 9;
1393         $uid_user2 = $max_uid - 10;
1394
1395         if ($unix_gids[0] < 0xffff - 8) {
1396                 $max_gid = 0xffff;
1397         } else {
1398                 $max_gid = $unix_gids[0];
1399         }
1400
1401         $gid_nobody = $max_gid - 1;
1402         $gid_nogroup = $max_gid - 2;
1403         $gid_root = $max_gid - 3;
1404         $gid_domusers = $max_gid - 4;
1405         $gid_domadmins = $max_gid - 5;
1406         $gid_userdup = $max_gid - 6;
1407         $gid_everyone = $max_gid - 7;
1408         $gid_force_user = $max_gid - 8;
1409
1410         ##
1411         ## create conffile
1412         ##
1413
1414         unless (open(CONF, ">$conffile")) {
1415                 warn("Unable to open $conffile");
1416                 return undef;
1417         }
1418         print CONF "
1419 [global]
1420         netbios name = $server
1421         interfaces = $server_ip/8 $server_ipv6/64
1422         bind interfaces only = yes
1423         panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
1424         smbd:suicide mode = yes
1425
1426         workgroup = $domain
1427
1428         private dir = $privatedir
1429         pid directory = $piddir
1430         lock directory = $lockdir
1431         log file = $logdir/log.\%m
1432         log level = 1
1433         debug pid = yes
1434         max log size = 0
1435
1436         state directory = $lockdir
1437         cache directory = $lockdir
1438
1439         passdb backend = tdbsam
1440
1441         time server = yes
1442
1443         add user script =               $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1444         add group script =              $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action add --name %g
1445         add machine script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1446         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
1447         delete user script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1448         delete group script =           $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action delete --name %g
1449         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
1450
1451         addprinter command =            $mod_printer_pl -a -s $conffile --
1452         deleteprinter command =         $mod_printer_pl -d -s $conffile --
1453
1454         eventlog list = application \"dns server\"
1455
1456         kernel oplocks = no
1457         kernel change notify = no
1458
1459         logging = file
1460         printing = bsd
1461         printcap name = /dev/null
1462
1463         winbindd socket directory = $wbsockdir
1464         nmbd:socket dir = $nmbdsockdir
1465         idmap config * : range = 100000-200000
1466         winbind enum users = yes
1467         winbind enum groups = yes
1468         winbind separator = /
1469         include system krb5 conf = no
1470
1471 #       min receivefile size = 4000
1472
1473         read only = no
1474
1475         smbd:sharedelay = 100000
1476         smbd:writetimeupdatedelay = 500000
1477         map hidden = no
1478         map system = no
1479         map readonly = no
1480         store dos attributes = yes
1481         create mask = 755
1482         dos filemode = yes
1483         strict rename = yes
1484         strict sync = yes
1485         vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1486
1487         printing = vlp
1488         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1489         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1490         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1491         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1492         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1493         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1494         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1495         lpq cache time = 0
1496         print notify backchannel = yes
1497
1498         ncalrpc dir = $prefix_abs/ncalrpc
1499
1500         # The samba3.blackbox.smbclient_s3 test uses this to test that
1501         # sending messages works, and that the %m sub works.
1502         message command = mv %s $shrdir/message.%m
1503
1504         # fsrvp server requires registry shares
1505         registry shares = yes
1506
1507         # Used by RPC SRVSVC tests
1508         add share command = $bindir_abs/smbaddshare
1509         change share command = $bindir_abs/smbchangeshare
1510         delete share command = $bindir_abs/smbdeleteshare
1511
1512         # fruit:copyfile is a global option
1513         fruit:copyfile = yes
1514
1515         #this does not mean that we use non-secure test env,
1516         #it just means we ALLOW one to be configured.
1517         allow insecure wide links = yes
1518
1519         # Begin extra options
1520         $extra_options
1521         # End extra options
1522
1523         #Include user defined custom parameters if set
1524 ";
1525
1526         if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1527                 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1528         }
1529
1530         print CONF "
1531 [tmp]
1532         path = $shrdir
1533         comment = smb username is [%U]
1534 [tmpsort]
1535         path = $shrdir
1536         comment = Load dirsort module
1537         vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1538 [tmpenc]
1539         path = $shrdir
1540         comment = encrypt smb username is [%U]
1541         smb encrypt = required
1542         vfs objects = dirsort
1543 [tmpguest]
1544         path = $shrdir
1545         guest ok = yes
1546 [guestonly]
1547         path = $shrdir
1548         guest only = yes
1549         guest ok = yes
1550 [forceuser]
1551         path = $shrdir
1552         force user = $unix_name
1553         guest ok = yes
1554 [forceuser_unixonly]
1555         comment = force a user with unix user SID and group SID
1556         path = $shrdir
1557         force user = pdbtest
1558         guest ok = yes
1559 [forceuser_wkngroup]
1560         comment = force a user with well-known group SID
1561         path = $shrdir
1562         force user = pdbtest_wkn
1563         guest ok = yes
1564 [forcegroup]
1565         path = $shrdir
1566         force group = nogroup
1567         guest ok = yes
1568 [ro-tmp]
1569         path = $ro_shrdir
1570         guest ok = yes
1571 [write-list-tmp]
1572         path = $shrdir
1573         read only = yes
1574         write list = $unix_name
1575 [valid-users-tmp]
1576         path = $shrdir
1577         valid users = $unix_name
1578         access based share enum = yes
1579 [msdfs-share]
1580         path = $msdfs_shrdir
1581         msdfs root = yes
1582         msdfs shuffle referrals = yes
1583         guest ok = yes
1584 [hideunread]
1585         copy = tmp
1586         hide unreadable = yes
1587 [tmpcase]
1588         copy = tmp
1589         case sensitive = yes
1590 [hideunwrite]
1591         copy = tmp
1592         hide unwriteable files = yes
1593 [durable]
1594         copy = tmp
1595         kernel share modes = no
1596         kernel oplocks = no
1597         posix locking = no
1598 [fs_specific]
1599         copy = tmp
1600         $fs_specific_conf
1601 [print1]
1602         copy = tmp
1603         printable = yes
1604
1605 [print2]
1606         copy = print1
1607 [print3]
1608         copy = print1
1609         default devmode = no
1610 [lp]
1611         copy = print1
1612
1613 [nfs4acl_simple]
1614         path = $shrdir
1615         comment = smb username is [%U]
1616         nfs4:mode = simple
1617         vfs objects = nfs4acl_xattr xattr_tdb
1618
1619 [nfs4acl_special]
1620         path = $shrdir
1621         comment = smb username is [%U]
1622         nfs4:mode = special
1623         vfs objects = nfs4acl_xattr xattr_tdb
1624
1625 [xcopy_share]
1626         path = $shrdir
1627         comment = smb username is [%U]
1628         create mask = 777
1629         force create mode = 777
1630 [posix_share]
1631         path = $shrdir
1632         comment = smb username is [%U]
1633         create mask = 0777
1634         force create mode = 0
1635         directory mask = 0777
1636         force directory mode = 0
1637         vfs objects = xattr_tdb streams_depot
1638 [aio]
1639         copy = tmp
1640         aio read size = 1
1641         aio write size = 1
1642
1643 [print\$]
1644         copy = tmp
1645
1646 [vfs_fruit]
1647         path = $shrdir
1648         vfs objects = catia fruit streams_xattr acl_xattr
1649         ea support = yes
1650         fruit:resource = file
1651         fruit:metadata = netatalk
1652         fruit:locking = netatalk
1653         fruit:encoding = native
1654
1655 [badname-tmp]
1656         path = $badnames_shrdir
1657         guest ok = yes
1658
1659 [manglenames_share]
1660         path = $manglenames_shrdir
1661         guest ok = yes
1662
1663 [dynamic_share]
1664         path = $shrdir/%R
1665         guest ok = yes
1666
1667 [widelinks_share]
1668         path = $widelinks_shrdir
1669         wide links = no
1670         guest ok = yes
1671
1672 [fsrvp_share]
1673         path = $shrdir
1674         comment = fake shapshots using rsync
1675         vfs objects = shell_snap shadow_copy2
1676         shell_snap:check path command = $fake_snap_pl --check
1677         shell_snap:create command = $fake_snap_pl --create
1678         shell_snap:delete command = $fake_snap_pl --delete
1679         # a relative path here fails, the snapshot dir is no longer found
1680         shadow:snapdir = $shrdir/.snapshots
1681
1682 [shadow1]
1683         path = $shadow_shrdir
1684         comment = previous versions snapshots under mount point
1685         vfs objects = shadow_copy2
1686         shadow:mountpoint = $shadow_mntdir
1687
1688 [shadow2]
1689         path = $shadow_shrdir
1690         comment = previous versions snapshots outside mount point
1691         vfs objects = shadow_copy2
1692         shadow:mountpoint = $shadow_mntdir
1693         shadow:snapdir = $shadow_tstdir/.snapshots
1694
1695 [shadow3]
1696         path = $shadow_shrdir
1697         comment = previous versions with subvolume snapshots, snapshots under base dir
1698         vfs objects = shadow_copy2
1699         shadow:mountpoint = $shadow_mntdir
1700         shadow:basedir = $shadow_basedir
1701         shadow:snapdir = $shadow_basedir/.snapshots
1702
1703 [shadow4]
1704         path = $shadow_shrdir
1705         comment = previous versions with subvolume snapshots, snapshots outside mount point
1706         vfs objects = shadow_copy2
1707         shadow:mountpoint = $shadow_mntdir
1708         shadow:basedir = $shadow_basedir
1709         shadow:snapdir = $shadow_tstdir/.snapshots
1710
1711 [shadow5]
1712         path = $shadow_shrdir
1713         comment = previous versions at volume root snapshots under mount point
1714         vfs objects = shadow_copy2
1715         shadow:mountpoint = $shadow_shrdir
1716
1717 [shadow6]
1718         path = $shadow_shrdir
1719         comment = previous versions at volume root snapshots outside mount point
1720         vfs objects = shadow_copy2
1721         shadow:mountpoint = $shadow_shrdir
1722         shadow:snapdir = $shadow_tstdir/.snapshots
1723
1724 [shadow7]
1725         path = $shadow_shrdir
1726         comment = previous versions snapshots everywhere
1727         vfs objects = shadow_copy2
1728         shadow:mountpoint = $shadow_mntdir
1729         shadow:snapdirseverywhere = yes
1730
1731 [shadow8]
1732         path = $shadow_shrdir
1733         comment = previous versions using snapsharepath
1734         vfs objects = shadow_copy2
1735         shadow:mountpoint = $shadow_mntdir
1736         shadow:snapdir = $shadow_tstdir/.snapshots
1737         shadow:snapsharepath = share
1738
1739 [shadow_fmt0]
1740         comment = Testing shadow:format with default option
1741         vfs object = shadow_copy2
1742         path = $shadow_shrdir
1743         read only = no
1744         guest ok = yes
1745         shadow:mountpoint = $shadow_mntdir
1746         shadow:basedir = $shadow_basedir
1747         shadow:snapdir = $shadow_basedir/.snapshots
1748         shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
1749
1750 [shadow_fmt1]
1751         comment = Testing shadow:format with only date component
1752         vfs object = shadow_copy2
1753         path = $shadow_shrdir
1754         read only = no
1755         guest ok = yes
1756         shadow:mountpoint = $shadow_mntdir
1757         shadow:basedir = $shadow_basedir
1758         shadow:snapdir = $shadow_basedir/.snapshots
1759         shadow:format = \@GMT-%Y-%m-%d
1760
1761 [shadow_fmt2]
1762         comment = Testing shadow:format with some hardcoded prefix
1763         vfs object = shadow_copy2
1764         path = $shadow_shrdir
1765         read only = no
1766         guest ok = yes
1767         shadow:mountpoint = $shadow_mntdir
1768         shadow:basedir = $shadow_basedir
1769         shadow:snapdir = $shadow_basedir/.snapshots
1770         shadow:format = snap\@GMT-%Y.%m.%d-%H.%M.%S
1771
1772 [shadow_fmt3]
1773         comment = Testing shadow:format with modified format
1774         vfs object = shadow_copy2
1775         path = $shadow_shrdir
1776         read only = no
1777         guest ok = yes
1778         shadow:mountpoint = $shadow_mntdir
1779         shadow:basedir = $shadow_basedir
1780         shadow:snapdir = $shadow_basedir/.snapshots
1781         shadow:format = \@GMT-%Y.%m.%d-%H_%M_%S-snap
1782
1783 [shadow_fmt4]
1784         comment = Testing shadow:snapprefix regex
1785         vfs object = shadow_copy2
1786         path = $shadow_shrdir
1787         read only = no
1788         guest ok = yes
1789         shadow:mountpoint = $shadow_mntdir
1790         shadow:basedir = $shadow_basedir
1791         shadow:snapdir = $shadow_basedir/.snapshots
1792         shadow:snapprefix = \^s[a-z]*p\$
1793         shadow:format = _GMT-%Y.%m.%d-%H.%M.%S
1794
1795 [shadow_fmt5]
1796         comment = Testing shadow:snapprefix with delim regex
1797         vfs object = shadow_copy2
1798         path = $shadow_shrdir
1799         read only = no
1800         guest ok = yes
1801         shadow:mountpoint = $shadow_mntdir
1802         shadow:basedir = $shadow_basedir
1803         shadow:snapdir = $shadow_basedir/.snapshots
1804         shadow:delimiter = \@GMT
1805         shadow:snapprefix = [a-z]*
1806         shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
1807
1808 [shadow_wl]
1809         path = $shadow_shrdir
1810         comment = previous versions with wide links allowed
1811         vfs objects = shadow_copy2
1812         shadow:mountpoint = $shadow_mntdir
1813         wide links = yes
1814 [dfq]
1815         path = $shrdir/dfree
1816         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
1817         admin users = $unix_name
1818         include = $dfqconffile
1819 [dfq_owner]
1820         path = $shrdir/dfree
1821         vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
1822         inherit owner = yes
1823         include = $dfqconffile
1824 [acl_xattr_ign_sysacl_posix]
1825         copy = tmp
1826         acl_xattr:ignore system acls = yes
1827         acl_xattr:default acl style = posix
1828 [acl_xattr_ign_sysacl_windows]
1829         copy = tmp
1830         acl_xattr:ignore system acls = yes
1831         acl_xattr:default acl style = windows
1832
1833 [mangle_illegal]
1834         copy = tmp
1835         mangled names = illegal
1836         ";
1837         close(CONF);
1838
1839         unless (open(DFQCONF, ">$dfqconffile")) {
1840                 warn("Unable to open $dfqconffile");
1841                 return undef;
1842         }
1843         close(DFQCONF);
1844
1845         ##
1846         ## create a test account
1847         ##
1848
1849         unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1850            warn("Unable to open $nss_wrapper_passwd");
1851            return undef;
1852         } 
1853         print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1854 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1855 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1856 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1857 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
1858 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
1859 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
1860 smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
1861 user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
1862 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
1863 ";
1864         if ($unix_uid != 0) {
1865                 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
1866 ";
1867         }
1868         close(PASSWD);
1869
1870         unless (open(GROUP, ">$nss_wrapper_group")) {
1871              warn("Unable to open $nss_wrapper_group");
1872              return undef;
1873         }
1874         print GROUP "nobody:x:$gid_nobody:
1875 nogroup:x:$gid_nogroup:nobody
1876 $unix_name-group:x:$unix_gids[0]:
1877 domusers:X:$gid_domusers:
1878 domadmins:X:$gid_domadmins:
1879 userdup:x:$gid_userdup:$unix_name
1880 everyone:x:$gid_everyone:
1881 force_user:x:$gid_force_user:
1882 ";
1883         if ($unix_gids[0] != 0) {
1884                 print GROUP "root:x:$gid_root:
1885 ";
1886         }
1887
1888         close(GROUP);
1889
1890         ## hosts
1891         my $hostname = lc($server);
1892         unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
1893                 warn("Unable to open $nss_wrapper_hosts");
1894                 return undef;
1895         }
1896         print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n";
1897         print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n";
1898         close(HOSTS);
1899
1900         ## hosts
1901         unless (open(RESOLV_CONF, ">$resolv_conf")) {
1902                 warn("Unable to open $resolv_conf");
1903                 return undef;
1904         }
1905         if (defined($dc_server_ip) or defined($dc_server_ipv6)) {
1906                 if (defined($dc_server_ip)) {
1907                         print RESOLV_CONF "nameserver $dc_server_ip\n";
1908                 }
1909                 if (defined($dc_server_ipv6)) {
1910                         print RESOLV_CONF "nameserver $dc_server_ipv6\n";
1911                 }
1912         } else {
1913                 print RESOLV_CONF "nameserver ${server_ip}\n";
1914                 print RESOLV_CONF "nameserver ${server_ipv6}\n";
1915         }
1916         close(RESOLV_CONF);
1917
1918         foreach my $evlog (@eventlog_list) {
1919                 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1920                 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1921                 close(EVENTLOG);
1922         }
1923
1924         $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1925         $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1926         $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1927         $ENV{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
1928         if ($ENV{SAMBA_DNS_FAKING}) {
1929                 $ENV{RESOLV_WRAPPER_CONF} = $resolv_conf;
1930         } else {
1931                 $ENV{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
1932         }
1933
1934         createuser($self, $unix_name, $password, $conffile) || die("Unable to create user");
1935         createuser($self, "force_user", $password, $conffile) || die("Unable to create force_user");
1936         createuser($self, "smbget_user", $password, $conffile) || die("Unable to create smbget_user");
1937         createuser($self, "user1", $password, $conffile) || die("Unable to create user1");
1938         createuser($self, "user2", $password, $conffile) || die("Unable to create user2");
1939
1940         open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1941         print DNS_UPDATE_LIST "A $server. $server_ip\n";
1942         print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
1943         close(DNS_UPDATE_LIST);
1944
1945         print "DONE\n";
1946
1947         $ret{SERVER_IP} = $server_ip;
1948         $ret{SERVER_IPV6} = $server_ipv6;
1949         $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1950         $ret{NMBD_TEST_LOG_POS} = 0;
1951         $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1952         $ret{WINBINDD_TEST_LOG_POS} = 0;
1953         $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1954         $ret{SMBD_TEST_LOG_POS} = 0;
1955         $ret{SERVERCONFFILE} = $conffile;
1956         $ret{CONFIGURATION} ="-s $conffile";
1957         $ret{SERVER} = $server;
1958         $ret{USERNAME} = $unix_name;
1959         $ret{USERID} = $unix_uid;
1960         $ret{DOMAIN} = $domain;
1961         $ret{NETBIOSNAME} = $server;
1962         $ret{PASSWORD} = $password;
1963         $ret{PIDDIR} = $piddir;
1964         $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
1965         $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1966         $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1967         $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1968         $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1969         $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1970         $ret{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
1971         $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1972         $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
1973         if ($ENV{SAMBA_DNS_FAKING}) {
1974                 $ret{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
1975         } else {
1976                 $ret{RESOLV_WRAPPER_CONF} = $resolv_conf;
1977         }
1978         $ret{LOCAL_PATH} = "$shrdir";
1979         $ret{LOGDIR} = $logdir;
1980
1981         #
1982         # Avoid hitting system krb5.conf -
1983         # An env that needs Kerberos will reset this to the real
1984         # value.
1985         #
1986         $ret{KRB5_CONFIG} = abs_path($prefix) . "/no_krb5.conf";
1987
1988         # Define KRB5CCNAME for each environment we set up
1989         $ret{KRB5_CCACHE} = abs_path($prefix) . "/krb5ccache";
1990         $ENV{KRB5CCNAME} = $ret{KRB5_CCACHE};
1991
1992         return \%ret;
1993 }
1994
1995 sub wait_for_start($$$$$)
1996 {
1997         my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1998         my $ret;
1999
2000         if ($nmbd eq "yes") {
2001                 my $count = 0;
2002
2003                 # give time for nbt server to register its names
2004                 print "checking for nmbd\n";
2005
2006                 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
2007                 my $nmblookup = Samba::bindir_path($self, "nmblookup");
2008
2009                 do {
2010                         $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
2011                         if ($ret != 0) {
2012                                 sleep(1);
2013                         } else {
2014                                 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
2015                                 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
2016                                 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
2017                                 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
2018                         }
2019                         $count++;
2020                 } while ($ret != 0 && $count < 10);
2021                 if ($count == 10) {
2022                         print "NMBD not reachable after 10 retries\n";
2023                         teardown_env($self, $envvars);
2024                         return 0;
2025                 }
2026         }
2027
2028         if ($winbindd eq "yes") {
2029             print "checking for winbindd\n";
2030             my $count = 0;
2031             do {
2032                 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --ping-dc");
2033                 if ($ret != 0) {
2034                     sleep(1);
2035                 }
2036                 $count++;
2037             } while ($ret != 0 && $count < 20);
2038             if ($count == 20) {
2039                 print "WINBINDD not reachable after 20 seconds\n";
2040                 teardown_env($self, $envvars);
2041                 return 0;
2042             }
2043         }
2044
2045         if ($smbd eq "yes") {
2046             # make sure smbd is also up set
2047             print "wait for smbd\n";
2048
2049             my $count = 0;
2050             do {
2051                 $ret = system(Samba::bindir_path($self, "smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
2052                 if ($ret != 0) {
2053                     sleep(1);
2054                 }
2055                 $count++
2056             } while ($ret != 0 && $count < 20);
2057             if ($count == 20) {
2058                 print "SMBD failed to start up in a reasonable time (20sec)\n";
2059                 teardown_env($self, $envvars);
2060                 return 0;
2061             }
2062         }
2063
2064         # Ensure we have domain users mapped.
2065         $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
2066         if ($ret != 0) {
2067             return 1;
2068         }
2069         $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
2070         if ($ret != 0) {
2071             return 1;
2072         }
2073         $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add sid=S-1-1-0 unixgroup=everyone type=builtin");
2074         if ($ret != 0) {
2075             return 1;
2076         }
2077
2078         if ($winbindd eq "yes") {
2079             # note: creating builtin groups requires winbindd for the
2080             # unix id allocator
2081             $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
2082             if ($ret != 0) {
2083                 print "Failed to create BUILTIN\\Users group\n";
2084                 return 0;
2085             }
2086             my $count = 0;
2087             do {
2088                 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
2089                 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
2090                 if ($ret != 0) {
2091                     sleep(2);
2092                 }
2093                 $count++;
2094             } while ($ret != 0 && $count < 10);
2095             if ($count == 10) {
2096                 print "WINBINDD not reachable after 20 seconds\n";
2097                 teardown_env($self, $envvars);
2098                 return 0;
2099             }
2100         }
2101
2102         print $self->getlog_env($envvars);
2103
2104         return 1;
2105 }
2106
2107 1;