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