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.
10 use FindBin
qw($RealBin);
17 my $smbd_build_options = Samba::bindir_path($self, "smbd") . " -b|";
18 open(IN, $smbd_build_options) or die("Unable to run $smbd_build_options: $!");
27 # If we were not built with ADS support, pretend we were never even available
28 print "smbd does not have ADS support\n" unless $found_ads;
32 # return smb.conf parameters applicable to @path, based on the underlying
34 sub get_fs_specific_conf($$)
36 my ($self, $path) = @_;
38 my $stat_out = `stat --file-system $path` or return "";
40 if ($stat_out =~ m/Type:\s+btrfs/) {
45 return "vfs objects = $mods";
52 my ($classname, $bindir, $srcdir, $server_maxtime) = @_;
53 my $self = { vars => {},
56 server_maxtime => $server_maxtime
64 my ($self, $envvars) = @_;
67 # This should cause smbd to terminate gracefully
68 close($envvars->{STDIN_PIPE});
70 my $smbdpid = $envvars->{SMBD_TL_PID};
71 my $nmbdpid = $envvars->{NMBD_TL_PID};
72 my $winbinddpid = $envvars->{WINBINDD_TL_PID};
74 # This should give it time to write out the gcov data
76 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
77 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
78 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
81 && $winbinddchild == -1) {
88 if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
92 $self->stop_sig_term($smbdpid);
93 $self->stop_sig_term($nmbdpid);
94 $self->stop_sig_term($winbinddpid);
98 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
99 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
100 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
103 && $winbinddchild == -1) {
110 if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
114 warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
115 $self->stop_sig_kill($smbdpid);
116 $self->stop_sig_kill($nmbdpid);
117 $self->stop_sig_kill($winbinddpid);
122 sub getlog_env_app($$$)
124 my ($self, $envvars, $name) = @_;
126 my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
129 open(LOG, "<".$envvars->{$name."_TEST_LOG"});
131 seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
135 $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
138 return "" if $out eq $title;
145 my ($self, $envvars) = @_;
148 $ret .= $self->getlog_env_app($envvars, "SMBD");
149 $ret .= $self->getlog_env_app($envvars, "NMBD");
150 $ret .= $self->getlog_env_app($envvars, "WINBINDD");
157 my ($self, $envvars) = @_;
159 my $childpid = waitpid(-1, WNOHANG);
167 my ($self, $envname, $path) = @_;
169 $ENV{ENVNAME} = $envname;
171 if (defined($self->{vars}->{$envname})) {
172 return $self->{vars}->{$envname};
175 if ($envname eq "nt4_dc") {
176 return $self->setup_nt4_dc("$path/nt4_dc");
177 } elsif ($envname eq "nt4_dc_schannel") {
178 return $self->setup_nt4_dc_schannel("$path/nt4_dc_schannel");
179 } elsif ($envname eq "simpleserver") {
180 return $self->setup_simpleserver("$path/simpleserver");
181 } elsif ($envname eq "fileserver") {
182 return $self->setup_fileserver("$path/fileserver");
183 } elsif ($envname eq "maptoguest") {
184 return $self->setup_maptoguest("$path/maptoguest");
185 } elsif ($envname eq "ktest") {
186 return $self->setup_ktest("$path/ktest");
187 } elsif ($envname eq "nt4_member") {
188 if (not defined($self->{vars}->{nt4_dc})) {
189 if (not defined($self->setup_nt4_dc("$path/nt4_dc"))) {
193 return $self->setup_nt4_member("$path/nt4_member", $self->{vars}->{nt4_dc});
201 my ($self, $path) = @_;
203 print "PROVISIONING NT4 DC...";
205 my $nt4_dc_options = "
210 rpc_server:epmapper = external
211 rpc_server:spoolss = external
212 rpc_server:lsarpc = external
213 rpc_server:samr = external
214 rpc_server:netlogon = external
215 rpc_server:register_embedded_np = yes
216 rpc_server:FssagentRpc = external
218 rpc_daemon:epmd = fork
219 rpc_daemon:spoolssd = fork
220 rpc_daemon:lsasd = fork
221 rpc_daemon:fssd = fork
222 fss: sequence timeout = 1
225 my $vars = $self->provision($path,
230 $vars or return undef;
232 if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
236 $vars->{DC_SERVER} = $vars->{SERVER};
237 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
238 $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
239 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
240 $vars->{DC_USERNAME} = $vars->{USERNAME};
241 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
243 $self->{vars}->{nt4_dc} = $vars;
248 sub setup_nt4_dc_schannel($$)
250 my ($self, $path) = @_;
252 print "PROVISIONING NT4 DC WITH SERVER SCHANNEL ...";
259 rpc_server:epmapper = external
260 rpc_server:spoolss = external
261 rpc_server:lsarpc = external
262 rpc_server:samr = external
263 rpc_server:netlogon = external
264 rpc_server:register_embedded_np = yes
266 rpc_daemon:epmd = fork
267 rpc_daemon:spoolssd = fork
268 rpc_daemon:lsasd = fork
270 server schannel = yes
273 my $vars = $self->provision($path,
278 $vars or return undef;
280 if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
284 $vars->{DC_SERVER} = $vars->{SERVER};
285 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
286 $vars->{DC_SERVER_IPV6} = $vars->{SERVER_IPV6};
287 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
288 $vars->{DC_USERNAME} = $vars->{USERNAME};
289 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
291 $self->{vars}->{nt4_dc_schannel} = $vars;
296 sub setup_nt4_member($$$)
298 my ($self, $prefix, $nt4_dc_vars) = @_;
302 print "PROVISIONING MEMBER...";
304 my $member_options = "
307 dbwrap_tdb_mutexes:* = yes
309 my $ret = $self->provision($prefix,
311 "localnt4member3pass",
314 $ret or return undef;
316 my $nmblookup = Samba::bindir_path($self, "nmblookup");
318 print "Waiting for the LOGON SERVER registration ...\n";
319 $rc = system("$nmblookup $ret->{CONFIGURATION} $ret->{DOMAIN}\#1c");
324 } while ($rc != 0 && $count < 10);
326 print "NMBD not reachable after 10 retries\n";
327 teardown_env($self, $ret);
331 my $net = Samba::bindir_path($self, "net");
333 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
334 $cmd .= "$net 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");
342 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
346 $ret->{DC_SERVER} = $nt4_dc_vars->{SERVER};
347 $ret->{DC_SERVER_IP} = $nt4_dc_vars->{SERVER_IP};
348 $ret->{DC_SERVER_IPV6} = $nt4_dc_vars->{SERVER_IPV6};
349 $ret->{DC_NETBIOSNAME} = $nt4_dc_vars->{NETBIOSNAME};
350 $ret->{DC_USERNAME} = $nt4_dc_vars->{USERNAME};
351 $ret->{DC_PASSWORD} = $nt4_dc_vars->{PASSWORD};
356 sub setup_admember($$$$)
358 my ($self, $prefix, $dcvars) = @_;
360 # If we didn't build with ADS, pretend this env was never available
361 if (not $self->have_ads()) {
365 print "PROVISIONING S3 AD MEMBER...";
367 my $member_options = "
370 workgroup = $dcvars->{DOMAIN}
371 realm = $dcvars->{REALM}
374 my $ret = $self->provision($prefix,
378 $dcvars->{SERVER_IP},
379 $dcvars->{SERVER_IPV6});
381 $ret or return undef;
384 $ret->{DOMAIN} = $dcvars->{DOMAIN};
385 $ret->{REALM} = $dcvars->{REALM};
388 my $prefix_abs = abs_path($prefix);
390 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
391 $ctx->{domain} = $dcvars->{DOMAIN};
392 $ctx->{realm} = $dcvars->{REALM};
393 $ctx->{dnsname} = lc($dcvars->{REALM});
394 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
395 $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
396 Samba::mk_krb5_conf($ctx, "");
398 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
400 my $net = Samba::bindir_path($self, "net");
402 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
403 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
404 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
406 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
408 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
409 $cmd .= "$net join $ret->{CONFIGURATION}";
410 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
412 if (system($cmd) != 0) {
413 warn("Join failed\n$cmd");
417 # We need world access to this share, as otherwise the domain
418 # administrator from the AD domain provided by Samba4 can't
419 # access the share for tests.
420 chmod 0777, "$prefix/share";
422 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
426 $ret->{DC_SERVER} = $dcvars->{SERVER};
427 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
428 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
429 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
430 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
431 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
433 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
434 $ret->{target} = $self;
439 sub setup_admember_rfc2307($$$$)
441 my ($self, $prefix, $dcvars) = @_;
443 # If we didn't build with ADS, pretend this env was never available
444 if (not $self->have_ads()) {
448 print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
450 my $member_options = "
453 workgroup = $dcvars->{DOMAIN}
454 realm = $dcvars->{REALM}
455 idmap config $dcvars->{DOMAIN} : backend = rfc2307
456 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
457 idmap config $dcvars->{DOMAIN} : ldap_server = ad
458 idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
459 idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
462 my $ret = $self->provision($prefix,
466 $dcvars->{SERVER_IP},
467 $dcvars->{SERVER_IPV6});
469 $ret or return undef;
472 $ret->{DOMAIN} = $dcvars->{DOMAIN};
473 $ret->{REALM} = $dcvars->{REALM};
476 my $prefix_abs = abs_path($prefix);
478 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
479 $ctx->{domain} = $dcvars->{DOMAIN};
480 $ctx->{realm} = $dcvars->{REALM};
481 $ctx->{dnsname} = lc($dcvars->{REALM});
482 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
483 $ctx->{kdc_ipv6} = $dcvars->{SERVER_IPV6};
484 Samba::mk_krb5_conf($ctx, "");
486 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
488 my $net = Samba::bindir_path($self, "net");
490 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
491 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
492 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
494 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
496 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
497 $cmd .= "$net join $ret->{CONFIGURATION}";
498 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
500 if (system($cmd) != 0) {
501 warn("Join failed\n$cmd");
505 # We need world access to this share, as otherwise the domain
506 # administrator from the AD domain provided by Samba4 can't
507 # access the share for tests.
508 chmod 0777, "$prefix/share";
510 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
514 $ret->{DC_SERVER} = $dcvars->{SERVER};
515 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
516 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
517 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
518 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
519 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
521 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
522 $ret->{target} = $self;
527 sub setup_simpleserver($$)
529 my ($self, $path) = @_;
531 print "PROVISIONING simple server...";
533 my $prefix_abs = abs_path($path);
535 my $simpleserver_options = "
537 vfs objects = xattr_tdb streams_depot
540 path = $prefix_abs/share
541 vfs objects = aio_fork
543 vfs_aio_fork:erratic_testing_mode=yes
546 my $vars = $self->provision($path,
549 $simpleserver_options);
551 $vars or return undef;
553 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
557 $self->{vars}->{simpleserver} = $vars;
562 sub setup_fileserver($$)
564 my ($self, $path) = @_;
565 my $prefix_abs = abs_path($path);
567 print "PROVISIONING file server ...\n";
571 mkdir($prefix_abs, 0777);
573 my $share_dir="$prefix_abs/share";
575 # Create share directory structure
576 my $lower_case_share_dir="$share_dir/lower-case";
577 push(@dirs, $lower_case_share_dir);
579 my $lower_case_share_dir_30000="$share_dir/lower-case-30000";
580 push(@dirs, $lower_case_share_dir_30000);
582 my $fileserver_options = "
584 path = $lower_case_share_dir
585 comment = smb username is [%U]
586 case sensitive = True
589 short preserve case = no
591 path = $lower_case_share_dir_30000
592 comment = smb username is [%U]
593 case sensitive = True
596 short preserve case = no
599 my $vars = $self->provision($path,
607 $vars or return undef;
609 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
613 $self->{vars}->{fileserver} = $vars;
615 mkdir($_, 0777) foreach(@dirs);
617 ## Create case sensitive lower case share dir
618 foreach my $file ('a'..'z') {
619 my $full_path = $lower_case_share_dir . '/' . $file;
620 open my $fh, '>', $full_path;
621 # Add some content to file
622 print $fh $full_path;
626 for (my $file = 1; $file < 51; ++$file) {
627 my $full_path = $lower_case_share_dir . '/' . $file;
628 open my $fh, '>', $full_path;
629 # Add some content to file
630 print $fh $full_path;
634 # Create content for 30000 share
635 foreach my $file ('a'..'z') {
636 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
637 open my $fh, '>', $full_path;
638 # Add some content to file
639 print $fh $full_path;
643 for (my $file = 1; $file < 30001; ++$file) {
644 my $full_path = $lower_case_share_dir_30000 . '/' . $file;
645 open my $fh, '>', $full_path;
646 # Add some content to file
647 print $fh $full_path;
656 my ($self, $prefix) = @_;
658 # If we didn't build with ADS, pretend this env was never available
659 if (not $self->have_ads()) {
663 print "PROVISIONING server with security=ads...";
665 my $ktest_options = "
667 realm = ktest.samba.example.com
669 username map = $prefix/lib/username.map
670 server signing = required
673 my $ret = $self->provision($prefix,
678 $ret or return undef;
681 my $prefix_abs = abs_path($prefix);
683 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
684 $ctx->{domain} = "KTEST";
685 $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
686 $ctx->{dnsname} = lc($ctx->{realm});
687 $ctx->{kdc_ipv4} = "0.0.0.0";
688 $ctx->{kdc_ipv6} = "::";
689 Samba::mk_krb5_conf($ctx, "");
691 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
693 open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
695 $ret->{USERNAME} = KTEST\\Administrator
699 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
700 #Samba4 DC with the same parameters as are being used here. The
701 #domain SID is S-1-5-21-1071277805-689288055-3486227160
703 system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
704 chmod 0600, "$prefix/private/secrets.tdb";
706 #Make sure there's no old ntdb file.
707 system("rm -f $prefix/private/secrets.ntdb");
709 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
710 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
712 #and having in krb5.conf:
713 # ticket_lifetime = 799718400
714 # renew_lifetime = 799718400
716 # The commands for the -2 keytab where were:
717 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
718 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
719 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
720 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
721 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
723 # and then for the -3 keytab, I did
725 # net changetrustpw; kdestroy and the same again.
727 # This creates a credential cache with a very long lifetime (2036 at
728 # at 2011-04), and shows that running 'net changetrustpw' does not
729 # break existing logins (for the secrets.tdb method at least).
732 $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
734 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
735 chmod 0600, "$prefix/krb5_ccache-2";
737 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
738 chmod 0600, "$prefix/krb5_ccache-3";
740 # We need world access to this share, as otherwise the domain
741 # administrator from the AD domain provided by ktest can't
742 # access the share for tests.
743 chmod 0777, "$prefix/share";
745 if (not $self->check_or_start($ret, "yes", "no", "yes")) {
751 sub setup_maptoguest($$)
753 my ($self, $path) = @_;
755 print "PROVISIONING maptoguest...";
758 map to guest = bad user
761 my $vars = $self->provision($path,
766 $vars or return undef;
768 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
772 $self->{vars}->{s3maptoguest} = $vars;
777 sub stop_sig_term($$) {
778 my ($self, $pid) = @_;
779 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
782 sub stop_sig_kill($$) {
783 my ($self, $pid) = @_;
784 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
789 my ($env_vars, $app, $pid) = @_;
791 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
798 my ($env_vars, $app) = @_;
800 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
806 sub check_or_start($$$$$) {
807 my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
809 # use a pipe for stdin in the child processes. This allows
810 # those processes to monitor the pipe for EOF to ensure they
811 # exit when the test script exits
812 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
814 unlink($env_vars->{NMBD_TEST_LOG});
815 print "STARTING NMBD...";
818 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
819 open STDERR, '>&STDOUT';
821 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
823 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
824 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
825 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
827 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
828 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
829 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
830 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
831 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
832 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
834 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
836 if ($nmbd ne "yes") {
837 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
839 print("Skip nmbd received signal $signame");
842 sleep($self->{server_maxtime});
846 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
847 my @optargs = ("-d0");
848 if (defined($ENV{NMBD_OPTIONS})) {
849 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
851 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
852 if(defined($ENV{NMBD_VALGRIND})) {
853 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
855 my @args = ("-F", "--no-process-group",
856 "-s", $env_vars->{SERVERCONFFILE},
857 "-l", $env_vars->{LOGDIR});
858 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
859 push(@args, "--log-stdout");
862 close($env_vars->{STDIN_PIPE});
863 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
865 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
866 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
868 $env_vars->{NMBD_TL_PID} = $pid;
869 write_pid($env_vars, "nmbd", $pid);
872 unlink($env_vars->{WINBINDD_TEST_LOG});
873 print "STARTING WINBINDD...";
876 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
877 open STDERR, '>&STDOUT';
879 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
881 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
882 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
883 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
885 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
886 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
887 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
888 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
889 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
890 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
891 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
892 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
894 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
897 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
899 if ($winbindd ne "yes") {
900 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
902 print("Skip winbindd received signal $signame");
905 sleep($self->{server_maxtime});
909 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
910 my @optargs = ("-d0");
911 if (defined($ENV{WINBINDD_OPTIONS})) {
912 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
914 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
915 if(defined($ENV{WINBINDD_VALGRIND})) {
916 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
918 my @args = ("-F", "--no-process-group",
919 "-s", $env_vars->{SERVERCONFFILE},
920 "-l", $env_vars->{LOGDIR});
921 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
922 push(@args, "--stdout");
925 close($env_vars->{STDIN_PIPE});
926 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
928 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
929 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
931 $env_vars->{WINBINDD_TL_PID} = $pid;
932 write_pid($env_vars, "winbindd", $pid);
935 unlink($env_vars->{SMBD_TEST_LOG});
936 print "STARTING SMBD...";
939 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
940 open STDERR, '>&STDOUT';
942 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
944 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
945 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
946 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
948 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
949 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
950 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
951 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
952 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
953 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
954 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
955 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
957 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
960 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
962 if ($smbd ne "yes") {
963 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
965 print("Skip smbd received signal $signame");
968 sleep($self->{server_maxtime});
972 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
973 my @optargs = ("-d0");
974 if (defined($ENV{SMBD_OPTIONS})) {
975 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
977 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
978 if(defined($ENV{SMBD_VALGRIND})) {
979 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
981 my @args = ("-F", "--no-process-group",
982 "-s", $env_vars->{SERVERCONFFILE},
983 "-l", $env_vars->{LOGDIR});
984 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
985 push(@args, "--log-stdout");
988 close($env_vars->{STDIN_PIPE});
989 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
991 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
992 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
994 $env_vars->{SMBD_TL_PID} = $pid;
995 write_pid($env_vars, "smbd", $pid);
1000 return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
1003 sub provision($$$$$$$$)
1005 my ($self, $prefix, $server, $password, $extra_options, $dc_server_ip, $dc_server_ipv6, $no_delete_prefix) = @_;
1008 ## setup the various environment variables we need
1011 my $swiface = Samba::get_interface($server);
1013 my $server_ip = "127.0.0.$swiface";
1014 my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
1015 my $domain = "SAMBA-TEST";
1017 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
1020 my $unix_gids_str = $);
1021 my @unix_gids = split(" ", $unix_gids_str);
1023 my $prefix_abs = abs_path($prefix);
1024 my $bindir_abs = abs_path($self->{bindir});
1028 my $shrdir="$prefix_abs/share";
1029 push(@dirs,$shrdir);
1031 my $libdir="$prefix_abs/lib";
1032 push(@dirs,$libdir);
1034 my $piddir="$prefix_abs/pid";
1035 push(@dirs,$piddir);
1037 my $privatedir="$prefix_abs/private";
1038 push(@dirs,$privatedir);
1040 my $lockdir="$prefix_abs/lockdir";
1041 push(@dirs,$lockdir);
1043 my $eventlogdir="$prefix_abs/lockdir/eventlog";
1044 push(@dirs,$eventlogdir);
1046 my $logdir="$prefix_abs/logs";
1047 push(@dirs,$logdir);
1049 my $driver32dir="$shrdir/W32X86";
1050 push(@dirs,$driver32dir);
1052 my $driver64dir="$shrdir/x64";
1053 push(@dirs,$driver64dir);
1055 my $driver40dir="$shrdir/WIN40";
1056 push(@dirs,$driver40dir);
1058 my $ro_shrdir="$shrdir/root-tmp";
1059 push(@dirs,$ro_shrdir);
1061 my $msdfs_shrdir="$shrdir/msdfsshare";
1062 push(@dirs,$msdfs_shrdir);
1064 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
1065 push(@dirs,$msdfs_deeppath);
1067 my $badnames_shrdir="$shrdir/badnames";
1068 push(@dirs,$badnames_shrdir);
1070 my $lease1_shrdir="$shrdir/SMB2_10";
1071 push(@dirs,$lease1_shrdir);
1073 my $lease2_shrdir="$shrdir/SMB3_00";
1074 push(@dirs,$lease2_shrdir);
1076 my $manglenames_shrdir="$shrdir/manglenames";
1077 push(@dirs,$manglenames_shrdir);
1079 # this gets autocreated by winbindd
1080 my $wbsockdir="$prefix_abs/winbindd";
1081 my $wbsockprivdir="$lockdir/winbindd_privileged";
1083 my $nmbdsockdir="$prefix_abs/nmbd";
1084 unlink($nmbdsockdir);
1087 ## create the test directory layout
1089 die ("prefix_abs = ''") if $prefix_abs eq "";
1090 die ("prefix_abs = '/'") if $prefix_abs eq "/";
1092 mkdir($prefix_abs, 0777);
1093 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
1094 if (not defined($no_delete_prefix) or not $no_delete_prefix) {
1095 system("rm -rf $prefix_abs/*");
1097 mkdir($_, 0777) foreach(@dirs);
1099 my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
1102 ## lockdir and piddir must be 0755
1104 chmod 0755, $lockdir;
1105 chmod 0755, $piddir;
1109 ## create ro and msdfs share layout
1112 chmod 0755, $ro_shrdir;
1113 my $unreadable_file = "$ro_shrdir/unreadable_file";
1114 unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
1115 warn("Unable to open $unreadable_file");
1118 close(UNREADABLE_FILE);
1119 chmod 0600, $unreadable_file;
1121 my $msdfs_target = "$ro_shrdir/msdfs-target";
1122 unless (open(MSDFS_TARGET, ">$msdfs_target")) {
1123 warn("Unable to open $msdfs_target");
1126 close(MSDFS_TARGET);
1127 chmod 0666, $msdfs_target;
1128 symlink "msdfs:$server_ip\\ro-tmp,$server_ipv6\\ro-tmp",
1129 "$msdfs_shrdir/msdfs-src1";
1130 symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
1133 ## create bad names in $badnames_shrdir
1135 ## (An invalid name, would be mangled to 8.3).
1136 my $badname_target = "$badnames_shrdir/\340|\231\216\377\177";
1137 unless (open(BADNAME_TARGET, ">$badname_target")) {
1138 warn("Unable to open $badname_target");
1141 close(BADNAME_TARGET);
1142 chmod 0666, $badname_target;
1144 ## (A bad name, would not be mangled to 8.3).
1145 my $badname_target = "$badnames_shrdir/\240\276\346\327\377\177";
1146 unless (open(BADNAME_TARGET, ">$badname_target")) {
1147 warn("Unable to open $badname_target");
1150 close(BADNAME_TARGET);
1151 chmod 0666, $badname_target;
1153 ## (A bad good name).
1154 my $badname_target = "$badnames_shrdir/blank.txt";
1155 unless (open(BADNAME_TARGET, ">$badname_target")) {
1156 warn("Unable to open $badname_target");
1159 close(BADNAME_TARGET);
1160 chmod 0666, $badname_target;
1163 ## create mangleable directory names in $manglenames_shrdir
1165 my $manglename_target = "$manglenames_shrdir/foo:bar";
1166 mkdir($manglename_target, 0777);
1168 my $conffile="$libdir/server.conf";
1170 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
1171 my $nss_wrapper_passwd = "$privatedir/passwd";
1172 my $nss_wrapper_group = "$privatedir/group";
1173 my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
1174 my $resolv_conf = "$privatedir/resolv.conf";
1175 my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
1177 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
1179 my $fake_snap_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/fake_snap.pl";
1181 my @eventlog_list = ("dns server", "application");
1184 ## calculate uids and gids
1187 my ($max_uid, $max_gid);
1188 my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2);
1189 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
1191 if ($unix_uid < 0xffff - 4) {
1194 $max_uid = $unix_uid;
1197 $uid_root = $max_uid - 1;
1198 $uid_nobody = $max_uid - 2;
1199 $uid_pdbtest = $max_uid - 3;
1200 $uid_pdbtest2 = $max_uid - 4;
1202 if ($unix_gids[0] < 0xffff - 5) {
1205 $max_gid = $unix_gids[0];
1208 $gid_nobody = $max_gid - 1;
1209 $gid_nogroup = $max_gid - 2;
1210 $gid_root = $max_gid - 3;
1211 $gid_domusers = $max_gid - 4;
1212 $gid_domadmins = $max_gid - 5;
1218 unless (open(CONF, ">$conffile")) {
1219 warn("Unable to open $conffile");
1224 netbios name = $server
1225 interfaces = $server_ip/8 $server_ipv6/64
1226 bind interfaces only = yes
1227 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
1228 smbd:suicide mode = yes
1232 private dir = $privatedir
1233 pid directory = $piddir
1234 lock directory = $lockdir
1235 log file = $logdir/log.\%m
1240 state directory = $lockdir
1241 cache directory = $lockdir
1243 passdb backend = tdbsam
1247 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1248 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
1249 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1250 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
1251 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1252 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1253 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
1255 addprinter command = $mod_printer_pl -a -s $conffile --
1256 deleteprinter command = $mod_printer_pl -d -s $conffile --
1258 eventlog list = application \"dns server\"
1261 kernel change notify = no
1266 printcap name = /dev/null
1268 winbindd socket directory = $wbsockdir
1269 nmbd:socket dir = $nmbdsockdir
1270 idmap config * : range = 100000-200000
1271 winbind enum users = yes
1272 winbind enum groups = yes
1273 winbind separator = /
1275 # min receivefile size = 4000
1278 server signing = auto
1280 smbd:sharedelay = 100000
1281 smbd:writetimeupdatedelay = 500000
1285 store dos attributes = yes
1289 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1292 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1293 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1294 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1295 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1296 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1297 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1298 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1300 print notify backchannel = yes
1302 ncalrpc dir = $prefix_abs/ncalrpc
1304 # The samba3.blackbox.smbclient_s3 test uses this to test that
1305 # sending messages works, and that the %m sub works.
1306 message command = mv %s $shrdir/message.%m
1308 # fsrvp server requires registry shares
1309 registry shares = yes
1311 # Used by RPC SRVSVC tests
1312 add share command = $bindir_abs/smbaddshare
1313 change share command = $bindir_abs/smbchangeshare
1314 delete share command = $bindir_abs/smbdeleteshare
1316 # fruit:copyfile is a global option
1317 fruit:copyfile = yes
1319 # Begin extra options
1323 #Include user defined custom parameters if set
1326 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1327 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1333 comment = smb username is [%U]
1336 comment = Load dirsort module
1337 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1340 comment = encrypt smb username is [%U]
1341 smb encrypt = required
1342 vfs objects = dirsort
1352 force user = $unix_name
1354 [forceuser_unixonly]
1356 force user = pdbtest
1360 force group = nogroup
1368 write list = $unix_name
1371 valid users = $unix_name
1373 path = $msdfs_shrdir
1375 msdfs shuffle referrals = yes
1379 hide unreadable = yes
1382 case sensitive = yes
1385 hide unwriteable files = yes
1388 kernel share modes = no
1402 default devmode = no
1408 comment = smb username is [%U]
1410 vfs objects = nfs4acl_xattr xattr_tdb
1414 comment = smb username is [%U]
1416 vfs objects = nfs4acl_xattr xattr_tdb
1420 comment = smb username is [%U]
1422 force create mode = 777
1425 comment = smb username is [%U]
1427 force create mode = 0
1428 directory mask = 0777
1429 force directory mode = 0
1430 vfs objects = xattr_tdb
1441 vfs objects = catia fruit streams_xattr
1442 fruit:ressource = file
1443 fruit:metadata = netatalk
1444 fruit:locking = netatalk
1445 fruit:encoding = native
1448 path = $badnames_shrdir
1452 path = $manglenames_shrdir
1461 comment = fake shapshots using rsync
1462 vfs objects = shell_snap shadow_copy2
1463 shell_snap:check path command = $fake_snap_pl --check
1464 shell_snap:create command = $fake_snap_pl --create
1465 shell_snap:delete command = $fake_snap_pl --delete
1466 # a relative path here fails, the snapshot dir is no longer found
1467 shadow:snapdir = $shrdir/.snapshots
1472 ## create a test account
1475 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1476 warn("Unable to open $nss_wrapper_passwd");
1479 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1480 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1481 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1482 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1484 if ($unix_uid != 0) {
1485 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
1490 unless (open(GROUP, ">$nss_wrapper_group")) {
1491 warn("Unable to open $nss_wrapper_group");
1494 print GROUP "nobody:x:$gid_nobody:
1495 nogroup:x:$gid_nogroup:nobody
1496 $unix_name-group:x:$unix_gids[0]:
1497 domusers:X:$gid_domusers:
1498 domadmins:X:$gid_domadmins:
1500 if ($unix_gids[0] != 0) {
1501 print GROUP "root:x:$gid_root:
1508 my $hostname = lc($server);
1509 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
1510 warn("Unable to open $nss_wrapper_hosts");
1513 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n";
1514 print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n";
1518 unless (open(RESOLV_CONF, ">$resolv_conf")) {
1519 warn("Unable to open $resolv_conf");
1522 if (defined($dc_server_ip) or defined($dc_server_ipv6)) {
1523 if (defined($dc_server_ip)) {
1524 print RESOLV_CONF "nameserver $dc_server_ip\n";
1526 if (defined($dc_server_ipv6)) {
1527 print RESOLV_CONF "nameserver $dc_server_ipv6\n";
1530 print RESOLV_CONF "nameserver ${server_ip}\n";
1531 print RESOLV_CONF "nameserver ${server_ipv6}\n";
1535 foreach my $evlog (@eventlog_list) {
1536 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1537 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1541 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1542 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1543 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1544 $ENV{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
1545 if ($ENV{SAMBA_DNS_FAKING}) {
1546 $ENV{RESOLV_WRAPPER_CONF} = $resolv_conf;
1548 $ENV{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
1551 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
1552 unless (open(PWD, "|$cmd")) {
1553 warn("Unable to set password for test account\n$cmd");
1556 print PWD "$password\n$password\n";
1557 unless (close(PWD)) {
1558 warn("Unable to set password for test account\n$cmd");
1563 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1564 print DNS_UPDATE_LIST "A $server. $server_ip\n";
1565 print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
1566 close(DNS_UPDATE_LIST);
1568 $ret{SERVER_IP} = $server_ip;
1569 $ret{SERVER_IPV6} = $server_ipv6;
1570 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1571 $ret{NMBD_TEST_LOG_POS} = 0;
1572 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1573 $ret{WINBINDD_TEST_LOG_POS} = 0;
1574 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1575 $ret{SMBD_TEST_LOG_POS} = 0;
1576 $ret{SERVERCONFFILE} = $conffile;
1577 $ret{CONFIGURATION} ="-s $conffile";
1578 $ret{SERVER} = $server;
1579 $ret{USERNAME} = $unix_name;
1580 $ret{USERID} = $unix_uid;
1581 $ret{DOMAIN} = $domain;
1582 $ret{NETBIOSNAME} = $server;
1583 $ret{PASSWORD} = $password;
1584 $ret{PIDDIR} = $piddir;
1585 $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
1586 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
1587 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1588 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1589 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1590 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1591 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1592 $ret{NSS_WRAPPER_HOSTNAME} = "${hostname}.samba.example.com";
1593 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1594 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
1595 if ($ENV{SAMBA_DNS_FAKING}) {
1596 $ret{RESOLV_WRAPPER_HOSTS} = $dns_host_file;
1598 $ret{RESOLV_WRAPPER_CONF} = $resolv_conf;
1600 $ret{LOCAL_PATH} = "$shrdir";
1601 $ret{LOGDIR} = $logdir;
1606 sub wait_for_start($$$$$)
1608 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1611 if ($nmbd eq "yes") {
1614 # give time for nbt server to register its names
1615 print "checking for nmbd\n";
1617 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
1618 my $nmblookup = Samba::bindir_path($self, "nmblookup");
1621 $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
1625 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
1626 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
1627 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
1628 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
1631 } while ($ret != 0 && $count < 10);
1633 print "NMBD not reachable after 10 retries\n";
1634 teardown_env($self, $envvars);
1639 if ($winbindd eq "yes") {
1640 print "checking for winbindd\n";
1643 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --ping-dc");
1648 } while ($ret != 0 && $count < 10);
1650 print "WINBINDD not reachable after 20 seconds\n";
1651 teardown_env($self, $envvars);
1656 if ($smbd eq "yes") {
1657 # make sure smbd is also up set
1658 print "wait for smbd\n";
1662 $ret = system(Samba::bindir_path($self, "smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
1667 } while ($ret != 0 && $count < 10);
1669 print "SMBD failed to start up in a reasonable time (20sec)\n";
1670 teardown_env($self, $envvars);
1675 # Ensure we have domain users mapped.
1676 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
1680 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
1685 if ($winbindd eq "yes") {
1686 # note: creating builtin groups requires winbindd for the
1688 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
1690 print "Failed to create BUILTIN\\Users group\n";
1695 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
1696 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
1701 } while ($ret != 0 && $count < 10);
1703 print "WINBINDD not reachable after 20 seconds\n";
1704 teardown_env($self, $envvars);
1709 print $self->getlog_env($envvars);