selftest: Bind rfc2307 tests to exactly one server
[Samba.git] / selftest / target / Samba3.pm
blobabf1b7b2e40dace485de651412511e12f6969739
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.
6 package Samba3;
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12 use target::Samba;
13 use File::Path 'remove_tree';
15 sub have_ads($) {
16 my ($self) = @_;
17 my $found_ads = 0;
18 my $smbd_build_options = Samba::bindir_path($self, "smbd") . " -b|";
19 open(IN, $smbd_build_options) or die("Unable to run $smbd_build_options: $!");
21 while (<IN>) {
22 if (/WITH_ADS/) {
23 $found_ads = 1;
26 close IN;
28 # If we were not built with ADS support, pretend we were never even available
29 print "smbd does not have ADS support\n" unless $found_ads;
30 return $found_ads;
33 # return smb.conf parameters applicable to @path, based on the underlying
34 # filesystem type
35 sub get_fs_specific_conf($$)
37 my ($self, $path) = @_;
38 my $mods = "";
39 my $stat_out = `stat --file-system $path` or return "";
41 if ($stat_out =~ m/Type:\s+btrfs/) {
42 $mods .= "streams_xattr btrfs";
45 if ($mods) {
46 return "vfs objects = $mods";
49 return undef;
52 sub new($$) {
53 my ($classname, $bindir, $srcdir, $server_maxtime) = @_;
54 my $self = { vars => {},
55 bindir => $bindir,
56 srcdir => $srcdir,
57 server_maxtime => $server_maxtime
59 bless $self;
60 return $self;
63 sub teardown_env($$)
65 my ($self, $envvars) = @_;
66 my $count = 0;
68 # This should cause smbd to terminate gracefully
69 close($envvars->{STDIN_PIPE});
71 my $smbdpid = $envvars->{SMBD_TL_PID};
72 my $nmbdpid = $envvars->{NMBD_TL_PID};
73 my $winbinddpid = $envvars->{WINBINDD_TL_PID};
75 # This should give it time to write out the gcov data
76 until ($count > 20) {
77 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
78 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
79 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
80 if ($smbdchild == -1
81 && $nmbdchild == -1
82 && $winbinddchild == -1) {
83 last;
85 sleep(1);
86 $count++;
89 if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
90 return;
93 $self->stop_sig_term($smbdpid);
94 $self->stop_sig_term($nmbdpid);
95 $self->stop_sig_term($winbinddpid);
97 $count = 0;
98 until ($count > 10) {
99 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
100 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
101 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
102 if ($smbdchild == -1
103 && $nmbdchild == -1
104 && $winbinddchild == -1) {
105 last;
107 sleep(1);
108 $count++;
111 if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
112 return;
115 warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
116 $self->stop_sig_kill($smbdpid);
117 $self->stop_sig_kill($nmbdpid);
118 $self->stop_sig_kill($winbinddpid);
120 return 0;
123 sub getlog_env_app($$$)
125 my ($self, $envvars, $name) = @_;
127 my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
128 my $out = $title;
130 open(LOG, "<".$envvars->{$name."_TEST_LOG"});
132 seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
133 while (<LOG>) {
134 $out .= $_;
136 $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
137 close(LOG);
139 return "" if $out eq $title;
141 return $out;
144 sub getlog_env($$)
146 my ($self, $envvars) = @_;
147 my $ret = "";
149 $ret .= $self->getlog_env_app($envvars, "SMBD");
150 $ret .= $self->getlog_env_app($envvars, "NMBD");
151 $ret .= $self->getlog_env_app($envvars, "WINBINDD");
153 return $ret;
156 sub check_env($$)
158 my ($self, $envvars) = @_;
160 my $childpid = waitpid(-1, WNOHANG);
162 # TODO ...
163 return 1;
166 sub setup_env($$$)
168 my ($self, $envname, $path) = @_;
170 $ENV{ENVNAME} = $envname;
172 if (defined($self->{vars}->{$envname})) {
173 return $self->{vars}->{$envname};
177 # Avoid hitting system krb5.conf -
178 # An env that needs Kerberos will reset this to the real
179 # value.
181 $ENV{KRB5_CONFIG} = "$path/no_krb5.conf";
183 if ($envname eq "nt4_dc") {
184 return $self->setup_nt4_dc("$path/nt4_dc");
185 } elsif ($envname eq "nt4_dc_schannel") {
186 return $self->setup_nt4_dc_schannel("$path/nt4_dc_schannel");
187 } elsif ($envname eq "simpleserver") {
188 return $self->setup_simpleserver("$path/simpleserver");
189 } elsif ($envname eq "fileserver") {
190 return $self->setup_fileserver("$path/fileserver");
191 } elsif ($envname eq "maptoguest") {
192 return $self->setup_maptoguest("$path/maptoguest");
193 } elsif ($envname eq "ktest") {
194 return $self->setup_ktest("$path/ktest");
195 } elsif ($envname eq "nt4_member") {
196 if (not defined($self->{vars}->{nt4_dc})) {
197 if (not defined($self->setup_nt4_dc("$path/nt4_dc"))) {
198 return undef;
201 return $self->setup_nt4_member("$path/nt4_member", $self->{vars}->{nt4_dc});
202 } else {
203 return "UNKNOWN";
207 sub setup_nt4_dc($$)
209 my ($self, $path) = @_;
211 print "PROVISIONING NT4 DC...";
213 my $nt4_dc_options = "
214 domain master = yes
215 domain logons = yes
216 lanman auth = yes
217 ntlm auth = yes
218 raw NTLMv2 auth = yes
220 rpc_server:epmapper = external
221 rpc_server:spoolss = external
222 rpc_server:lsarpc = external
223 rpc_server:samr = external
224 rpc_server:netlogon = external
225 rpc_server:register_embedded_np = yes
226 rpc_server:FssagentRpc = external
228 rpc_daemon:epmd = fork
229 rpc_daemon:spoolssd = fork
230 rpc_daemon:lsasd = fork
231 rpc_daemon:fssd = fork
232 fss: sequence timeout = 1
235 my $vars = $self->provision($path, "SAMBA-TEST",
236 "LOCALNT4DC2",
237 "localntdc2pass",
238 $nt4_dc_options);
240 $vars or return undef;
242 if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
243 return undef;
246 $vars->{DC_SERVER} = $vars->{SERVER};
247 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
248 $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
249 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
250 $vars->{DC_USERNAME} = $vars->{USERNAME};
251 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
253 $self->{vars}->{nt4_dc} = $vars;
255 return $vars;
258 sub setup_nt4_dc_schannel($$)
260 my ($self, $path) = @_;
262 print "PROVISIONING NT4 DC WITH SERVER SCHANNEL ...";
264 my $pdc_options = "
265 domain master = yes
266 domain logons = yes
267 lanman auth = yes
269 rpc_server:epmapper = external
270 rpc_server:spoolss = external
271 rpc_server:lsarpc = external
272 rpc_server:samr = external
273 rpc_server:netlogon = external
274 rpc_server:register_embedded_np = yes
276 rpc_daemon:epmd = fork
277 rpc_daemon:spoolssd = fork
278 rpc_daemon:lsasd = fork
280 server schannel = yes
281 # used to reproduce bug #12772
282 server max protocol = SMB2_02
285 my $vars = $self->provision($path, "NT4SCHANNEL",
286 "LOCALNT4DC9",
287 "localntdc9pass",
288 $pdc_options);
290 $vars or return undef;
292 if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
293 return undef;
296 $vars->{DC_SERVER} = $vars->{SERVER};
297 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
298 $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
299 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
300 $vars->{DC_USERNAME} = $vars->{USERNAME};
301 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
303 $self->{vars}->{nt4_dc_schannel} = $vars;
305 return $vars;
308 sub setup_nt4_member($$$)
310 my ($self, $prefix, $nt4_dc_vars) = @_;
311 my $count = 0;
312 my $rc;
314 print "PROVISIONING MEMBER...";
316 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
317 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
319 my $member_options = "
320 security = domain
321 dbwrap_tdb_mutexes:* = yes
322 ${require_mutexes}
324 my $ret = $self->provision($prefix, $nt4_dc_vars->{DOMAIN},
325 "LOCALNT4MEMBER3",
326 "localnt4member3pass",
327 $member_options);
329 $ret or return undef;
331 my $nmblookup = Samba::bindir_path($self, "nmblookup");
332 do {
333 print "Waiting for the LOGON SERVER registration ...\n";
334 $rc = system("$nmblookup $ret->{CONFIGURATION} $ret->{DOMAIN}\#1c");
335 if ($rc != 0) {
336 sleep(1);
338 $count++;
339 } while ($rc != 0 && $count < 10);
340 if ($count == 10) {
341 print "NMBD not reachable after 10 retries\n";
342 teardown_env($self, $ret);
343 return 0;
346 my $net = Samba::bindir_path($self, "net");
347 my $cmd = "";
348 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
349 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
350 $cmd .= "$net join $ret->{CONFIGURATION} $nt4_dc_vars->{DOMAIN} member";
351 $cmd .= " -U$nt4_dc_vars->{USERNAME}\%$nt4_dc_vars->{PASSWORD}";
353 if (system($cmd) != 0) {
354 warn("Join failed\n$cmd");
355 return undef;
358 my $cmd = "";
359 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
360 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
361 $cmd .= "$net $ret->{CONFIGURATION} primarytrust dumpinfo | grep -q 'REDACTED SECRET VALUES'";
363 if (system($cmd) != 0) {
364 warn("check failed\n$cmd");
365 return undef;
368 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
369 return undef;
372 $ret->{DC_SERVER} = $nt4_dc_vars->{SERVER};
373 $ret->{DC_SERVER_IP} = $nt4_dc_vars->{SERVER_IP};
374 $ret->{DC_SERVER_IPV6} = $nt4_dc_vars->{SERVER_IPV6};
375 $ret->{DC_NETBIOSNAME} = $nt4_dc_vars->{NETBIOSNAME};
376 $ret->{DC_USERNAME} = $nt4_dc_vars->{USERNAME};
377 $ret->{DC_PASSWORD} = $nt4_dc_vars->{PASSWORD};
379 return $ret;
382 sub setup_admember($$$$)
384 my ($self, $prefix, $dcvars) = @_;
386 my $prefix_abs = abs_path($prefix);
387 my @dirs = ();
389 # If we didn't build with ADS, pretend this env was never available
390 if (not $self->have_ads()) {
391 return "UNKNOWN";
394 print "PROVISIONING S3 AD MEMBER...";
396 mkdir($prefix_abs, 0777);
398 my $share_dir="$prefix_abs/share";
399 push(@dirs, $share_dir);
401 my $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}";
402 push(@dirs, $substitution_path);
404 $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/U_alice";
405 push(@dirs, $substitution_path);
407 $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/U_alice/G_domain users";
408 push(@dirs, $substitution_path);
410 # Using '/' as the winbind separator is a bad idea ...
411 $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}";
412 push(@dirs, $substitution_path);
414 $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice";
415 push(@dirs, $substitution_path);
417 $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice/g_$dcvars->{DOMAIN}";
418 push(@dirs, $substitution_path);
420 $substitution_path = "$share_dir/D_$dcvars->{DOMAIN}/u_$dcvars->{DOMAIN}/alice/g_$dcvars->{DOMAIN}/domain users";
421 push(@dirs, $substitution_path);
423 my $member_options = "
424 security = ads
425 workgroup = $dcvars->{DOMAIN}
426 realm = $dcvars->{REALM}
427 netbios aliases = foo bar
428 template homedir = /home/%D/%G/%U
430 [sub_dug]
431 path = $share_dir/D_%D/U_%U/G_%G
432 writeable = yes
434 [sub_dug2]
435 path = $share_dir/D_%D/u_%u/g_%g
436 writeable = yes
440 my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
441 "LOCALADMEMBER",
442 "loCalMemberPass",
443 $member_options,
444 $dcvars->{SERVER_IP},
445 $dcvars->{SERVER_IPV6});
447 $ret or return undef;
449 mkdir($_, 0777) foreach(@dirs);
451 close(USERMAP);
452 $ret->{DOMAIN} = $dcvars->{DOMAIN};
453 $ret->{REALM} = $dcvars->{REALM};
455 my $ctx;
456 $ctx = {};
457 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
458 $ctx->{domain} = $dcvars->{DOMAIN};
459 $ctx->{realm} = $dcvars->{REALM};
460 $ctx->{dnsname} = lc($dcvars->{REALM});
461 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
462 $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
463 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
464 Samba::mk_krb5_conf($ctx, "");
466 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
468 my $net = Samba::bindir_path($self, "net");
469 my $cmd = "";
470 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
471 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
472 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
473 } else {
474 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
476 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
477 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
478 $cmd .= "$net join $ret->{CONFIGURATION}";
479 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
481 if (system($cmd) != 0) {
482 warn("Join failed\n$cmd");
483 return undef;
486 # We need world access to this share, as otherwise the domain
487 # administrator from the AD domain provided by Samba4 can't
488 # access the share for tests.
489 chmod 0777, "$prefix/share";
491 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
492 return undef;
495 $ret->{DC_SERVER} = $dcvars->{SERVER};
496 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
497 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
498 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
499 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
500 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
502 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
503 $ret->{target} = $self;
505 return $ret;
508 sub setup_admember_rfc2307($$$$)
510 my ($self, $prefix, $dcvars) = @_;
512 # If we didn't build with ADS, pretend this env was never available
513 if (not $self->have_ads()) {
514 return "UNKNOWN";
517 print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
519 my $member_options = "
520 security = ads
521 workgroup = $dcvars->{DOMAIN}
522 realm = $dcvars->{REALM}
523 idmap cache time = 0
524 idmap negative cache time = 0
525 idmap config * : backend = autorid
526 idmap config * : range = 1000000-1999999
527 idmap config * : rangesize = 100000
528 idmap config $dcvars->{DOMAIN} : backend = rfc2307
529 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
530 idmap config $dcvars->{DOMAIN} : ldap_server = ad
531 idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
532 idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
534 password server = $dcvars->{SERVER}
537 my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
538 "RFC2307MEMBER",
539 "loCalMemberPass",
540 $member_options,
541 $dcvars->{SERVER_IP},
542 $dcvars->{SERVER_IPV6});
544 $ret or return undef;
546 close(USERMAP);
547 $ret->{DOMAIN} = $dcvars->{DOMAIN};
548 $ret->{REALM} = $dcvars->{REALM};
550 my $ctx;
551 my $prefix_abs = abs_path($prefix);
552 $ctx = {};
553 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
554 $ctx->{domain} = $dcvars->{DOMAIN};
555 $ctx->{realm} = $dcvars->{REALM};
556 $ctx->{dnsname} = lc($dcvars->{REALM});
557 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
558 $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
559 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
560 Samba::mk_krb5_conf($ctx, "");
562 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
564 my $net = Samba::bindir_path($self, "net");
565 my $cmd = "";
566 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
567 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
568 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
569 } else {
570 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
572 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
573 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
574 $cmd .= "$net join $ret->{CONFIGURATION}";
575 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
577 if (system($cmd) != 0) {
578 warn("Join failed\n$cmd");
579 return undef;
582 # We need world access to this share, as otherwise the domain
583 # administrator from the AD domain provided by Samba4 can't
584 # access the share for tests.
585 chmod 0777, "$prefix/share";
587 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
588 return undef;
591 $ret->{DC_SERVER} = $dcvars->{SERVER};
592 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
593 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
594 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
595 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
596 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
598 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
599 $ret->{target} = $self;
601 return $ret;
604 sub setup_ad_member_idmap_rid($$$$)
606 my ($self, $prefix, $dcvars) = @_;
608 # If we didn't build with ADS, pretend this env was never available
609 if (not $self->have_ads()) {
610 return "UNKNOWN";
613 print "PROVISIONING S3 AD MEMBER WITH idmap_rid config...";
615 my $member_options = "
616 security = ads
617 workgroup = $dcvars->{DOMAIN}
618 realm = $dcvars->{REALM}
619 idmap config * : backend = tdb
620 idmap config * : range = 1000000-1999999
621 idmap config $dcvars->{DOMAIN} : backend = rid
622 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
625 my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
626 "IDMAPRIDMEMBER",
627 "loCalMemberPass",
628 $member_options,
629 $dcvars->{SERVER_IP},
630 $dcvars->{SERVER_IPV6});
632 $ret or return undef;
634 close(USERMAP);
635 $ret->{DOMAIN} = $dcvars->{DOMAIN};
636 $ret->{REALM} = $dcvars->{REALM};
638 my $ctx;
639 my $prefix_abs = abs_path($prefix);
640 $ctx = {};
641 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
642 $ctx->{domain} = $dcvars->{DOMAIN};
643 $ctx->{realm} = $dcvars->{REALM};
644 $ctx->{dnsname} = lc($dcvars->{REALM});
645 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
646 $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
647 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
648 Samba::mk_krb5_conf($ctx, "");
650 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
652 my $net = Samba::bindir_path($self, "net");
653 my $cmd = "";
654 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
655 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
656 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
657 } else {
658 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
660 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
661 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
662 $cmd .= "$net join $ret->{CONFIGURATION}";
663 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
665 if (system($cmd) != 0) {
666 warn("Join failed\n$cmd");
667 return undef;
670 # We need world access to this share, as otherwise the domain
671 # administrator from the AD domain provided by Samba4 can't
672 # access the share for tests.
673 chmod 0777, "$prefix/share";
675 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
676 return undef;
679 $ret->{DC_SERVER} = $dcvars->{SERVER};
680 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
681 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
682 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
683 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
684 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
686 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
687 $ret->{target} = $self;
689 return $ret;
692 sub setup_simpleserver($$)
694 my ($self, $path) = @_;
696 print "PROVISIONING simple server...";
698 my $prefix_abs = abs_path($path);
700 my $simpleserver_options = "
701 lanman auth = yes
702 ntlm auth = yes
703 vfs objects = xattr_tdb streams_depot time_audit full_audit
704 change notify = no
705 smb encrypt = off
707 full_audit:syslog = no
708 full_audit:success = none
709 full_audit:failure = none
711 [vfs_aio_fork]
712 path = $prefix_abs/share
713 vfs objects = aio_fork
714 read only = no
715 vfs_aio_fork:erratic_testing_mode=yes
717 [dosmode]
718 path = $prefix_abs/share
719 vfs objects =
720 store dos attributes = yes
721 hide files = /hidefile/
722 hide dot files = yes
724 [enc_desired]
725 path = $prefix_abs/share
726 vfs objects =
727 smb encrypt = desired
730 my $vars = $self->provision($path, "WORKGROUP",
731 "LOCALSHARE4",
732 "local4pass",
733 $simpleserver_options);
735 $vars or return undef;
737 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
738 return undef;
741 $self->{vars}->{simpleserver} = $vars;
743 return $vars;
746 sub setup_fileserver($$)
748 my ($self, $path) = @_;
749 my $prefix_abs = abs_path($path);
750 my $srcdir_abs = abs_path($self->{srcdir});
752 print "PROVISIONING file server ...\n";
754 my @dirs = ();
756 mkdir($prefix_abs, 0777);
758 my $usershare_dir="$prefix_abs/lib/usershare";
760 mkdir("$prefix_abs/lib", 0755);
761 remove_tree($usershare_dir);
762 mkdir($usershare_dir, 01770);
764 my $share_dir="$prefix_abs/share";
766 # Create share directory structure
767 my $lower_case_share_dir="$share_dir/lower-case";
768 push(@dirs, $lower_case_share_dir);
770 my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
771 push(@dirs, $lower_case_share_dir_30000);
773 my $dfree_share_dir="$share_dir/dfree";
774 push(@dirs, $dfree_share_dir);
775 push(@dirs, "$dfree_share_dir/subdir1");
776 push(@dirs, "$dfree_share_dir/subdir2");
777 push(@dirs, "$dfree_share_dir/subdir3");
779 my $valid_users_sharedir="$share_dir/valid_users";
780 push(@dirs,$valid_users_sharedir);
782 my $offline_sharedir="$share_dir/offline";
783 push(@dirs,$offline_sharedir);
785 my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
786 push(@dirs, $force_user_valid_users_dir);
788 my $smbget_sharedir="$share_dir/smbget";
789 push(@dirs,$smbget_sharedir);
791 my $tarmode_sharedir="$share_dir/tarmode";
792 push(@dirs,$tarmode_sharedir);
794 my $usershare_sharedir="$share_dir/usershares";
795 push(@dirs,$usershare_sharedir);
797 my $fileserver_options = "
798 usershare path = $usershare_dir
799 usershare max shares = 10
800 usershare allow guests = yes
801 usershare prefix allow list = $usershare_sharedir
803 [lowercase]
804 path = $lower_case_share_dir
805 comment = smb username is [%U]
806 case sensitive = True
807 default case = lower
808 preserve case = no
809 short preserve case = no
810 [lowercase-30000]
811 path = $lower_case_share_dir_30000
812 comment = smb username is [%U]
813 case sensitive = True
814 default case = lower
815 preserve case = no
816 short preserve case = no
817 [dfree]
818 path = $dfree_share_dir
819 comment = smb username is [%U]
820 dfree command = $srcdir_abs/testprogs/blackbox/dfree.sh
821 [valid-users-access]
822 path = $valid_users_sharedir
823 valid users = +userdup
824 [offline]
825 path = $offline_sharedir
826 vfs objects = offline
828 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
829 # RH BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
830 [force_user_valid_users]
831 path = $force_user_valid_users_dir
832 comment = force user with valid users combination test share
833 valid users = +force_user
834 force user = force_user
835 force group = everyone
836 write list = force_user
838 [smbget]
839 path = $smbget_sharedir
840 comment = smb username is [%U]
841 guest ok = yes
842 [ign_sysacls]
843 path = $share_dir
844 comment = ignore system acls
845 acl_xattr:ignore system acls = yes
846 [inherit_owner]
847 path = $share_dir
848 comment = inherit owner
849 inherit owner = yes
850 [inherit_owner_u]
851 path = $share_dir
852 comment = inherit only unix owner
853 inherit owner = unix only
854 acl_xattr:ignore system acls = yes
857 my $vars = $self->provision($path, "WORKGROUP",
858 "FILESERVER",
859 "fileserver",
860 $fileserver_options,
861 undef,
862 undef,
865 $vars or return undef;
867 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
868 return undef;
871 $self->{vars}->{fileserver} = $vars;
873 mkdir($_, 0777) foreach(@dirs);
875 ## Create case sensitive lower case share dir
876 foreach my $file ('a'..'z') {
877 my $full_path = $lower_case_share_dir . '/' . $file;
878 open my $fh, '>', $full_path;
879 # Add some content to file
880 print $fh $full_path;
881 close $fh;
884 for (my $file = 1; $file < 51; ++$file) {
885 my $full_path = $lower_case_share_dir . '/' . $file;
886 open my $fh, '>', $full_path;
887 # Add some content to file
888 print $fh $full_path;
889 close $fh;
892 # Create content for 30000 share
893 foreach my $file ('a'..'z') {
894 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
895 open my $fh, '>', $full_path;
896 # Add some content to file
897 print $fh $full_path;
898 close $fh;
901 for (my $file = 1; $file < 30001; ++$file) {
902 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
903 open my $fh, '>', $full_path;
904 # Add some content to file
905 print $fh $full_path;
906 close $fh;
910 ## create a listable file in valid_users_share
912 my $valid_users_target = "$valid_users_sharedir/foo";
913 unless (open(VALID_USERS_TARGET, ">$valid_users_target")) {
914 warn("Unable to open $valid_users_target");
915 return undef;
917 close(VALID_USERS_TARGET);
918 chmod 0644, $valid_users_target;
920 return $vars;
923 sub setup_ktest($$$)
925 my ($self, $prefix) = @_;
927 # If we didn't build with ADS, pretend this env was never available
928 if (not $self->have_ads()) {
929 return "UNKNOWN";
932 print "PROVISIONING server with security=ads...";
934 my $ktest_options = "
935 workgroup = KTEST
936 realm = ktest.samba.example.com
937 security = ads
938 username map = $prefix/lib/username.map
939 server signing = required
940 server min protocol = SMB3_00
941 client max protocol = SMB3
944 my $ret = $self->provision($prefix, "KTEST",
945 "LOCALKTEST6",
946 "localktest6pass",
947 $ktest_options);
949 $ret or return undef;
951 my $ctx;
952 my $prefix_abs = abs_path($prefix);
953 $ctx = {};
954 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
955 $ctx->{domain} = "KTEST";
956 $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
957 $ctx->{dnsname} = lc($ctx->{realm});
958 $ctx->{kdc_ipv4} = "0.0.0.0";
959 $ctx->{kdc_ipv6} = "::";
960 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
961 Samba::mk_krb5_conf($ctx, "");
963 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
965 open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
966 print USERMAP "
967 $ret->{USERNAME} = KTEST\\Administrator
969 close(USERMAP);
971 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
972 #Samba4 DC with the same parameters as are being used here. The
973 #domain SID is S-1-5-21-1071277805-689288055-3486227160
975 system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
976 chmod 0600, "$prefix/private/secrets.tdb";
978 #Make sure there's no old ntdb file.
979 system("rm -f $prefix/private/secrets.ntdb");
981 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
982 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
984 #and having in krb5.conf:
985 # ticket_lifetime = 799718400
986 # renew_lifetime = 799718400
988 # The commands for the -2 keytab where were:
989 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
990 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
991 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
992 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
993 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
995 # and then for the -3 keytab, I did
997 # net changetrustpw; kdestroy and the same again.
999 # This creates a credential cache with a very long lifetime (2036 at
1000 # at 2011-04), and shows that running 'net changetrustpw' does not
1001 # break existing logins (for the secrets.tdb method at least).
1004 $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
1006 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
1007 chmod 0600, "$prefix/krb5_ccache-2";
1009 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
1010 chmod 0600, "$prefix/krb5_ccache-3";
1012 # We need world access to this share, as otherwise the domain
1013 # administrator from the AD domain provided by ktest can't
1014 # access the share for tests.
1015 chmod 0777, "$prefix/share";
1017 if (not $self->check_or_start($ret, "yes", "no", "yes")) {
1018 return undef;
1020 return $ret;
1023 sub setup_maptoguest($$)
1025 my ($self, $path) = @_;
1027 print "PROVISIONING maptoguest...";
1029 my $options = "
1030 map to guest = bad user
1031 ntlm auth = yes
1034 my $vars = $self->provision($path, "WORKGROUP",
1035 "maptoguest",
1036 "maptoguestpass",
1037 $options);
1039 $vars or return undef;
1041 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
1042 return undef;
1045 $self->{vars}->{s3maptoguest} = $vars;
1047 return $vars;
1050 sub stop_sig_term($$) {
1051 my ($self, $pid) = @_;
1052 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1055 sub stop_sig_kill($$) {
1056 my ($self, $pid) = @_;
1057 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1060 sub write_pid($$$)
1062 my ($env_vars, $app, $pid) = @_;
1064 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
1065 print PID $pid;
1066 close(PID);
1069 sub read_pid($$)
1071 my ($env_vars, $app) = @_;
1073 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
1074 my $pid = <PID>;
1075 close(PID);
1076 return $pid;
1079 sub check_or_start($$$$$) {
1080 my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
1082 # use a pipe for stdin in the child processes. This allows
1083 # those processes to monitor the pipe for EOF to ensure they
1084 # exit when the test script exits
1085 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
1087 unlink($env_vars->{NMBD_TEST_LOG});
1088 print "STARTING NMBD...";
1089 my $pid = fork();
1090 if ($pid == 0) {
1091 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
1092 open STDERR, '>&STDOUT';
1094 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1096 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1097 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.nmbd";
1098 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1099 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1101 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1102 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1103 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1104 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1105 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1106 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1107 $ENV{UID_WRAPPER_ROOT} = "1";
1109 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
1111 if ($nmbd ne "yes") {
1112 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1113 my $signame = shift;
1114 print("Skip nmbd received signal $signame");
1115 exit 0;
1117 sleep($self->{server_maxtime});
1118 exit 0;
1121 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
1122 my @optargs = ("-d0");
1123 if (defined($ENV{NMBD_OPTIONS})) {
1124 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
1126 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1127 if(defined($ENV{NMBD_VALGRIND})) {
1128 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
1130 my @args = ("-F", "--no-process-group",
1131 "-s", $env_vars->{SERVERCONFFILE},
1132 "-l", $env_vars->{LOGDIR});
1133 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
1134 push(@args, "--log-stdout");
1137 close($env_vars->{STDIN_PIPE});
1138 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1140 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1141 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1143 $env_vars->{NMBD_TL_PID} = $pid;
1144 write_pid($env_vars, "nmbd", $pid);
1145 print "DONE\n";
1147 unlink($env_vars->{WINBINDD_TEST_LOG});
1148 print "STARTING WINBINDD...";
1149 $pid = fork();
1150 if ($pid == 0) {
1151 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
1152 open STDERR, '>&STDOUT';
1154 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1156 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1157 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.winbindd";
1158 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1159 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1161 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1162 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1163 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1164 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1165 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1166 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1167 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1168 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1169 } else {
1170 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1172 $ENV{UID_WRAPPER_ROOT} = "1";
1174 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
1176 if ($winbindd ne "yes") {
1177 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1178 my $signame = shift;
1179 print("Skip winbindd received signal $signame");
1180 exit 0;
1182 sleep($self->{server_maxtime});
1183 exit 0;
1186 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
1187 my @optargs = ("-d0");
1188 if (defined($ENV{WINBINDD_OPTIONS})) {
1189 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
1191 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1192 if(defined($ENV{WINBINDD_VALGRIND})) {
1193 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
1195 my @args = ("-F", "--no-process-group",
1196 "-s", $env_vars->{SERVERCONFFILE},
1197 "-l", $env_vars->{LOGDIR});
1198 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
1199 push(@args, "--stdout");
1202 close($env_vars->{STDIN_PIPE});
1203 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1205 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1206 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1208 $env_vars->{WINBINDD_TL_PID} = $pid;
1209 write_pid($env_vars, "winbindd", $pid);
1210 print "DONE\n";
1212 unlink($env_vars->{SMBD_TEST_LOG});
1213 print "STARTING SMBD...";
1214 $pid = fork();
1215 if ($pid == 0) {
1216 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
1217 open STDERR, '>&STDOUT';
1219 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1221 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1222 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.smbd";
1223 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1224 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1226 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1227 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1228 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1229 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1230 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1231 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1232 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1233 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1234 } else {
1235 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1237 $ENV{UID_WRAPPER_ROOT} = "1";
1239 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
1241 if ($smbd ne "yes") {
1242 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1243 my $signame = shift;
1244 print("Skip smbd received signal $signame");
1245 exit 0;
1247 sleep($self->{server_maxtime});
1248 exit 0;
1251 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
1252 my @optargs = ("-d0");
1253 if (defined($ENV{SMBD_OPTIONS})) {
1254 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
1256 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1257 if(defined($ENV{SMBD_VALGRIND})) {
1258 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
1260 my @args = ("-F", "--no-process-group",
1261 "-s", $env_vars->{SERVERCONFFILE},
1262 "-l", $env_vars->{LOGDIR});
1263 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
1264 push(@args, "--log-stdout");
1267 close($env_vars->{STDIN_PIPE});
1268 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1270 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1271 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1273 $env_vars->{SMBD_TL_PID} = $pid;
1274 write_pid($env_vars, "smbd", $pid);
1275 print "DONE\n";
1277 close(STDIN_READER);
1279 return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
1282 sub createuser($$$$)
1284 my ($self, $username, $password, $conffile) = @_;
1285 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $username > /dev/null";
1286 unless (open(PWD, "|$cmd")) {
1287 warn("Unable to set password for $username account\n$cmd");
1288 return undef;
1290 print PWD "$password\n$password\n";
1291 unless (close(PWD)) {
1292 warn("Unable to set password for $username account\n$cmd");
1293 return undef;
1297 sub provision($$$$$$$$$)
1299 my ($self, $prefix, $domain, $server, $password, $extra_options, $dc_server_ip, $dc_server_ipv6, $no_delete_prefix) = @_;
1302 ## setup the various environment variables we need
1305 my $swiface = Samba::get_interface($server);
1306 my %ret = ();
1307 my $server_ip = "127.0.0.$swiface";
1308 my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
1310 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
1311 chomp $unix_name;
1312 my $unix_uid = $>;
1313 my $unix_gids_str = $);
1314 my @unix_gids = split(" ", $unix_gids_str);
1316 my $prefix_abs = abs_path($prefix);
1317 my $bindir_abs = abs_path($self->{bindir});
1319 my @dirs = ();
1321 my $shrdir="$prefix_abs/share";
1322 push(@dirs,$shrdir);
1324 my $libdir="$prefix_abs/lib";
1325 push(@dirs,$libdir);
1327 my $piddir="$prefix_abs/pid";
1328 push(@dirs,$piddir);
1330 my $privatedir="$prefix_abs/private";
1331 push(@dirs,$privatedir);
1333 my $lockdir="$prefix_abs/lockdir";
1334 push(@dirs,$lockdir);
1336 my $eventlogdir="$prefix_abs/lockdir/eventlog";
1337 push(@dirs,$eventlogdir);
1339 my $logdir="$prefix_abs/logs";
1340 push(@dirs,$logdir);
1342 my $driver32dir="$shrdir/W32X86";
1343 push(@dirs,$driver32dir);
1345 my $driver64dir="$shrdir/x64";
1346 push(@dirs,$driver64dir);
1348 my $driver40dir="$shrdir/WIN40";
1349 push(@dirs,$driver40dir);
1351 my $ro_shrdir="$shrdir/root-tmp";
1352 push(@dirs,$ro_shrdir);
1354 my $msdfs_shrdir="$shrdir/msdfsshare";
1355 push(@dirs,$msdfs_shrdir);
1357 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
1358 push(@dirs,$msdfs_deeppath);
1360 my $badnames_shrdir="$shrdir/badnames";
1361 push(@dirs,$badnames_shrdir);
1363 my $lease1_shrdir="$shrdir/SMB2_10";
1364 push(@dirs,$lease1_shrdir);
1366 my $lease2_shrdir="$shrdir/SMB3_00";
1367 push(@dirs,$lease2_shrdir);
1369 my $manglenames_shrdir="$shrdir/manglenames";
1370 push(@dirs,$manglenames_shrdir);
1372 my $widelinks_shrdir="$shrdir/widelinks";
1373 push(@dirs,$widelinks_shrdir);
1375 my $widelinks_linkdir="$shrdir/widelinks_foo";
1376 push(@dirs,$widelinks_linkdir);
1378 my $shadow_tstdir="$shrdir/shadow";
1379 push(@dirs,$shadow_tstdir);
1380 my $shadow_mntdir="$shadow_tstdir/mount";
1381 push(@dirs,$shadow_mntdir);
1382 my $shadow_basedir="$shadow_mntdir/base";
1383 push(@dirs,$shadow_basedir);
1384 my $shadow_shrdir="$shadow_basedir/share";
1385 push(@dirs,$shadow_shrdir);
1387 my $nosymlinks_shrdir="$shrdir/nosymlinks";
1388 push(@dirs,$nosymlinks_shrdir);
1390 my $local_symlinks_shrdir="$shrdir/local_symlinks";
1391 push(@dirs,$local_symlinks_shrdir);
1393 # this gets autocreated by winbindd
1394 my $wbsockdir="$prefix_abs/winbindd";
1396 my $nmbdsockdir="$prefix_abs/nmbd";
1397 unlink($nmbdsockdir);
1400 ## create the test directory layout
1402 die ("prefix_abs = ''") if $prefix_abs eq "";
1403 die ("prefix_abs = '/'") if $prefix_abs eq "/";
1405 mkdir($prefix_abs, 0777);
1406 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
1407 if (not defined($no_delete_prefix) or not $no_delete_prefix) {
1408 system("rm -rf $prefix_abs/*");
1410 mkdir($_, 0777) foreach(@dirs);
1412 my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
1415 ## lockdir and piddir must be 0755
1417 chmod 0755, $lockdir;
1418 chmod 0755, $piddir;
1422 ## create ro and msdfs share layout
1425 chmod 0755, $ro_shrdir;
1426 my $unreadable_file = "$ro_shrdir/unreadable_file";
1427 unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
1428 warn("Unable to open $unreadable_file");
1429 return undef;
1431 close(UNREADABLE_FILE);
1432 chmod 0600, $unreadable_file;
1434 my $msdfs_target = "$ro_shrdir/msdfs-target";
1435 unless (open(MSDFS_TARGET, ">$msdfs_target")) {
1436 warn("Unable to open $msdfs_target");
1437 return undef;
1439 close(MSDFS_TARGET);
1440 chmod 0666, $msdfs_target;
1441 symlink "msdfs:$server_ip\\ro-tmp,$server_ipv6\\ro-tmp",
1442 "$msdfs_shrdir/msdfs-src1";
1443 symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
1446 ## create bad names in $badnames_shrdir
1448 ## (An invalid name, would be mangled to 8.3).
1449 my $badname_target = "$badnames_shrdir/\340|\231\216\377\177";
1450 unless (open(BADNAME_TARGET, ">$badname_target")) {
1451 warn("Unable to open $badname_target");
1452 return undef;
1454 close(BADNAME_TARGET);
1455 chmod 0666, $badname_target;
1457 ## (A bad name, would not be mangled to 8.3).
1458 my $badname_target = "$badnames_shrdir/\240\276\346\327\377\177";
1459 unless (open(BADNAME_TARGET, ">$badname_target")) {
1460 warn("Unable to open $badname_target");
1461 return undef;
1463 close(BADNAME_TARGET);
1464 chmod 0666, $badname_target;
1466 ## (A bad good name).
1467 my $badname_target = "$badnames_shrdir/blank.txt";
1468 unless (open(BADNAME_TARGET, ">$badname_target")) {
1469 warn("Unable to open $badname_target");
1470 return undef;
1472 close(BADNAME_TARGET);
1473 chmod 0666, $badname_target;
1476 ## create mangleable directory names in $manglenames_shrdir
1478 my $manglename_target = "$manglenames_shrdir/foo:bar";
1479 mkdir($manglename_target, 0777);
1482 ## create symlinks for widelinks tests.
1484 my $widelinks_target = "$widelinks_linkdir/target";
1485 unless (open(WIDELINKS_TARGET, ">$widelinks_target")) {
1486 warn("Unable to open $widelinks_target");
1487 return undef;
1489 close(WIDELINKS_TARGET);
1490 chmod 0666, $widelinks_target;
1492 ## This link should get ACCESS_DENIED
1494 symlink "$widelinks_target", "$widelinks_shrdir/source";
1496 ## This link should be allowed
1498 symlink "$widelinks_shrdir", "$widelinks_shrdir/dot";
1500 my $conffile="$libdir/server.conf";
1501 my $dfqconffile="$libdir/dfq.conf";
1503 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
1504 my $nss_wrapper_passwd = "$privatedir/passwd";
1505 my $nss_wrapper_group = "$privatedir/group";
1506 my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
1507 my $resolv_conf = "$privatedir/resolv.conf";
1508 my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
1510 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
1512 my $fake_snap_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/fake_snap.pl";
1514 my @eventlog_list = ("dns server", "application");
1517 ## calculate uids and gids
1520 my ($max_uid, $max_gid);
1521 my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
1522 my ($uid_pdbtest_wkn);
1523 my ($uid_smbget);
1524 my ($uid_force_user);
1525 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
1526 my ($gid_userdup, $gid_everyone);
1527 my ($gid_force_user);
1528 my ($uid_user1);
1529 my ($uid_user2);
1531 if ($unix_uid < 0xffff - 10) {
1532 $max_uid = 0xffff;
1533 } else {
1534 $max_uid = $unix_uid;
1537 $uid_root = $max_uid - 1;
1538 $uid_nobody = $max_uid - 2;
1539 $uid_pdbtest = $max_uid - 3;
1540 $uid_pdbtest2 = $max_uid - 4;
1541 $uid_userdup = $max_uid - 5;
1542 $uid_pdbtest_wkn = $max_uid - 6;
1543 $uid_force_user = $max_uid - 7;
1544 $uid_smbget = $max_uid - 8;
1545 $uid_user1 = $max_uid - 9;
1546 $uid_user2 = $max_uid - 10;
1548 if ($unix_gids[0] < 0xffff - 8) {
1549 $max_gid = 0xffff;
1550 } else {
1551 $max_gid = $unix_gids[0];
1554 $gid_nobody = $max_gid - 1;
1555 $gid_nogroup = $max_gid - 2;
1556 $gid_root = $max_gid - 3;
1557 $gid_domusers = $max_gid - 4;
1558 $gid_domadmins = $max_gid - 5;
1559 $gid_userdup = $max_gid - 6;
1560 $gid_everyone = $max_gid - 7;
1561 $gid_force_user = $max_gid - 8;
1564 ## create conffile
1567 unless (open(CONF, ">$conffile")) {
1568 warn("Unable to open $conffile");
1569 return undef;
1571 print CONF "
1572 [global]
1573 netbios name = $server
1574 interfaces = $server_ip/8 $server_ipv6/64
1575 bind interfaces only = yes
1576 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
1577 smbd:suicide mode = yes
1579 workgroup = $domain
1581 private dir = $privatedir
1582 pid directory = $piddir
1583 lock directory = $lockdir
1584 log file = $logdir/log.\%m
1585 log level = 1
1586 debug pid = yes
1587 max log size = 0
1589 state directory = $lockdir
1590 cache directory = $lockdir
1592 passdb backend = tdbsam
1594 time server = yes
1596 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1597 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
1598 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1599 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
1600 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1601 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1602 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
1604 addprinter command = $mod_printer_pl -a -s $conffile --
1605 deleteprinter command = $mod_printer_pl -d -s $conffile --
1607 eventlog list = application \"dns server\"
1609 kernel oplocks = no
1610 kernel change notify = no
1612 logging = file
1613 printing = bsd
1614 printcap name = /dev/null
1616 winbindd socket directory = $wbsockdir
1617 nmbd:socket dir = $nmbdsockdir
1618 idmap config * : range = 100000-200000
1619 winbind enum users = yes
1620 winbind enum groups = yes
1621 winbind separator = /
1622 include system krb5 conf = no
1624 # min receivefile size = 4000
1626 read only = no
1628 smbd:sharedelay = 100000
1629 smbd:writetimeupdatedelay = 500000
1630 map hidden = no
1631 map system = no
1632 map readonly = no
1633 store dos attributes = yes
1634 create mask = 755
1635 dos filemode = yes
1636 strict rename = yes
1637 strict sync = yes
1638 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1640 printing = vlp
1641 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1642 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1643 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1644 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1645 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1646 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1647 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1648 lpq cache time = 0
1649 print notify backchannel = yes
1651 ncalrpc dir = $prefix_abs/ncalrpc
1653 # The samba3.blackbox.smbclient_s3 test uses this to test that
1654 # sending messages works, and that the %m sub works.
1655 message command = mv %s $shrdir/message.%m
1657 # fsrvp server requires registry shares
1658 registry shares = yes
1660 # Used by RPC SRVSVC tests
1661 add share command = $bindir_abs/smbaddshare
1662 change share command = $bindir_abs/smbchangeshare
1663 delete share command = $bindir_abs/smbdeleteshare
1665 # fruit:copyfile is a global option
1666 fruit:copyfile = yes
1668 #this does not mean that we use non-secure test env,
1669 #it just means we ALLOW one to be configured.
1670 allow insecure wide links = yes
1672 # Begin extra options
1673 $extra_options
1674 # End extra options
1676 #Include user defined custom parameters if set
1679 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1680 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1683 print CONF "
1684 [tmp]
1685 path = $shrdir
1686 comment = smb username is [%U]
1687 [tmpsort]
1688 path = $shrdir
1689 comment = Load dirsort module
1690 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1691 [tmpenc]
1692 path = $shrdir
1693 comment = encrypt smb username is [%U]
1694 smb encrypt = required
1695 vfs objects = dirsort
1696 [tmpguest]
1697 path = $shrdir
1698 guest ok = yes
1699 [guestonly]
1700 path = $shrdir
1701 guest only = yes
1702 guest ok = yes
1703 [forceuser]
1704 path = $shrdir
1705 force user = $unix_name
1706 guest ok = yes
1707 [forceuser_unixonly]
1708 comment = force a user with unix user SID and group SID
1709 path = $shrdir
1710 force user = pdbtest
1711 guest ok = yes
1712 [forceuser_wkngroup]
1713 comment = force a user with well-known group SID
1714 path = $shrdir
1715 force user = pdbtest_wkn
1716 guest ok = yes
1717 [forcegroup]
1718 path = $shrdir
1719 force group = nogroup
1720 guest ok = yes
1721 [ro-tmp]
1722 path = $ro_shrdir
1723 guest ok = yes
1724 [write-list-tmp]
1725 path = $shrdir
1726 read only = yes
1727 write list = $unix_name
1728 [valid-users-tmp]
1729 path = $shrdir
1730 valid users = $unix_name
1731 access based share enum = yes
1732 [msdfs-share]
1733 path = $msdfs_shrdir
1734 msdfs root = yes
1735 msdfs shuffle referrals = yes
1736 guest ok = yes
1737 [hideunread]
1738 copy = tmp
1739 hide unreadable = yes
1740 [tmpcase]
1741 copy = tmp
1742 case sensitive = yes
1743 [hideunwrite]
1744 copy = tmp
1745 hide unwriteable files = yes
1746 [durable]
1747 copy = tmp
1748 kernel share modes = no
1749 kernel oplocks = no
1750 posix locking = no
1751 [fs_specific]
1752 copy = tmp
1753 $fs_specific_conf
1754 [print1]
1755 copy = tmp
1756 printable = yes
1758 [print2]
1759 copy = print1
1760 [print3]
1761 copy = print1
1762 default devmode = no
1763 [lp]
1764 copy = print1
1766 [nfs4acl_simple]
1767 path = $shrdir
1768 comment = smb username is [%U]
1769 nfs4:mode = simple
1770 vfs objects = nfs4acl_xattr xattr_tdb
1772 [nfs4acl_special]
1773 path = $shrdir
1774 comment = smb username is [%U]
1775 nfs4:mode = special
1776 vfs objects = nfs4acl_xattr xattr_tdb
1778 [xcopy_share]
1779 path = $shrdir
1780 comment = smb username is [%U]
1781 create mask = 777
1782 force create mode = 777
1783 [posix_share]
1784 path = $shrdir
1785 comment = smb username is [%U]
1786 create mask = 0777
1787 force create mode = 0
1788 directory mask = 0777
1789 force directory mode = 0
1790 vfs objects = xattr_tdb streams_depot
1791 [aio]
1792 copy = tmp
1793 aio read size = 1
1794 aio write size = 1
1796 [print\$]
1797 copy = tmp
1799 [vfs_fruit]
1800 path = $shrdir
1801 vfs objects = catia fruit streams_xattr acl_xattr
1802 fruit:resource = file
1803 fruit:metadata = netatalk
1804 fruit:locking = netatalk
1805 fruit:encoding = native
1807 [vfs_fruit_metadata_stream]
1808 path = $shrdir
1809 vfs objects = fruit streams_xattr acl_xattr
1810 fruit:resource = file
1811 fruit:metadata = stream
1813 [vfs_fruit_stream_depot]
1814 path = $shrdir
1815 vfs objects = fruit streams_depot acl_xattr
1816 fruit:resource = stream
1817 fruit:metadata = stream
1819 [vfs_wo_fruit]
1820 path = $shrdir
1821 vfs objects = streams_xattr acl_xattr
1823 [vfs_wo_fruit_stream_depot]
1824 path = $shrdir
1825 vfs objects = streams_depot acl_xattr
1827 [badname-tmp]
1828 path = $badnames_shrdir
1829 guest ok = yes
1831 [manglenames_share]
1832 path = $manglenames_shrdir
1833 guest ok = yes
1835 [dynamic_share]
1836 path = $shrdir/%R
1837 guest ok = yes
1839 [widelinks_share]
1840 path = $widelinks_shrdir
1841 wide links = no
1842 guest ok = yes
1844 [fsrvp_share]
1845 path = $shrdir
1846 comment = fake shapshots using rsync
1847 vfs objects = shell_snap shadow_copy2
1848 shell_snap:check path command = $fake_snap_pl --check
1849 shell_snap:create command = $fake_snap_pl --create
1850 shell_snap:delete command = $fake_snap_pl --delete
1851 # a relative path here fails, the snapshot dir is no longer found
1852 shadow:snapdir = $shrdir/.snapshots
1854 [shadow1]
1855 path = $shadow_shrdir
1856 comment = previous versions snapshots under mount point
1857 vfs objects = shadow_copy2
1858 shadow:mountpoint = $shadow_mntdir
1860 [shadow2]
1861 path = $shadow_shrdir
1862 comment = previous versions snapshots outside mount point
1863 vfs objects = shadow_copy2
1864 shadow:mountpoint = $shadow_mntdir
1865 shadow:snapdir = $shadow_tstdir/.snapshots
1867 [shadow3]
1868 path = $shadow_shrdir
1869 comment = previous versions with subvolume snapshots, snapshots under base dir
1870 vfs objects = shadow_copy2
1871 shadow:mountpoint = $shadow_mntdir
1872 shadow:basedir = $shadow_basedir
1873 shadow:snapdir = $shadow_basedir/.snapshots
1875 [shadow4]
1876 path = $shadow_shrdir
1877 comment = previous versions with subvolume snapshots, snapshots outside mount point
1878 vfs objects = shadow_copy2
1879 shadow:mountpoint = $shadow_mntdir
1880 shadow:basedir = $shadow_basedir
1881 shadow:snapdir = $shadow_tstdir/.snapshots
1883 [shadow5]
1884 path = $shadow_shrdir
1885 comment = previous versions at volume root snapshots under mount point
1886 vfs objects = shadow_copy2
1887 shadow:mountpoint = $shadow_shrdir
1889 [shadow6]
1890 path = $shadow_shrdir
1891 comment = previous versions at volume root snapshots outside mount point
1892 vfs objects = shadow_copy2
1893 shadow:mountpoint = $shadow_shrdir
1894 shadow:snapdir = $shadow_tstdir/.snapshots
1896 [shadow7]
1897 path = $shadow_shrdir
1898 comment = previous versions snapshots everywhere
1899 vfs objects = shadow_copy2
1900 shadow:mountpoint = $shadow_mntdir
1901 shadow:snapdirseverywhere = yes
1903 [shadow8]
1904 path = $shadow_shrdir
1905 comment = previous versions using snapsharepath
1906 vfs objects = shadow_copy2
1907 shadow:mountpoint = $shadow_mntdir
1908 shadow:snapdir = $shadow_tstdir/.snapshots
1909 shadow:snapsharepath = share
1911 [shadow_fmt0]
1912 comment = Testing shadow:format with default option
1913 vfs object = shadow_copy2
1914 path = $shadow_shrdir
1915 read only = no
1916 guest ok = yes
1917 shadow:mountpoint = $shadow_mntdir
1918 shadow:basedir = $shadow_basedir
1919 shadow:snapdir = $shadow_basedir/.snapshots
1920 shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
1922 [shadow_fmt1]
1923 comment = Testing shadow:format with only date component
1924 vfs object = shadow_copy2
1925 path = $shadow_shrdir
1926 read only = no
1927 guest ok = yes
1928 shadow:mountpoint = $shadow_mntdir
1929 shadow:basedir = $shadow_basedir
1930 shadow:snapdir = $shadow_basedir/.snapshots
1931 shadow:format = \@GMT-%Y-%m-%d
1933 [shadow_fmt2]
1934 comment = Testing shadow:format with some hardcoded prefix
1935 vfs object = shadow_copy2
1936 path = $shadow_shrdir
1937 read only = no
1938 guest ok = yes
1939 shadow:mountpoint = $shadow_mntdir
1940 shadow:basedir = $shadow_basedir
1941 shadow:snapdir = $shadow_basedir/.snapshots
1942 shadow:format = snap\@GMT-%Y.%m.%d-%H.%M.%S
1944 [shadow_fmt3]
1945 comment = Testing shadow:format with modified format
1946 vfs object = shadow_copy2
1947 path = $shadow_shrdir
1948 read only = no
1949 guest ok = yes
1950 shadow:mountpoint = $shadow_mntdir
1951 shadow:basedir = $shadow_basedir
1952 shadow:snapdir = $shadow_basedir/.snapshots
1953 shadow:format = \@GMT-%Y.%m.%d-%H_%M_%S-snap
1955 [shadow_fmt4]
1956 comment = Testing shadow:snapprefix regex
1957 vfs object = shadow_copy2
1958 path = $shadow_shrdir
1959 read only = no
1960 guest ok = yes
1961 shadow:mountpoint = $shadow_mntdir
1962 shadow:basedir = $shadow_basedir
1963 shadow:snapdir = $shadow_basedir/.snapshots
1964 shadow:snapprefix = \^s[a-z]*p\$
1965 shadow:format = _GMT-%Y.%m.%d-%H.%M.%S
1967 [shadow_fmt5]
1968 comment = Testing shadow:snapprefix with delim regex
1969 vfs object = shadow_copy2
1970 path = $shadow_shrdir
1971 read only = no
1972 guest ok = yes
1973 shadow:mountpoint = $shadow_mntdir
1974 shadow:basedir = $shadow_basedir
1975 shadow:snapdir = $shadow_basedir/.snapshots
1976 shadow:delimiter = \@GMT
1977 shadow:snapprefix = [a-z]*
1978 shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
1980 [shadow_wl]
1981 path = $shadow_shrdir
1982 comment = previous versions with wide links allowed
1983 vfs objects = shadow_copy2
1984 shadow:mountpoint = $shadow_mntdir
1985 wide links = yes
1986 [dfq]
1987 path = $shrdir/dfree
1988 vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
1989 admin users = $unix_name
1990 include = $dfqconffile
1991 [dfq_owner]
1992 path = $shrdir/dfree
1993 vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
1994 inherit owner = yes
1995 include = $dfqconffile
1996 [acl_xattr_ign_sysacl_posix]
1997 copy = tmp
1998 acl_xattr:ignore system acls = yes
1999 acl_xattr:default acl style = posix
2000 [acl_xattr_ign_sysacl_windows]
2001 copy = tmp
2002 acl_xattr:ignore system acls = yes
2003 acl_xattr:default acl style = windows
2005 [mangle_illegal]
2006 copy = tmp
2007 mangled names = illegal
2009 [nosymlinks]
2010 copy = tmp
2011 path = $nosymlinks_shrdir
2012 follow symlinks = no
2014 [local_symlinks]
2015 copy = tmp
2016 path = $local_symlinks_shrdir
2017 follow symlinks = yes
2019 [kernel_oplocks]
2020 copy = tmp
2021 kernel oplocks = yes
2022 vfs objects = streams_xattr xattr_tdb
2024 [compound_find]
2025 copy = tmp
2026 smbd:find async delay usec = 10000
2028 close(CONF);
2030 unless (open(DFQCONF, ">$dfqconffile")) {
2031 warn("Unable to open $dfqconffile");
2032 return undef;
2034 close(DFQCONF);
2037 ## create a test account
2040 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
2041 warn("Unable to open $nss_wrapper_passwd");
2042 return undef;
2044 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
2045 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
2046 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
2047 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
2048 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
2049 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
2050 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
2051 smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
2052 user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
2053 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
2055 if ($unix_uid != 0) {
2056 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
2059 close(PASSWD);
2061 unless (open(GROUP, ">$nss_wrapper_group")) {
2062 warn("Unable to open $nss_wrapper_group");
2063 return undef;
2065 print GROUP "nobody:x:$gid_nobody:
2066 nogroup:x:$gid_nogroup:nobody
2067 $unix_name-group:x:$unix_gids[0]:
2068 domusers:X:$gid_domusers:
2069 domadmins:X:$gid_domadmins:
2070 userdup:x:$gid_userdup:$unix_name
2071 everyone:x:$gid_everyone:
2072 force_user:x:$gid_force_user:
2074 if ($unix_gids[0] != 0) {
2075 print GROUP "root:x:$gid_root:
2079 close(GROUP);
2081 ## hosts
2082 my $hostname = lc($server);
2083 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
2084 warn("Unable to open $nss_wrapper_hosts");
2085 return undef;
2087 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n";
2088 print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n";
2089 close(HOSTS);
2091 ## hosts
2092 unless (open(RESOLV_CONF, ">$resolv_conf")) {
2093 warn("Unable to open $resolv_conf");
2094 return undef;
2096 if (defined($dc_server_ip) or defined($dc_server_ipv6)) {
2097 if (defined($dc_server_ip)) {
2098 print RESOLV_CONF "nameserver $dc_server_ip\n";
2100 if (defined($dc_server_ipv6)) {
2101 print RESOLV_CONF "nameserver $dc_server_ipv6\n";
2103 } else {
2104 print RESOLV_CONF "nameserver ${server_ip}\n";
2105 print RESOLV_CONF "nameserver ${server_ipv6}\n";
2107 close(RESOLV_CONF);
2109 foreach my $evlog (@eventlog_list) {
2110 my $evlogtdb = "$eventlogdir/$evlog.tdb";
2111 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
2112 close(EVENTLOG);
2115 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
2116 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
2117 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
2118 $ENV{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
2119 if ($ENV{SAMBA_DNS_FAKING}) {
2120 $ENV{RESOLV_WRAPPER_CONF} = $resolv_conf;
2121 } else {
2122 $ENV{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
2125 createuser($self, $unix_name, $password, $conffile) || die("Unable to create user");
2126 createuser($self, "force_user", $password, $conffile) || die("Unable to create force_user");
2127 createuser($self, "smbget_user", $password, $conffile) || die("Unable to create smbget_user");
2128 createuser($self, "user1", $password, $conffile) || die("Unable to create user1");
2129 createuser($self, "user2", $password, $conffile) || die("Unable to create user2");
2131 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
2132 print DNS_UPDATE_LIST "A $server. $server_ip\n";
2133 print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
2134 close(DNS_UPDATE_LIST);
2136 print "DONE\n";
2138 $ret{SERVER_IP} = $server_ip;
2139 $ret{SERVER_IPV6} = $server_ipv6;
2140 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
2141 $ret{NMBD_TEST_LOG_POS} = 0;
2142 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
2143 $ret{WINBINDD_TEST_LOG_POS} = 0;
2144 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
2145 $ret{SMBD_TEST_LOG_POS} = 0;
2146 $ret{SERVERCONFFILE} = $conffile;
2147 $ret{CONFIGURATION} ="-s $conffile";
2148 $ret{LOCK_DIR} = $lockdir;
2149 $ret{SERVER} = $server;
2150 $ret{USERNAME} = $unix_name;
2151 $ret{USERID} = $unix_uid;
2152 $ret{DOMAIN} = $domain;
2153 $ret{NETBIOSNAME} = $server;
2154 $ret{PASSWORD} = $password;
2155 $ret{PIDDIR} = $piddir;
2156 $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
2157 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
2158 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
2159 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
2160 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
2161 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
2162 $ret{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
2163 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
2164 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
2165 if ($ENV{SAMBA_DNS_FAKING}) {
2166 $ret{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
2167 } else {
2168 $ret{RESOLV_WRAPPER_CONF} = $resolv_conf;
2170 $ret{LOCAL_PATH} = "$shrdir";
2171 $ret{LOGDIR} = $logdir;
2174 # Avoid hitting system krb5.conf -
2175 # An env that needs Kerberos will reset this to the real
2176 # value.
2178 $ret{KRB5_CONFIG} = abs_path($prefix) . "/no_krb5.conf";
2180 # Define KRB5CCNAME for each environment we set up
2181 $ret{KRB5_CCACHE} = abs_path($prefix) . "/krb5ccache";
2182 $ENV{KRB5CCNAME} = $ret{KRB5_CCACHE};
2184 return \%ret;
2187 sub wait_for_start($$$$$)
2189 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
2190 my $ret;
2192 if ($nmbd eq "yes") {
2193 my $count = 0;
2195 # give time for nbt server to register its names
2196 print "checking for nmbd\n";
2198 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
2199 my $nmblookup = Samba::bindir_path($self, "nmblookup");
2201 do {
2202 $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
2203 if ($ret != 0) {
2204 sleep(1);
2205 } else {
2206 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
2207 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
2208 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
2209 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
2211 $count++;
2212 } while ($ret != 0 && $count < 10);
2213 if ($count == 10) {
2214 print "NMBD not reachable after 10 retries\n";
2215 teardown_env($self, $envvars);
2216 return 0;
2220 if ($winbindd eq "yes") {
2221 print "checking for winbindd\n";
2222 my $count = 0;
2223 do {
2224 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --ping-dc");
2225 if ($ret != 0) {
2226 sleep(1);
2228 $count++;
2229 } while ($ret != 0 && $count < 20);
2230 if ($count == 20) {
2231 print "WINBINDD not reachable after 20 seconds\n";
2232 teardown_env($self, $envvars);
2233 return 0;
2237 if ($smbd eq "yes") {
2238 # make sure smbd is also up set
2239 print "wait for smbd\n";
2241 my $count = 0;
2242 do {
2243 $ret = system(Samba::bindir_path($self, "smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
2244 if ($ret != 0) {
2245 sleep(1);
2247 $count++
2248 } while ($ret != 0 && $count < 20);
2249 if ($count == 20) {
2250 print "SMBD failed to start up in a reasonable time (20sec)\n";
2251 teardown_env($self, $envvars);
2252 return 0;
2256 # Ensure we have domain users mapped.
2257 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
2258 if ($ret != 0) {
2259 return 1;
2261 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
2262 if ($ret != 0) {
2263 return 1;
2265 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add sid=S-1-1-0 unixgroup=everyone type=builtin");
2266 if ($ret != 0) {
2267 return 1;
2270 if ($winbindd eq "yes") {
2271 # note: creating builtin groups requires winbindd for the
2272 # unix id allocator
2273 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
2274 if ($ret != 0) {
2275 print "Failed to create BUILTIN\\Users group\n";
2276 return 0;
2278 my $count = 0;
2279 do {
2280 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache del IDMAP/SID2XID/S-1-5-32-545");
2281 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
2282 if ($ret != 0) {
2283 sleep(2);
2285 $count++;
2286 } while ($ret != 0 && $count < 10);
2287 if ($count == 10) {
2288 print "WINBINDD not reachable after 20 seconds\n";
2289 teardown_env($self, $envvars);
2290 return 0;
2294 print $self->getlog_env($envvars);
2296 return 1;