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