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