python: Make generated modules samba.ntstatus and samba.werror Python 3 compatible.
[Samba.git] / selftest / target / Samba3.pm
blob54da52b7fa22612ada1fba7965f604ce6213068f
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_ad_member_idmap_ad($$$$)
694 my ($self, $prefix, $dcvars) = @_;
696 # If we didn't build with ADS, pretend this env was never available
697 if (not $self->have_ads()) {
698 return "UNKNOWN";
701 print "PROVISIONING S3 AD MEMBER WITH idmap_ad config...";
703 my $member_options = "
704 security = ads
705 workgroup = $dcvars->{DOMAIN}
706 realm = $dcvars->{REALM}
707 password server = $dcvars->{SERVER}
708 idmap config * : backend = tdb
709 idmap config * : range = 1000000-1999999
710 idmap config $dcvars->{DOMAIN} : backend = ad
711 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
714 my $ret = $self->provision($prefix, $dcvars->{DOMAIN},
715 "IDMAPADMEMBER",
716 "loCalMemberPass",
717 $member_options,
718 $dcvars->{SERVER_IP},
719 $dcvars->{SERVER_IPV6});
721 $ret or return undef;
723 close(USERMAP);
724 $ret->{DOMAIN} = $dcvars->{DOMAIN};
725 $ret->{REALM} = $dcvars->{REALM};
727 my $ctx;
728 my $prefix_abs = abs_path($prefix);
729 $ctx = {};
730 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
731 $ctx->{domain} = $dcvars->{DOMAIN};
732 $ctx->{realm} = $dcvars->{REALM};
733 $ctx->{dnsname} = lc($dcvars->{REALM});
734 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
735 $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
736 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
737 Samba::mk_krb5_conf($ctx, "");
739 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
741 my $net = Samba::bindir_path($self, "net");
742 my $cmd = "";
743 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
744 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
745 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
746 } else {
747 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
749 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
750 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=\"$ret->{SELFTEST_WINBINDD_SOCKET_DIR}\" ";
751 $cmd .= "$net join $ret->{CONFIGURATION}";
752 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
754 if (system($cmd) != 0) {
755 warn("Join failed\n$cmd");
756 return undef;
759 # We need world access to this share, as otherwise the domain
760 # administrator from the AD domain provided by Samba4 can't
761 # access the share for tests.
762 chmod 0777, "$prefix/share";
764 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
765 return undef;
768 $ret->{DC_SERVER} = $dcvars->{SERVER};
769 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
770 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
771 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
772 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
773 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
775 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
776 $ret->{target} = $self;
778 return $ret;
781 sub setup_simpleserver($$)
783 my ($self, $path) = @_;
785 print "PROVISIONING simple server...";
787 my $prefix_abs = abs_path($path);
789 my $simpleserver_options = "
790 lanman auth = yes
791 ntlm auth = yes
792 vfs objects = xattr_tdb streams_depot time_audit full_audit
793 change notify = no
794 smb encrypt = off
796 full_audit:syslog = no
797 full_audit:success = none
798 full_audit:failure = none
800 [vfs_aio_fork]
801 path = $prefix_abs/share
802 vfs objects = aio_fork
803 read only = no
804 vfs_aio_fork:erratic_testing_mode=yes
806 [dosmode]
807 path = $prefix_abs/share
808 vfs objects =
809 store dos attributes = yes
810 hide files = /hidefile/
811 hide dot files = yes
813 [enc_desired]
814 path = $prefix_abs/share
815 vfs objects =
816 smb encrypt = desired
819 my $vars = $self->provision($path, "WORKGROUP",
820 "LOCALSHARE4",
821 "local4pass",
822 $simpleserver_options);
824 $vars or return undef;
826 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
827 return undef;
830 $self->{vars}->{simpleserver} = $vars;
832 return $vars;
835 sub setup_fileserver($$)
837 my ($self, $path) = @_;
838 my $prefix_abs = abs_path($path);
839 my $srcdir_abs = abs_path($self->{srcdir});
841 print "PROVISIONING file server ...\n";
843 my @dirs = ();
845 mkdir($prefix_abs, 0777);
847 my $usershare_dir="$prefix_abs/lib/usershare";
849 mkdir("$prefix_abs/lib", 0755);
850 remove_tree($usershare_dir);
851 mkdir($usershare_dir, 01770);
853 my $share_dir="$prefix_abs/share";
855 # Create share directory structure
856 my $lower_case_share_dir="$share_dir/lower-case";
857 push(@dirs, $lower_case_share_dir);
859 my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
860 push(@dirs, $lower_case_share_dir_30000);
862 my $dfree_share_dir="$share_dir/dfree";
863 push(@dirs, $dfree_share_dir);
864 push(@dirs, "$dfree_share_dir/subdir1");
865 push(@dirs, "$dfree_share_dir/subdir2");
866 push(@dirs, "$dfree_share_dir/subdir3");
868 my $valid_users_sharedir="$share_dir/valid_users";
869 push(@dirs,$valid_users_sharedir);
871 my $offline_sharedir="$share_dir/offline";
872 push(@dirs,$offline_sharedir);
874 my $force_user_valid_users_dir = "$share_dir/force_user_valid_users";
875 push(@dirs, $force_user_valid_users_dir);
877 my $smbget_sharedir="$share_dir/smbget";
878 push(@dirs,$smbget_sharedir);
880 my $tarmode_sharedir="$share_dir/tarmode";
881 push(@dirs,$tarmode_sharedir);
883 my $usershare_sharedir="$share_dir/usershares";
884 push(@dirs,$usershare_sharedir);
886 my $fileserver_options = "
887 usershare path = $usershare_dir
888 usershare max shares = 10
889 usershare allow guests = yes
890 usershare prefix allow list = $usershare_sharedir
892 [lowercase]
893 path = $lower_case_share_dir
894 comment = smb username is [%U]
895 case sensitive = True
896 default case = lower
897 preserve case = no
898 short preserve case = no
899 [lowercase-30000]
900 path = $lower_case_share_dir_30000
901 comment = smb username is [%U]
902 case sensitive = True
903 default case = lower
904 preserve case = no
905 short preserve case = no
906 [dfree]
907 path = $dfree_share_dir
908 comment = smb username is [%U]
909 dfree command = $srcdir_abs/testprogs/blackbox/dfree.sh
910 [valid-users-access]
911 path = $valid_users_sharedir
912 valid users = +userdup
913 [offline]
914 path = $offline_sharedir
915 vfs objects = offline
917 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=9878
918 # RH BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1077651
919 [force_user_valid_users]
920 path = $force_user_valid_users_dir
921 comment = force user with valid users combination test share
922 valid users = +force_user
923 force user = force_user
924 force group = everyone
925 write list = force_user
927 [smbget]
928 path = $smbget_sharedir
929 comment = smb username is [%U]
930 guest ok = yes
931 [ign_sysacls]
932 path = $share_dir
933 comment = ignore system acls
934 acl_xattr:ignore system acls = yes
935 [inherit_owner]
936 path = $share_dir
937 comment = inherit owner
938 inherit owner = yes
939 [inherit_owner_u]
940 path = $share_dir
941 comment = inherit only unix owner
942 inherit owner = unix only
943 acl_xattr:ignore system acls = yes
946 my $vars = $self->provision($path, "WORKGROUP",
947 "FILESERVER",
948 "fileserver",
949 $fileserver_options,
950 undef,
951 undef,
954 $vars or return undef;
956 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
957 return undef;
960 $self->{vars}->{fileserver} = $vars;
962 mkdir($_, 0777) foreach(@dirs);
964 ## Create case sensitive lower case share dir
965 foreach my $file ('a'..'z') {
966 my $full_path = $lower_case_share_dir . '/' . $file;
967 open my $fh, '>', $full_path;
968 # Add some content to file
969 print $fh $full_path;
970 close $fh;
973 for (my $file = 1; $file < 51; ++$file) {
974 my $full_path = $lower_case_share_dir . '/' . $file;
975 open my $fh, '>', $full_path;
976 # Add some content to file
977 print $fh $full_path;
978 close $fh;
981 # Create content for 30000 share
982 foreach my $file ('a'..'z') {
983 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
984 open my $fh, '>', $full_path;
985 # Add some content to file
986 print $fh $full_path;
987 close $fh;
990 for (my $file = 1; $file < 30001; ++$file) {
991 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
992 open my $fh, '>', $full_path;
993 # Add some content to file
994 print $fh $full_path;
995 close $fh;
999 ## create a listable file in valid_users_share
1001 my $valid_users_target = "$valid_users_sharedir/foo";
1002 unless (open(VALID_USERS_TARGET, ">$valid_users_target")) {
1003 warn("Unable to open $valid_users_target");
1004 return undef;
1006 close(VALID_USERS_TARGET);
1007 chmod 0644, $valid_users_target;
1009 return $vars;
1012 sub setup_ktest($$$)
1014 my ($self, $prefix) = @_;
1016 # If we didn't build with ADS, pretend this env was never available
1017 if (not $self->have_ads()) {
1018 return "UNKNOWN";
1021 print "PROVISIONING server with security=ads...";
1023 my $ktest_options = "
1024 workgroup = KTEST
1025 realm = ktest.samba.example.com
1026 security = ads
1027 username map = $prefix/lib/username.map
1028 server signing = required
1029 server min protocol = SMB3_00
1030 client max protocol = SMB3
1032 # This disables NTLM auth against the local SAM, which
1033 # we use can then test this setting by.
1034 ntlm auth = disabled
1037 my $ret = $self->provision($prefix, "KTEST",
1038 "LOCALKTEST6",
1039 "localktest6pass",
1040 $ktest_options);
1042 $ret or return undef;
1044 my $ctx;
1045 my $prefix_abs = abs_path($prefix);
1046 $ctx = {};
1047 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
1048 $ctx->{domain} = "KTEST";
1049 $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
1050 $ctx->{dnsname} = lc($ctx->{realm});
1051 $ctx->{kdc_ipv4} = "0.0.0.0";
1052 $ctx->{kdc_ipv6} = "::";
1053 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
1054 Samba::mk_krb5_conf($ctx, "");
1056 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
1058 open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
1059 print USERMAP "
1060 $ret->{USERNAME} = KTEST\\Administrator
1062 close(USERMAP);
1064 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
1065 #Samba4 DC with the same parameters as are being used here. The
1066 #domain SID is S-1-5-21-1071277805-689288055-3486227160
1068 system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
1069 chmod 0600, "$prefix/private/secrets.tdb";
1071 #Make sure there's no old ntdb file.
1072 system("rm -f $prefix/private/secrets.ntdb");
1074 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
1075 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
1077 #and having in krb5.conf:
1078 # ticket_lifetime = 799718400
1079 # renew_lifetime = 799718400
1081 # The commands for the -2 keytab where were:
1082 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
1083 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
1084 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
1085 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
1086 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
1088 # and then for the -3 keytab, I did
1090 # net changetrustpw; kdestroy and the same again.
1092 # This creates a credential cache with a very long lifetime (2036 at
1093 # at 2011-04), and shows that running 'net changetrustpw' does not
1094 # break existing logins (for the secrets.tdb method at least).
1097 $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
1099 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
1100 chmod 0600, "$prefix/krb5_ccache-2";
1102 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
1103 chmod 0600, "$prefix/krb5_ccache-3";
1105 # We need world access to this share, as otherwise the domain
1106 # administrator from the AD domain provided by ktest can't
1107 # access the share for tests.
1108 chmod 0777, "$prefix/share";
1110 if (not $self->check_or_start($ret, "yes", "no", "yes")) {
1111 return undef;
1113 return $ret;
1116 sub setup_maptoguest($$)
1118 my ($self, $path) = @_;
1120 print "PROVISIONING maptoguest...";
1122 my $options = "
1123 map to guest = bad user
1124 ntlm auth = yes
1127 my $vars = $self->provision($path, "WORKGROUP",
1128 "maptoguest",
1129 "maptoguestpass",
1130 $options);
1132 $vars or return undef;
1134 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
1135 return undef;
1138 $self->{vars}->{s3maptoguest} = $vars;
1140 return $vars;
1143 sub stop_sig_term($$) {
1144 my ($self, $pid) = @_;
1145 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1148 sub stop_sig_kill($$) {
1149 my ($self, $pid) = @_;
1150 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
1153 sub write_pid($$$)
1155 my ($env_vars, $app, $pid) = @_;
1157 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
1158 print PID $pid;
1159 close(PID);
1162 sub read_pid($$)
1164 my ($env_vars, $app) = @_;
1166 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
1167 my $pid = <PID>;
1168 close(PID);
1169 return $pid;
1172 sub check_or_start($$$$$) {
1173 my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
1175 # use a pipe for stdin in the child processes. This allows
1176 # those processes to monitor the pipe for EOF to ensure they
1177 # exit when the test script exits
1178 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
1180 unlink($env_vars->{NMBD_TEST_LOG});
1181 print "STARTING NMBD...";
1182 my $pid = fork();
1183 if ($pid == 0) {
1184 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
1185 open STDERR, '>&STDOUT';
1187 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1189 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1190 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.nmbd";
1191 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1192 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1194 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1195 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1196 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1197 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1198 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1199 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1200 $ENV{UID_WRAPPER_ROOT} = "1";
1202 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
1204 if ($nmbd ne "yes") {
1205 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1206 my $signame = shift;
1207 print("Skip nmbd received signal $signame");
1208 exit 0;
1210 sleep($self->{server_maxtime});
1211 exit 0;
1214 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
1215 my @optargs = ("-d0");
1216 if (defined($ENV{NMBD_OPTIONS})) {
1217 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
1219 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1220 if(defined($ENV{NMBD_VALGRIND})) {
1221 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
1223 my @args = ("-F", "--no-process-group",
1224 "-s", $env_vars->{SERVERCONFFILE},
1225 "-l", $env_vars->{LOGDIR});
1226 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
1227 push(@args, "--log-stdout");
1230 close($env_vars->{STDIN_PIPE});
1231 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1233 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1234 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1236 $env_vars->{NMBD_TL_PID} = $pid;
1237 write_pid($env_vars, "nmbd", $pid);
1238 print "DONE\n";
1240 unlink($env_vars->{WINBINDD_TEST_LOG});
1241 print "STARTING WINBINDD...";
1242 $pid = fork();
1243 if ($pid == 0) {
1244 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
1245 open STDERR, '>&STDOUT';
1247 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1249 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1250 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.winbindd";
1251 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1252 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1254 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1255 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1256 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1257 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1258 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1259 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1260 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1261 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1262 } else {
1263 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1265 $ENV{UID_WRAPPER_ROOT} = "1";
1267 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
1269 if ($winbindd ne "yes") {
1270 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1271 my $signame = shift;
1272 print("Skip winbindd received signal $signame");
1273 exit 0;
1275 sleep($self->{server_maxtime});
1276 exit 0;
1279 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
1280 my @optargs = ("-d0");
1281 if (defined($ENV{WINBINDD_OPTIONS})) {
1282 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
1284 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1285 if(defined($ENV{WINBINDD_VALGRIND})) {
1286 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
1288 my @args = ("-F", "--no-process-group",
1289 "-s", $env_vars->{SERVERCONFFILE},
1290 "-l", $env_vars->{LOGDIR});
1291 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
1292 push(@args, "--stdout");
1295 close($env_vars->{STDIN_PIPE});
1296 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1298 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1299 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1301 $env_vars->{WINBINDD_TL_PID} = $pid;
1302 write_pid($env_vars, "winbindd", $pid);
1303 print "DONE\n";
1305 unlink($env_vars->{SMBD_TEST_LOG});
1306 print "STARTING SMBD...";
1307 $pid = fork();
1308 if ($pid == 0) {
1309 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
1310 open STDERR, '>&STDOUT';
1312 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
1314 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
1315 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.smbd";
1316 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
1317 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
1319 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
1320 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
1321 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
1322 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
1323 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
1324 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
1325 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
1326 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
1327 } else {
1328 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
1330 $ENV{UID_WRAPPER_ROOT} = "1";
1332 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
1334 if ($smbd ne "yes") {
1335 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
1336 my $signame = shift;
1337 print("Skip smbd received signal $signame");
1338 exit 0;
1340 sleep($self->{server_maxtime});
1341 exit 0;
1344 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
1345 my @optargs = ("-d0");
1346 if (defined($ENV{SMBD_OPTIONS})) {
1347 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
1349 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
1350 if(defined($ENV{SMBD_VALGRIND})) {
1351 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
1353 my @args = ("-F", "--no-process-group",
1354 "-s", $env_vars->{SERVERCONFFILE},
1355 "-l", $env_vars->{LOGDIR});
1356 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
1357 push(@args, "--log-stdout");
1360 close($env_vars->{STDIN_PIPE});
1361 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
1363 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
1364 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
1366 $env_vars->{SMBD_TL_PID} = $pid;
1367 write_pid($env_vars, "smbd", $pid);
1368 print "DONE\n";
1370 close(STDIN_READER);
1372 return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
1375 sub createuser($$$$)
1377 my ($self, $username, $password, $conffile) = @_;
1378 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $username > /dev/null";
1379 unless (open(PWD, "|$cmd")) {
1380 warn("Unable to set password for $username account\n$cmd");
1381 return undef;
1383 print PWD "$password\n$password\n";
1384 unless (close(PWD)) {
1385 warn("Unable to set password for $username account\n$cmd");
1386 return undef;
1390 sub provision($$$$$$$$$)
1392 my ($self, $prefix, $domain, $server, $password, $extra_options, $dc_server_ip, $dc_server_ipv6, $no_delete_prefix) = @_;
1395 ## setup the various environment variables we need
1398 my $swiface = Samba::get_interface($server);
1399 my %ret = ();
1400 my $server_ip = "127.0.0.$swiface";
1401 my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
1403 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
1404 chomp $unix_name;
1405 my $unix_uid = $>;
1406 my $unix_gids_str = $);
1407 my @unix_gids = split(" ", $unix_gids_str);
1409 my $prefix_abs = abs_path($prefix);
1410 my $bindir_abs = abs_path($self->{bindir});
1412 my @dirs = ();
1414 my $shrdir="$prefix_abs/share";
1415 push(@dirs,$shrdir);
1417 my $libdir="$prefix_abs/lib";
1418 push(@dirs,$libdir);
1420 my $piddir="$prefix_abs/pid";
1421 push(@dirs,$piddir);
1423 my $privatedir="$prefix_abs/private";
1424 push(@dirs,$privatedir);
1426 my $lockdir="$prefix_abs/lockdir";
1427 push(@dirs,$lockdir);
1429 my $eventlogdir="$prefix_abs/lockdir/eventlog";
1430 push(@dirs,$eventlogdir);
1432 my $logdir="$prefix_abs/logs";
1433 push(@dirs,$logdir);
1435 my $driver32dir="$shrdir/W32X86";
1436 push(@dirs,$driver32dir);
1438 my $driver64dir="$shrdir/x64";
1439 push(@dirs,$driver64dir);
1441 my $driver40dir="$shrdir/WIN40";
1442 push(@dirs,$driver40dir);
1444 my $ro_shrdir="$shrdir/root-tmp";
1445 push(@dirs,$ro_shrdir);
1447 my $msdfs_shrdir="$shrdir/msdfsshare";
1448 push(@dirs,$msdfs_shrdir);
1450 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
1451 push(@dirs,$msdfs_deeppath);
1453 my $badnames_shrdir="$shrdir/badnames";
1454 push(@dirs,$badnames_shrdir);
1456 my $lease1_shrdir="$shrdir/SMB2_10";
1457 push(@dirs,$lease1_shrdir);
1459 my $lease2_shrdir="$shrdir/SMB3_00";
1460 push(@dirs,$lease2_shrdir);
1462 my $manglenames_shrdir="$shrdir/manglenames";
1463 push(@dirs,$manglenames_shrdir);
1465 my $widelinks_shrdir="$shrdir/widelinks";
1466 push(@dirs,$widelinks_shrdir);
1468 my $widelinks_linkdir="$shrdir/widelinks_foo";
1469 push(@dirs,$widelinks_linkdir);
1471 my $shadow_tstdir="$shrdir/shadow";
1472 push(@dirs,$shadow_tstdir);
1473 my $shadow_mntdir="$shadow_tstdir/mount";
1474 push(@dirs,$shadow_mntdir);
1475 my $shadow_basedir="$shadow_mntdir/base";
1476 push(@dirs,$shadow_basedir);
1477 my $shadow_shrdir="$shadow_basedir/share";
1478 push(@dirs,$shadow_shrdir);
1480 my $nosymlinks_shrdir="$shrdir/nosymlinks";
1481 push(@dirs,$nosymlinks_shrdir);
1483 my $local_symlinks_shrdir="$shrdir/local_symlinks";
1484 push(@dirs,$local_symlinks_shrdir);
1486 # this gets autocreated by winbindd
1487 my $wbsockdir="$prefix_abs/winbindd";
1489 my $nmbdsockdir="$prefix_abs/nmbd";
1490 unlink($nmbdsockdir);
1493 ## create the test directory layout
1495 die ("prefix_abs = ''") if $prefix_abs eq "";
1496 die ("prefix_abs = '/'") if $prefix_abs eq "/";
1498 mkdir($prefix_abs, 0777);
1499 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
1500 if (not defined($no_delete_prefix) or not $no_delete_prefix) {
1501 system("rm -rf $prefix_abs/*");
1503 mkdir($_, 0777) foreach(@dirs);
1505 my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
1508 ## lockdir and piddir must be 0755
1510 chmod 0755, $lockdir;
1511 chmod 0755, $piddir;
1515 ## create ro and msdfs share layout
1518 chmod 0755, $ro_shrdir;
1519 my $unreadable_file = "$ro_shrdir/unreadable_file";
1520 unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
1521 warn("Unable to open $unreadable_file");
1522 return undef;
1524 close(UNREADABLE_FILE);
1525 chmod 0600, $unreadable_file;
1527 my $msdfs_target = "$ro_shrdir/msdfs-target";
1528 unless (open(MSDFS_TARGET, ">$msdfs_target")) {
1529 warn("Unable to open $msdfs_target");
1530 return undef;
1532 close(MSDFS_TARGET);
1533 chmod 0666, $msdfs_target;
1534 symlink "msdfs:$server_ip\\ro-tmp,$server_ipv6\\ro-tmp",
1535 "$msdfs_shrdir/msdfs-src1";
1536 symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
1539 ## create bad names in $badnames_shrdir
1541 ## (An invalid name, would be mangled to 8.3).
1542 my $badname_target = "$badnames_shrdir/\340|\231\216\377\177";
1543 unless (open(BADNAME_TARGET, ">$badname_target")) {
1544 warn("Unable to open $badname_target");
1545 return undef;
1547 close(BADNAME_TARGET);
1548 chmod 0666, $badname_target;
1550 ## (A bad name, would not be mangled to 8.3).
1551 my $badname_target = "$badnames_shrdir/\240\276\346\327\377\177";
1552 unless (open(BADNAME_TARGET, ">$badname_target")) {
1553 warn("Unable to open $badname_target");
1554 return undef;
1556 close(BADNAME_TARGET);
1557 chmod 0666, $badname_target;
1559 ## (A bad good name).
1560 my $badname_target = "$badnames_shrdir/blank.txt";
1561 unless (open(BADNAME_TARGET, ">$badname_target")) {
1562 warn("Unable to open $badname_target");
1563 return undef;
1565 close(BADNAME_TARGET);
1566 chmod 0666, $badname_target;
1569 ## create mangleable directory names in $manglenames_shrdir
1571 my $manglename_target = "$manglenames_shrdir/foo:bar";
1572 mkdir($manglename_target, 0777);
1575 ## create symlinks for widelinks tests.
1577 my $widelinks_target = "$widelinks_linkdir/target";
1578 unless (open(WIDELINKS_TARGET, ">$widelinks_target")) {
1579 warn("Unable to open $widelinks_target");
1580 return undef;
1582 close(WIDELINKS_TARGET);
1583 chmod 0666, $widelinks_target;
1585 ## This link should get ACCESS_DENIED
1587 symlink "$widelinks_target", "$widelinks_shrdir/source";
1589 ## This link should be allowed
1591 symlink "$widelinks_shrdir", "$widelinks_shrdir/dot";
1593 my $conffile="$libdir/server.conf";
1594 my $dfqconffile="$libdir/dfq.conf";
1596 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
1597 my $nss_wrapper_passwd = "$privatedir/passwd";
1598 my $nss_wrapper_group = "$privatedir/group";
1599 my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
1600 my $resolv_conf = "$privatedir/resolv.conf";
1601 my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
1603 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
1605 my $fake_snap_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/fake_snap.pl";
1607 my @eventlog_list = ("dns server", "application");
1610 ## calculate uids and gids
1613 my ($max_uid, $max_gid);
1614 my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2, $uid_userdup);
1615 my ($uid_pdbtest_wkn);
1616 my ($uid_smbget);
1617 my ($uid_force_user);
1618 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
1619 my ($gid_userdup, $gid_everyone);
1620 my ($gid_force_user);
1621 my ($uid_user1);
1622 my ($uid_user2);
1624 if ($unix_uid < 0xffff - 10) {
1625 $max_uid = 0xffff;
1626 } else {
1627 $max_uid = $unix_uid;
1630 $uid_root = $max_uid - 1;
1631 $uid_nobody = $max_uid - 2;
1632 $uid_pdbtest = $max_uid - 3;
1633 $uid_pdbtest2 = $max_uid - 4;
1634 $uid_userdup = $max_uid - 5;
1635 $uid_pdbtest_wkn = $max_uid - 6;
1636 $uid_force_user = $max_uid - 7;
1637 $uid_smbget = $max_uid - 8;
1638 $uid_user1 = $max_uid - 9;
1639 $uid_user2 = $max_uid - 10;
1641 if ($unix_gids[0] < 0xffff - 8) {
1642 $max_gid = 0xffff;
1643 } else {
1644 $max_gid = $unix_gids[0];
1647 $gid_nobody = $max_gid - 1;
1648 $gid_nogroup = $max_gid - 2;
1649 $gid_root = $max_gid - 3;
1650 $gid_domusers = $max_gid - 4;
1651 $gid_domadmins = $max_gid - 5;
1652 $gid_userdup = $max_gid - 6;
1653 $gid_everyone = $max_gid - 7;
1654 $gid_force_user = $max_gid - 8;
1657 ## create conffile
1660 unless (open(CONF, ">$conffile")) {
1661 warn("Unable to open $conffile");
1662 return undef;
1664 print CONF "
1665 [global]
1666 netbios name = $server
1667 interfaces = $server_ip/8 $server_ipv6/64
1668 bind interfaces only = yes
1669 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
1670 smbd:suicide mode = yes
1672 workgroup = $domain
1674 private dir = $privatedir
1675 pid directory = $piddir
1676 lock directory = $lockdir
1677 log file = $logdir/log.\%m
1678 log level = 1
1679 debug pid = yes
1680 max log size = 0
1682 state directory = $lockdir
1683 cache directory = $lockdir
1685 passdb backend = tdbsam
1687 time server = yes
1689 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1690 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
1691 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1692 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
1693 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1694 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1695 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
1697 addprinter command = $mod_printer_pl -a -s $conffile --
1698 deleteprinter command = $mod_printer_pl -d -s $conffile --
1700 eventlog list = application \"dns server\"
1702 kernel oplocks = no
1703 kernel change notify = no
1705 logging = file
1706 printing = bsd
1707 printcap name = /dev/null
1709 winbindd socket directory = $wbsockdir
1710 nmbd:socket dir = $nmbdsockdir
1711 idmap config * : range = 100000-200000
1712 winbind enum users = yes
1713 winbind enum groups = yes
1714 winbind separator = /
1715 include system krb5 conf = no
1717 # min receivefile size = 4000
1719 read only = no
1721 smbd:sharedelay = 100000
1722 smbd:writetimeupdatedelay = 500000
1723 map hidden = no
1724 map system = no
1725 map readonly = no
1726 store dos attributes = yes
1727 create mask = 755
1728 dos filemode = yes
1729 strict rename = yes
1730 strict sync = yes
1731 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1733 printing = vlp
1734 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1735 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1736 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1737 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1738 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1739 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1740 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1741 lpq cache time = 0
1742 print notify backchannel = yes
1744 ncalrpc dir = $prefix_abs/ncalrpc
1746 # The samba3.blackbox.smbclient_s3 test uses this to test that
1747 # sending messages works, and that the %m sub works.
1748 message command = mv %s $shrdir/message.%m
1750 # fsrvp server requires registry shares
1751 registry shares = yes
1753 # Used by RPC SRVSVC tests
1754 add share command = $bindir_abs/smbaddshare
1755 change share command = $bindir_abs/smbchangeshare
1756 delete share command = $bindir_abs/smbdeleteshare
1758 # fruit:copyfile is a global option
1759 fruit:copyfile = yes
1761 #this does not mean that we use non-secure test env,
1762 #it just means we ALLOW one to be configured.
1763 allow insecure wide links = yes
1765 # Begin extra options
1766 $extra_options
1767 # End extra options
1769 #Include user defined custom parameters if set
1772 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1773 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1776 print CONF "
1777 [tmp]
1778 path = $shrdir
1779 comment = smb username is [%U]
1780 [tmpsort]
1781 path = $shrdir
1782 comment = Load dirsort module
1783 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1784 [tmpenc]
1785 path = $shrdir
1786 comment = encrypt smb username is [%U]
1787 smb encrypt = required
1788 vfs objects = dirsort
1789 [tmpguest]
1790 path = $shrdir
1791 guest ok = yes
1792 [guestonly]
1793 path = $shrdir
1794 guest only = yes
1795 guest ok = yes
1796 [forceuser]
1797 path = $shrdir
1798 force user = $unix_name
1799 guest ok = yes
1800 [forceuser_unixonly]
1801 comment = force a user with unix user SID and group SID
1802 path = $shrdir
1803 force user = pdbtest
1804 guest ok = yes
1805 [forceuser_wkngroup]
1806 comment = force a user with well-known group SID
1807 path = $shrdir
1808 force user = pdbtest_wkn
1809 guest ok = yes
1810 [forcegroup]
1811 path = $shrdir
1812 force group = nogroup
1813 guest ok = yes
1814 [ro-tmp]
1815 path = $ro_shrdir
1816 guest ok = yes
1817 [write-list-tmp]
1818 path = $shrdir
1819 read only = yes
1820 write list = $unix_name
1821 [valid-users-tmp]
1822 path = $shrdir
1823 valid users = $unix_name
1824 access based share enum = yes
1825 [msdfs-share]
1826 path = $msdfs_shrdir
1827 msdfs root = yes
1828 msdfs shuffle referrals = yes
1829 guest ok = yes
1830 [hideunread]
1831 copy = tmp
1832 hide unreadable = yes
1833 [tmpcase]
1834 copy = tmp
1835 case sensitive = yes
1836 [hideunwrite]
1837 copy = tmp
1838 hide unwriteable files = yes
1839 [durable]
1840 copy = tmp
1841 kernel share modes = no
1842 kernel oplocks = no
1843 posix locking = no
1844 [fs_specific]
1845 copy = tmp
1846 $fs_specific_conf
1847 [print1]
1848 copy = tmp
1849 printable = yes
1851 [print2]
1852 copy = print1
1853 [print3]
1854 copy = print1
1855 default devmode = no
1856 [lp]
1857 copy = print1
1859 [nfs4acl_simple]
1860 path = $shrdir
1861 comment = smb username is [%U]
1862 nfs4:mode = simple
1863 vfs objects = nfs4acl_xattr xattr_tdb
1865 [nfs4acl_special]
1866 path = $shrdir
1867 comment = smb username is [%U]
1868 nfs4:mode = special
1869 vfs objects = nfs4acl_xattr xattr_tdb
1871 [xcopy_share]
1872 path = $shrdir
1873 comment = smb username is [%U]
1874 create mask = 777
1875 force create mode = 777
1876 [posix_share]
1877 path = $shrdir
1878 comment = smb username is [%U]
1879 create mask = 0777
1880 force create mode = 0
1881 directory mask = 0777
1882 force directory mode = 0
1883 vfs objects = xattr_tdb streams_depot
1884 [aio]
1885 copy = tmp
1886 aio read size = 1
1887 aio write size = 1
1889 [print\$]
1890 copy = tmp
1892 [vfs_fruit]
1893 path = $shrdir
1894 vfs objects = catia fruit streams_xattr acl_xattr
1895 fruit:resource = file
1896 fruit:metadata = netatalk
1897 fruit:locking = netatalk
1898 fruit:encoding = native
1900 [vfs_fruit_metadata_stream]
1901 path = $shrdir
1902 vfs objects = fruit streams_xattr acl_xattr
1903 fruit:resource = file
1904 fruit:metadata = stream
1906 [vfs_fruit_stream_depot]
1907 path = $shrdir
1908 vfs objects = fruit streams_depot acl_xattr
1909 fruit:resource = stream
1910 fruit:metadata = stream
1912 [vfs_wo_fruit]
1913 path = $shrdir
1914 vfs objects = streams_xattr acl_xattr
1916 [vfs_wo_fruit_stream_depot]
1917 path = $shrdir
1918 vfs objects = streams_depot acl_xattr
1920 [badname-tmp]
1921 path = $badnames_shrdir
1922 guest ok = yes
1924 [manglenames_share]
1925 path = $manglenames_shrdir
1926 guest ok = yes
1928 [dynamic_share]
1929 path = $shrdir/%R
1930 guest ok = yes
1932 [widelinks_share]
1933 path = $widelinks_shrdir
1934 wide links = no
1935 guest ok = yes
1937 [fsrvp_share]
1938 path = $shrdir
1939 comment = fake shapshots using rsync
1940 vfs objects = shell_snap shadow_copy2
1941 shell_snap:check path command = $fake_snap_pl --check
1942 shell_snap:create command = $fake_snap_pl --create
1943 shell_snap:delete command = $fake_snap_pl --delete
1944 # a relative path here fails, the snapshot dir is no longer found
1945 shadow:snapdir = $shrdir/.snapshots
1947 [shadow1]
1948 path = $shadow_shrdir
1949 comment = previous versions snapshots under mount point
1950 vfs objects = shadow_copy2
1951 shadow:mountpoint = $shadow_mntdir
1953 [shadow2]
1954 path = $shadow_shrdir
1955 comment = previous versions snapshots outside mount point
1956 vfs objects = shadow_copy2
1957 shadow:mountpoint = $shadow_mntdir
1958 shadow:snapdir = $shadow_tstdir/.snapshots
1960 [shadow3]
1961 path = $shadow_shrdir
1962 comment = previous versions with subvolume snapshots, snapshots under base dir
1963 vfs objects = shadow_copy2
1964 shadow:mountpoint = $shadow_mntdir
1965 shadow:basedir = $shadow_basedir
1966 shadow:snapdir = $shadow_basedir/.snapshots
1968 [shadow4]
1969 path = $shadow_shrdir
1970 comment = previous versions with subvolume snapshots, snapshots outside mount point
1971 vfs objects = shadow_copy2
1972 shadow:mountpoint = $shadow_mntdir
1973 shadow:basedir = $shadow_basedir
1974 shadow:snapdir = $shadow_tstdir/.snapshots
1976 [shadow5]
1977 path = $shadow_shrdir
1978 comment = previous versions at volume root snapshots under mount point
1979 vfs objects = shadow_copy2
1980 shadow:mountpoint = $shadow_shrdir
1982 [shadow6]
1983 path = $shadow_shrdir
1984 comment = previous versions at volume root snapshots outside mount point
1985 vfs objects = shadow_copy2
1986 shadow:mountpoint = $shadow_shrdir
1987 shadow:snapdir = $shadow_tstdir/.snapshots
1989 [shadow7]
1990 path = $shadow_shrdir
1991 comment = previous versions snapshots everywhere
1992 vfs objects = shadow_copy2
1993 shadow:mountpoint = $shadow_mntdir
1994 shadow:snapdirseverywhere = yes
1996 [shadow8]
1997 path = $shadow_shrdir
1998 comment = previous versions using snapsharepath
1999 vfs objects = shadow_copy2
2000 shadow:mountpoint = $shadow_mntdir
2001 shadow:snapdir = $shadow_tstdir/.snapshots
2002 shadow:snapsharepath = share
2004 [shadow_fmt0]
2005 comment = Testing shadow:format with default option
2006 vfs object = shadow_copy2
2007 path = $shadow_shrdir
2008 read only = no
2009 guest ok = yes
2010 shadow:mountpoint = $shadow_mntdir
2011 shadow:basedir = $shadow_basedir
2012 shadow:snapdir = $shadow_basedir/.snapshots
2013 shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
2015 [shadow_fmt1]
2016 comment = Testing shadow:format with only date component
2017 vfs object = shadow_copy2
2018 path = $shadow_shrdir
2019 read only = no
2020 guest ok = yes
2021 shadow:mountpoint = $shadow_mntdir
2022 shadow:basedir = $shadow_basedir
2023 shadow:snapdir = $shadow_basedir/.snapshots
2024 shadow:format = \@GMT-%Y-%m-%d
2026 [shadow_fmt2]
2027 comment = Testing shadow:format with some hardcoded prefix
2028 vfs object = shadow_copy2
2029 path = $shadow_shrdir
2030 read only = no
2031 guest ok = yes
2032 shadow:mountpoint = $shadow_mntdir
2033 shadow:basedir = $shadow_basedir
2034 shadow:snapdir = $shadow_basedir/.snapshots
2035 shadow:format = snap\@GMT-%Y.%m.%d-%H.%M.%S
2037 [shadow_fmt3]
2038 comment = Testing shadow:format with modified format
2039 vfs object = shadow_copy2
2040 path = $shadow_shrdir
2041 read only = no
2042 guest ok = yes
2043 shadow:mountpoint = $shadow_mntdir
2044 shadow:basedir = $shadow_basedir
2045 shadow:snapdir = $shadow_basedir/.snapshots
2046 shadow:format = \@GMT-%Y.%m.%d-%H_%M_%S-snap
2048 [shadow_fmt4]
2049 comment = Testing shadow:snapprefix regex
2050 vfs object = shadow_copy2
2051 path = $shadow_shrdir
2052 read only = no
2053 guest ok = yes
2054 shadow:mountpoint = $shadow_mntdir
2055 shadow:basedir = $shadow_basedir
2056 shadow:snapdir = $shadow_basedir/.snapshots
2057 shadow:snapprefix = \^s[a-z]*p\$
2058 shadow:format = _GMT-%Y.%m.%d-%H.%M.%S
2060 [shadow_fmt5]
2061 comment = Testing shadow:snapprefix with delim regex
2062 vfs object = shadow_copy2
2063 path = $shadow_shrdir
2064 read only = no
2065 guest ok = yes
2066 shadow:mountpoint = $shadow_mntdir
2067 shadow:basedir = $shadow_basedir
2068 shadow:snapdir = $shadow_basedir/.snapshots
2069 shadow:delimiter = \@GMT
2070 shadow:snapprefix = [a-z]*
2071 shadow:format = \@GMT-%Y.%m.%d-%H.%M.%S
2073 [shadow_wl]
2074 path = $shadow_shrdir
2075 comment = previous versions with wide links allowed
2076 vfs objects = shadow_copy2
2077 shadow:mountpoint = $shadow_mntdir
2078 wide links = yes
2079 [dfq]
2080 path = $shrdir/dfree
2081 vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2082 admin users = $unix_name
2083 include = $dfqconffile
2084 [dfq_owner]
2085 path = $shrdir/dfree
2086 vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
2087 inherit owner = yes
2088 include = $dfqconffile
2089 [acl_xattr_ign_sysacl_posix]
2090 copy = tmp
2091 acl_xattr:ignore system acls = yes
2092 acl_xattr:default acl style = posix
2093 [acl_xattr_ign_sysacl_windows]
2094 copy = tmp
2095 acl_xattr:ignore system acls = yes
2096 acl_xattr:default acl style = windows
2098 [mangle_illegal]
2099 copy = tmp
2100 mangled names = illegal
2102 [nosymlinks]
2103 copy = tmp
2104 path = $nosymlinks_shrdir
2105 follow symlinks = no
2107 [local_symlinks]
2108 copy = tmp
2109 path = $local_symlinks_shrdir
2110 follow symlinks = yes
2112 [kernel_oplocks]
2113 copy = tmp
2114 kernel oplocks = yes
2115 vfs objects = streams_xattr xattr_tdb
2117 [compound_find]
2118 copy = tmp
2119 smbd:find async delay usec = 10000
2121 close(CONF);
2123 unless (open(DFQCONF, ">$dfqconffile")) {
2124 warn("Unable to open $dfqconffile");
2125 return undef;
2127 close(DFQCONF);
2130 ## create a test account
2133 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
2134 warn("Unable to open $nss_wrapper_passwd");
2135 return undef;
2137 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
2138 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
2139 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
2140 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
2141 userdup:x:$uid_userdup:$gid_userdup:userdup gecos:$prefix_abs:/bin/false
2142 pdbtest_wkn:x:$uid_pdbtest_wkn:$gid_everyone:pdbtest_wkn gecos:$prefix_abs:/bin/false
2143 force_user:x:$uid_force_user:$gid_force_user:force user gecos:$prefix_abs:/bin/false
2144 smbget_user:x:$uid_smbget:$gid_domusers:smbget_user gecos:$prefix_abs:/bin/false
2145 user1:x:$uid_user1:$gid_nogroup:user1 gecos:$prefix_abs:/bin/false
2146 user2:x:$uid_user2:$gid_nogroup:user2 gecos:$prefix_abs:/bin/false
2148 if ($unix_uid != 0) {
2149 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
2152 close(PASSWD);
2154 unless (open(GROUP, ">$nss_wrapper_group")) {
2155 warn("Unable to open $nss_wrapper_group");
2156 return undef;
2158 print GROUP "nobody:x:$gid_nobody:
2159 nogroup:x:$gid_nogroup:nobody
2160 $unix_name-group:x:$unix_gids[0]:
2161 domusers:X:$gid_domusers:
2162 domadmins:X:$gid_domadmins:
2163 userdup:x:$gid_userdup:$unix_name
2164 everyone:x:$gid_everyone:
2165 force_user:x:$gid_force_user:
2167 if ($unix_gids[0] != 0) {
2168 print GROUP "root:x:$gid_root:
2172 close(GROUP);
2174 ## hosts
2175 my $hostname = lc($server);
2176 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
2177 warn("Unable to open $nss_wrapper_hosts");
2178 return undef;
2180 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n";
2181 print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n";
2182 close(HOSTS);
2184 ## hosts
2185 unless (open(RESOLV_CONF, ">$resolv_conf")) {
2186 warn("Unable to open $resolv_conf");
2187 return undef;
2189 if (defined($dc_server_ip) or defined($dc_server_ipv6)) {
2190 if (defined($dc_server_ip)) {
2191 print RESOLV_CONF "nameserver $dc_server_ip\n";
2193 if (defined($dc_server_ipv6)) {
2194 print RESOLV_CONF "nameserver $dc_server_ipv6\n";
2196 } else {
2197 print RESOLV_CONF "nameserver ${server_ip}\n";
2198 print RESOLV_CONF "nameserver ${server_ipv6}\n";
2200 close(RESOLV_CONF);
2202 foreach my $evlog (@eventlog_list) {
2203 my $evlogtdb = "$eventlogdir/$evlog.tdb";
2204 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
2205 close(EVENTLOG);
2208 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
2209 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
2210 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
2211 $ENV{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
2212 if ($ENV{SAMBA_DNS_FAKING}) {
2213 $ENV{RESOLV_WRAPPER_CONF} = $resolv_conf;
2214 } else {
2215 $ENV{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
2218 createuser($self, $unix_name, $password, $conffile) || die("Unable to create user");
2219 createuser($self, "force_user", $password, $conffile) || die("Unable to create force_user");
2220 createuser($self, "smbget_user", $password, $conffile) || die("Unable to create smbget_user");
2221 createuser($self, "user1", $password, $conffile) || die("Unable to create user1");
2222 createuser($self, "user2", $password, $conffile) || die("Unable to create user2");
2224 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
2225 print DNS_UPDATE_LIST "A $server. $server_ip\n";
2226 print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
2227 close(DNS_UPDATE_LIST);
2229 print "DONE\n";
2231 $ret{SERVER_IP} = $server_ip;
2232 $ret{SERVER_IPV6} = $server_ipv6;
2233 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
2234 $ret{NMBD_TEST_LOG_POS} = 0;
2235 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
2236 $ret{WINBINDD_TEST_LOG_POS} = 0;
2237 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
2238 $ret{SMBD_TEST_LOG_POS} = 0;
2239 $ret{SERVERCONFFILE} = $conffile;
2240 $ret{CONFIGURATION} ="-s $conffile";
2241 $ret{LOCK_DIR} = $lockdir;
2242 $ret{SERVER} = $server;
2243 $ret{USERNAME} = $unix_name;
2244 $ret{USERID} = $unix_uid;
2245 $ret{DOMAIN} = $domain;
2246 $ret{NETBIOSNAME} = $server;
2247 $ret{PASSWORD} = $password;
2248 $ret{PIDDIR} = $piddir;
2249 $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
2250 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
2251 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
2252 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
2253 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
2254 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
2255 $ret{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
2256 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
2257 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
2258 if ($ENV{SAMBA_DNS_FAKING}) {
2259 $ret{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
2260 } else {
2261 $ret{RESOLV_WRAPPER_CONF} = $resolv_conf;
2263 $ret{LOCAL_PATH} = "$shrdir";
2264 $ret{LOGDIR} = $logdir;
2267 # Avoid hitting system krb5.conf -
2268 # An env that needs Kerberos will reset this to the real
2269 # value.
2271 $ret{KRB5_CONFIG} = abs_path($prefix) . "/no_krb5.conf";
2273 # Define KRB5CCNAME for each environment we set up
2274 $ret{KRB5_CCACHE} = abs_path($prefix) . "/krb5ccache";
2275 $ENV{KRB5CCNAME} = $ret{KRB5_CCACHE};
2277 return \%ret;
2280 sub wait_for_start($$$$$)
2282 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
2283 my $ret;
2285 if ($nmbd eq "yes") {
2286 my $count = 0;
2288 # give time for nbt server to register its names
2289 print "checking for nmbd\n";
2291 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
2292 my $nmblookup = Samba::bindir_path($self, "nmblookup");
2294 do {
2295 $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
2296 if ($ret != 0) {
2297 sleep(1);
2298 } else {
2299 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
2300 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
2301 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
2302 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
2304 $count++;
2305 } while ($ret != 0 && $count < 10);
2306 if ($count == 10) {
2307 print "NMBD not reachable after 10 retries\n";
2308 teardown_env($self, $envvars);
2309 return 0;
2313 if ($winbindd eq "yes") {
2314 print "checking for winbindd\n";
2315 my $count = 0;
2316 do {
2317 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --ping-dc");
2318 if ($ret != 0) {
2319 sleep(1);
2321 $count++;
2322 } while ($ret != 0 && $count < 20);
2323 if ($count == 20) {
2324 print "WINBINDD not reachable after 20 seconds\n";
2325 teardown_env($self, $envvars);
2326 return 0;
2330 if ($smbd eq "yes") {
2331 # make sure smbd is also up set
2332 print "wait for smbd\n";
2334 my $count = 0;
2335 do {
2336 $ret = system(Samba::bindir_path($self, "smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
2337 if ($ret != 0) {
2338 sleep(1);
2340 $count++
2341 } while ($ret != 0 && $count < 20);
2342 if ($count == 20) {
2343 print "SMBD failed to start up in a reasonable time (20sec)\n";
2344 teardown_env($self, $envvars);
2345 return 0;
2349 # Ensure we have domain users mapped.
2350 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
2351 if ($ret != 0) {
2352 return 1;
2354 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
2355 if ($ret != 0) {
2356 return 1;
2358 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add sid=S-1-1-0 unixgroup=everyone type=builtin");
2359 if ($ret != 0) {
2360 return 1;
2363 if ($winbindd eq "yes") {
2364 # note: creating builtin groups requires winbindd for the
2365 # unix id allocator
2366 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
2367 if ($ret != 0) {
2368 print "Failed to create BUILTIN\\Users group\n";
2369 return 0;
2371 my $count = 0;
2372 do {
2373 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache del IDMAP/SID2XID/S-1-5-32-545");
2374 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
2375 if ($ret != 0) {
2376 sleep(2);
2378 $count++;
2379 } while ($ret != 0 && $count < 10);
2380 if ($count == 10) {
2381 print "WINBINDD not reachable after 20 seconds\n";
2382 teardown_env($self, $envvars);
2383 return 0;
2387 print $self->getlog_env($envvars);
2389 return 1;