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