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