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, $binary_mapping, $srcdir, $server_maxtime) = @_;
53 my $self = { vars => {},
55 binary_mapping => $binary_mapping,
57 server_maxtime => $server_maxtime
65 my ($self, $envvars) = @_;
68 # This should cause smbd to terminate gracefully
69 close($envvars->{STDIN_PIPE});
71 my $smbdpid = $envvars->{SMBD_TL_PID};
72 my $nmbdpid = $envvars->{NMBD_TL_PID};
73 my $winbinddpid = $envvars->{WINBINDD_TL_PID};
75 # This should give it time to write out the gcov data
77 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
78 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
79 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
82 && $winbinddchild == -1) {
89 if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
93 $self->stop_sig_term($smbdpid);
94 $self->stop_sig_term($nmbdpid);
95 $self->stop_sig_term($winbinddpid);
99 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
100 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
101 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
104 && $winbinddchild == -1) {
111 if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
115 warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
116 $self->stop_sig_kill($smbdpid);
117 $self->stop_sig_kill($nmbdpid);
118 $self->stop_sig_kill($winbinddpid);
123 sub getlog_env_app($$$)
125 my ($self, $envvars, $name) = @_;
127 my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
130 open(LOG, "<".$envvars->{$name."_TEST_LOG"});
132 seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
136 $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
139 return "" if $out eq $title;
146 my ($self, $envvars) = @_;
149 $ret .= $self->getlog_env_app($envvars, "SMBD");
150 $ret .= $self->getlog_env_app($envvars, "NMBD");
151 $ret .= $self->getlog_env_app($envvars, "WINBINDD");
158 my ($self, $envvars) = @_;
160 my $childpid = waitpid(-1, WNOHANG);
168 my ($self, $envname, $path) = @_;
170 $ENV{ENVNAME} = $envname;
172 if (defined($self->{vars}->{$envname})) {
173 return $self->{vars}->{$envname};
176 if ($envname eq "s3dc") {
177 return $self->setup_s3dc("$path/s3dc");
178 } elsif ($envname eq "simpleserver") {
179 return $self->setup_simpleserver("$path/simpleserver");
180 } elsif ($envname eq "maptoguest") {
181 return $self->setup_maptoguest("$path/maptoguest");
182 } elsif ($envname eq "ktest") {
183 return $self->setup_ktest("$path/ktest");
184 } elsif ($envname eq "member") {
185 if (not defined($self->{vars}->{s3dc})) {
186 if (not defined($self->setup_s3dc("$path/s3dc"))) {
190 return $self->setup_member("$path/member", $self->{vars}->{s3dc});
198 my ($self, $path) = @_;
200 print "PROVISIONING S3DC...";
207 rpc_server:epmapper = external
208 rpc_server:spoolss = external
209 rpc_server:lsarpc = external
210 rpc_server:samr = external
211 rpc_server:netlogon = external
212 rpc_server:register_embedded_np = yes
214 rpc_daemon:epmd = fork
215 rpc_daemon:spoolssd = fork
216 rpc_daemon:lsasd = fork
219 my $vars = $self->provision($path,
224 $vars or return undef;
226 if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
230 $vars->{DC_SERVER} = $vars->{SERVER};
231 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
232 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
233 $vars->{DC_USERNAME} = $vars->{USERNAME};
234 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
236 $self->{vars}->{s3dc} = $vars;
241 sub setup_member($$$)
243 my ($self, $prefix, $s3dcvars) = @_;
245 print "PROVISIONING MEMBER...";
247 my $member_options = "
251 my $ret = $self->provision($prefix,
256 $ret or return undef;
258 my $net = Samba::bindir_path($self, "net");
260 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
261 $cmd .= "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member";
262 $cmd .= " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}";
264 if (system($cmd) != 0) {
265 warn("Join failed\n$cmd");
269 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
273 $ret->{DC_SERVER} = $s3dcvars->{SERVER};
274 $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
275 $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
276 $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
277 $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
282 sub setup_admember($$$$)
284 my ($self, $prefix, $dcvars) = @_;
286 # If we didn't build with ADS, pretend this env was never available
287 if (not $self->have_ads()) {
291 print "PROVISIONING S3 AD MEMBER...";
293 my $member_options = "
296 workgroup = $dcvars->{DOMAIN}
297 realm = $dcvars->{REALM}
300 my $ret = $self->provision($prefix,
305 $ret or return undef;
308 $ret->{DOMAIN} = $dcvars->{DOMAIN};
309 $ret->{REALM} = $dcvars->{REALM};
312 my $prefix_abs = abs_path($prefix);
314 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
315 $ctx->{domain} = $dcvars->{DOMAIN};
316 $ctx->{realm} = $dcvars->{REALM};
317 $ctx->{dnsname} = lc($dcvars->{REALM});
318 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
319 Samba::mk_krb5_conf($ctx, "");
321 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
323 my $net = Samba::bindir_path($self, "net");
325 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
326 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
327 $cmd .= "$net join $ret->{CONFIGURATION}";
328 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
330 if (system($cmd) != 0) {
331 warn("Join failed\n$cmd");
335 # We need world access to this share, as otherwise the domain
336 # administrator from the AD domain provided by Samba4 can't
337 # access the share for tests.
338 chmod 0777, "$prefix/share";
340 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
344 $ret->{DC_SERVER} = $dcvars->{SERVER};
345 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
346 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
347 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
348 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
350 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
351 $ret->{target} = $self;
356 sub setup_admember_rfc2307($$$$)
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 WITH idmap_rfc2307 config...";
367 my $member_options = "
370 workgroup = $dcvars->{DOMAIN}
371 realm = $dcvars->{REALM}
372 idmap config $dcvars->{DOMAIN} : backend = rfc2307
373 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
374 idmap config $dcvars->{DOMAIN} : ldap_server = ad
375 idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
376 idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
379 my $ret = $self->provision($prefix,
384 $ret or return undef;
387 $ret->{DOMAIN} = $dcvars->{DOMAIN};
388 $ret->{REALM} = $dcvars->{REALM};
391 my $prefix_abs = abs_path($prefix);
393 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
394 $ctx->{domain} = $dcvars->{DOMAIN};
395 $ctx->{realm} = $dcvars->{REALM};
396 $ctx->{dnsname} = lc($dcvars->{REALM});
397 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
398 Samba::mk_krb5_conf($ctx, "");
400 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
402 my $net = Samba::bindir_path($self, "net");
404 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
405 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
406 $cmd .= "$net join $ret->{CONFIGURATION}";
407 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
409 if (system($cmd) != 0) {
410 warn("Join failed\n$cmd");
414 # We need world access to this share, as otherwise the domain
415 # administrator from the AD domain provided by Samba4 can't
416 # access the share for tests.
417 chmod 0777, "$prefix/share";
419 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
423 $ret->{DC_SERVER} = $dcvars->{SERVER};
424 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
425 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
426 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
427 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
429 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
430 $ret->{target} = $self;
435 sub setup_simpleserver($$)
437 my ($self, $path) = @_;
439 print "PROVISIONING server with security=share...";
441 my $prefix_abs = abs_path($path);
443 my $simpleserver_options = "
445 vfs objects = xattr_tdb streams_depot
448 path = $prefix_abs/share
449 vfs objects = aio_fork
451 vfs_aio_fork:erratic_testing_mode=yes
454 my $vars = $self->provision($path,
457 $simpleserver_options);
459 $vars or return undef;
461 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
465 $self->{vars}->{simpleserver} = $vars;
472 my ($self, $prefix) = @_;
474 # If we didn't build with ADS, pretend this env was never available
475 if (not $self->have_ads()) {
479 print "PROVISIONING server with security=ads...";
481 my $ktest_options = "
483 realm = ktest.samba.example.com
485 username map = $prefix/lib/username.map
486 server signing = required
489 my $ret = $self->provision($prefix,
494 $ret or return undef;
497 my $prefix_abs = abs_path($prefix);
499 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
500 $ctx->{domain} = "KTEST";
501 $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
502 $ctx->{dnsname} = lc($ctx->{realm});
503 $ctx->{kdc_ipv4} = "0.0.0.0";
504 Samba::mk_krb5_conf($ctx, "");
506 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
508 open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
510 $ret->{USERNAME} = KTEST\\Administrator
514 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
515 #Samba4 DC with the same parameters as are being used here. The
516 #domain SID is S-1-5-21-1071277805-689288055-3486227160
518 system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
519 chmod 0600, "$prefix/private/secrets.tdb";
521 #Make sure there's no old ntdb file.
522 system("rm -f $prefix/private/secrets.ntdb");
524 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
525 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
527 #and having in krb5.conf:
528 # ticket_lifetime = 799718400
529 # renew_lifetime = 799718400
531 # The commands for the -2 keytab where were:
532 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
533 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
534 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
535 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
536 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
538 # and then for the -3 keytab, I did
540 # net changetrustpw; kdestroy and the same again.
542 # This creates a credential cache with a very long lifetime (2036 at
543 # at 2011-04), and shows that running 'net changetrustpw' does not
544 # break existing logins (for the secrets.tdb method at least).
547 $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
549 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
550 chmod 0600, "$prefix/krb5_ccache-2";
552 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
553 chmod 0600, "$prefix/krb5_ccache-3";
555 # We need world access to this share, as otherwise the domain
556 # administrator from the AD domain provided by ktest can't
557 # access the share for tests.
558 chmod 0777, "$prefix/share";
560 if (not $self->check_or_start($ret, "yes", "no", "yes")) {
566 sub setup_maptoguest($$)
568 my ($self, $path) = @_;
570 print "PROVISIONING maptoguest...";
573 map to guest = bad user
576 my $vars = $self->provision($path,
581 $vars or return undef;
583 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
587 $self->{vars}->{s3maptoguest} = $vars;
592 sub stop_sig_term($$) {
593 my ($self, $pid) = @_;
594 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
597 sub stop_sig_kill($$) {
598 my ($self, $pid) = @_;
599 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
604 my ($env_vars, $app, $pid) = @_;
606 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
613 my ($env_vars, $app) = @_;
615 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
621 sub check_or_start($$$$$) {
622 my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
624 # use a pipe for stdin in the child processes. This allows
625 # those processes to monitor the pipe for EOF to ensure they
626 # exit when the test script exits
627 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
629 unlink($env_vars->{NMBD_TEST_LOG});
630 print "STARTING NMBD...";
633 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
634 open STDERR, '>&STDOUT';
636 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
638 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
639 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
640 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
642 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
643 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
644 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
645 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
646 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
648 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
650 if ($nmbd ne "yes") {
651 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
653 print("Skip nmbd received signal $signame");
656 sleep($self->{server_maxtime});
660 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
661 my @optargs = ("-d0");
662 if (defined($ENV{NMBD_OPTIONS})) {
663 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
665 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
666 if(defined($ENV{NMBD_VALGRIND})) {
667 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
669 my @args = ("-F", "--no-process-group",
670 "-s", $env_vars->{SERVERCONFFILE},
671 "-l", $env_vars->{LOGDIR});
672 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
673 push(@args, "--log-stdout");
676 close($env_vars->{STDIN_PIPE});
677 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
679 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
680 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
682 $env_vars->{NMBD_TL_PID} = $pid;
683 write_pid($env_vars, "nmbd", $pid);
686 unlink($env_vars->{WINBINDD_TEST_LOG});
687 print "STARTING WINBINDD...";
690 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
691 open STDERR, '>&STDOUT';
693 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
695 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
696 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
697 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
699 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
700 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
701 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
702 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
703 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
705 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
707 if ($winbindd ne "yes") {
708 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
710 print("Skip winbindd received signal $signame");
713 sleep($self->{server_maxtime});
717 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
718 my @optargs = ("-d0");
719 if (defined($ENV{WINBINDD_OPTIONS})) {
720 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
722 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
723 if(defined($ENV{WINBINDD_VALGRIND})) {
724 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
726 my @args = ("-F", "--no-process-group",
727 "-s", $env_vars->{SERVERCONFFILE},
728 "-l", $env_vars->{LOGDIR});
729 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
730 push(@args, "--stdout");
733 close($env_vars->{STDIN_PIPE});
734 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
736 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
737 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
739 $env_vars->{WINBINDD_TL_PID} = $pid;
740 write_pid($env_vars, "winbindd", $pid);
743 unlink($env_vars->{SMBD_TEST_LOG});
744 print "STARTING SMBD...";
747 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
748 open STDERR, '>&STDOUT';
750 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
752 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
753 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
754 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
756 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
757 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
758 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
759 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
760 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
762 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
764 if ($smbd ne "yes") {
765 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
767 print("Skip smbd received signal $signame");
770 sleep($self->{server_maxtime});
774 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
775 my @optargs = ("-d0");
776 if (defined($ENV{SMBD_OPTIONS})) {
777 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
779 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
780 if(defined($ENV{SMBD_VALGRIND})) {
781 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
783 my @args = ("-F", "--no-process-group",
784 "-s", $env_vars->{SERVERCONFFILE},
785 "-l", $env_vars->{LOGDIR});
786 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
787 push(@args, "--log-stdout");
790 close($env_vars->{STDIN_PIPE});
791 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
793 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
794 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
796 $env_vars->{SMBD_TL_PID} = $pid;
797 write_pid($env_vars, "smbd", $pid);
802 return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
805 sub provision($$$$$$)
807 my ($self, $prefix, $server, $password, $extra_options, $no_delete_prefix) = @_;
810 ## setup the various environment variables we need
813 my $swiface = Samba::get_interface($server);
815 my $server_ip = "127.0.0.$swiface";
816 my $domain = "SAMBA-TEST";
818 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
821 my $unix_gids_str = $);
822 my @unix_gids = split(" ", $unix_gids_str);
824 my $prefix_abs = abs_path($prefix);
825 my $bindir_abs = abs_path($self->{bindir});
827 my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
831 my $shrdir="$prefix_abs/share";
834 my $libdir="$prefix_abs/lib";
837 my $piddir="$prefix_abs/pid";
840 my $privatedir="$prefix_abs/private";
841 push(@dirs,$privatedir);
843 my $lockdir="$prefix_abs/lockdir";
844 push(@dirs,$lockdir);
846 my $eventlogdir="$prefix_abs/lockdir/eventlog";
847 push(@dirs,$eventlogdir);
849 my $logdir="$prefix_abs/logs";
852 my $driver32dir="$shrdir/W32X86";
853 push(@dirs,$driver32dir);
855 my $driver64dir="$shrdir/x64";
856 push(@dirs,$driver64dir);
858 my $driver40dir="$shrdir/WIN40";
859 push(@dirs,$driver40dir);
861 my $ro_shrdir="$shrdir/root-tmp";
862 push(@dirs,$ro_shrdir);
864 my $msdfs_shrdir="$shrdir/msdfsshare";
865 push(@dirs,$msdfs_shrdir);
867 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
868 push(@dirs,$msdfs_deeppath);
870 # this gets autocreated by winbindd
871 my $wbsockdir="$prefix_abs/winbindd";
872 my $wbsockprivdir="$lockdir/winbindd_privileged";
874 my $nmbdsockdir="$prefix_abs/nmbd";
875 unlink($nmbdsockdir);
877 my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
880 ## create the test directory layout
882 die ("prefix_abs = ''") if $prefix_abs eq "";
883 die ("prefix_abs = '/'") if $prefix_abs eq "/";
885 mkdir($prefix_abs, 0777);
886 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
887 if (not defined($no_delete_prefix) or not $no_delete_prefix) {
888 system("rm -rf $prefix_abs/*");
890 mkdir($_, 0777) foreach(@dirs);
893 ## lockdir and piddir must be 0755
895 chmod 0755, $lockdir;
900 ## create ro and msdfs share layout
903 chmod 0755, $ro_shrdir;
904 my $unreadable_file = "$ro_shrdir/unreadable_file";
905 unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
906 warn("Unable to open $unreadable_file");
909 close(UNREADABLE_FILE);
910 chmod 0600, $unreadable_file;
912 my $msdfs_target = "$ro_shrdir/msdfs-target";
913 unless (open(MSDFS_TARGET, ">$msdfs_target")) {
914 warn("Unable to open $msdfs_target");
918 chmod 0666, $msdfs_target;
919 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
920 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
922 my $conffile="$libdir/server.conf";
924 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
925 my $nss_wrapper_passwd = "$privatedir/passwd";
926 my $nss_wrapper_group = "$privatedir/group";
927 my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
929 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
931 my @eventlog_list = ("dns server", "application");
934 ## calculate uids and gids
937 my ($max_uid, $max_gid);
938 my ($uid_nobody, $uid_root, $uid_pdbtest);
939 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
941 if ($unix_uid < 0xffff - 2) {
944 $max_uid = $unix_uid;
947 $uid_root = $max_uid - 1;
948 $uid_nobody = $max_uid - 2;
949 $uid_pdbtest = $max_uid - 3;
951 if ($unix_gids[0] < 0xffff - 3) {
954 $max_gid = $unix_gids[0];
957 $gid_nobody = $max_gid - 1;
958 $gid_nogroup = $max_gid - 2;
959 $gid_root = $max_gid - 3;
960 $gid_domusers = $max_gid - 4;
961 $gid_domadmins = $max_gid - 5;
967 unless (open(CONF, ">$conffile")) {
968 warn("Unable to open $conffile");
973 netbios name = $server
974 interfaces = $server_ip/8
975 bind interfaces only = yes
976 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
977 smbd:suicide mode = yes
981 private dir = $privatedir
982 pid directory = $piddir
983 lock directory = $lockdir
984 log file = $logdir/log.\%m
989 state directory = $lockdir
990 cache directory = $lockdir
992 passdb backend = tdbsam
996 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
997 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
998 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
999 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
1000 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1001 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1002 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
1004 addprinter command = $mod_printer_pl -a -s $conffile --
1005 deleteprinter command = $mod_printer_pl -d -s $conffile --
1007 eventlog list = application \"dns server\"
1010 kernel change notify = no
1014 printcap name = /dev/null
1016 winbindd socket directory = $wbsockdir
1017 nmbd:socket dir = $nmbdsockdir
1018 idmap config * : range = 100000-200000
1019 winbind enum users = yes
1020 winbind enum groups = yes
1022 # min receivefile size = 4000
1025 server signing = auto
1027 smbd:sharedelay = 100000
1028 smbd:writetimeupdatedelay = 500000
1032 store dos attributes = yes
1035 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1038 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1039 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1040 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1041 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1042 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1043 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1044 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1046 print notify backchannel = yes
1048 ncalrpc dir = $prefix_abs/ncalrpc
1049 resolv:host file = $dns_host_file
1051 # The samba3.blackbox.smbclient_s3 test uses this to test that
1052 # sending messages works, and that the %m sub works.
1053 message command = mv %s $shrdir/message.%m
1055 # Begin extra options
1059 #Include user defined custom parameters if set
1062 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1063 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1069 comment = smb username is [%U]
1072 comment = Load dirsort module
1073 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1076 comment = encrypt smb username is [%U]
1077 smb encrypt = required
1078 vfs objects = dirsort
1088 force user = $unix_name
1092 force group = nogroup
1100 write list = $unix_name
1103 valid users = $unix_name
1105 path = $msdfs_shrdir
1110 hide unreadable = yes
1113 case sensitive = yes
1116 hide unwriteable files = yes
1119 kernel share modes = no
1133 default devmode = no
1139 comment = smb username is [%U]
1141 vfs objects = nfs4acl_xattr xattr_tdb
1145 comment = smb username is [%U]
1147 vfs objects = nfs4acl_xattr xattr_tdb
1151 comment = smb username is [%U]
1153 force create mode = 777
1156 comment = smb username is [%U]
1158 force create mode = 0
1159 directory mask = 0777
1160 force directory mode = 0
1161 vfs objects = xattr_tdb
1173 ## create a test account
1176 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1177 warn("Unable to open $nss_wrapper_passwd");
1180 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1181 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1182 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1184 if ($unix_uid != 0) {
1185 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
1190 unless (open(GROUP, ">$nss_wrapper_group")) {
1191 warn("Unable to open $nss_wrapper_group");
1194 print GROUP "nobody:x:$gid_nobody:
1195 nogroup:x:$gid_nogroup:nobody
1196 $unix_name-group:x:$unix_gids[0]:
1197 domusers:X:$gid_domusers:
1198 domadmins:X:$gid_domadmins:
1200 if ($unix_gids[0] != 0) {
1201 print GROUP "root:x:$gid_root:
1208 my $hostname = lc($server);
1209 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
1210 warn("Unable to open $nss_wrapper_hosts");
1213 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}
1218 foreach my $evlog (@eventlog_list) {
1219 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1220 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1224 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1225 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1226 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1228 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
1229 unless (open(PWD, "|$cmd")) {
1230 warn("Unable to set password for test account\n$cmd");
1233 print PWD "$password\n$password\n";
1234 unless (close(PWD)) {
1235 warn("Unable to set password for test account\n$cmd");
1240 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1241 print DNS_UPDATE_LIST "A $server. $server_ip";
1242 close(DNS_UPDATE_LIST);
1244 if (system("$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$dns_host_file -s $conffile --update-list=$prefix/dns_update_list --no-substiutions --no-credentials") != 0) {
1245 die "Unable to update hostname into $dns_host_file";
1248 $ret{SERVER_IP} = $server_ip;
1249 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1250 $ret{NMBD_TEST_LOG_POS} = 0;
1251 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1252 $ret{WINBINDD_TEST_LOG_POS} = 0;
1253 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1254 $ret{SMBD_TEST_LOG_POS} = 0;
1255 $ret{SERVERCONFFILE} = $conffile;
1256 $ret{CONFIGURATION} ="-s $conffile";
1257 $ret{SERVER} = $server;
1258 $ret{USERNAME} = $unix_name;
1259 $ret{USERID} = $unix_uid;
1260 $ret{DOMAIN} = $domain;
1261 $ret{NETBIOSNAME} = $server;
1262 $ret{PASSWORD} = $password;
1263 $ret{PIDDIR} = $piddir;
1264 $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
1265 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
1266 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1267 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1268 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1269 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1270 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1271 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1272 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
1273 $ret{LOCAL_PATH} = "$shrdir";
1274 $ret{LOGDIR} = $logdir;
1279 sub wait_for_start($$$$$)
1281 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1284 if ($nmbd eq "yes") {
1285 # give time for nbt server to register its names
1286 print "delaying for nbt name registration\n";
1288 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
1289 my $nmblookup = Samba::bindir_path($self, "nmblookup3");
1290 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
1291 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
1292 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
1293 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
1294 system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
1297 if ($winbindd eq "yes") {
1298 print "checking for winbindd\n";
1301 $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " -p");
1306 } while ($ret != 0 && $count < 10);
1308 print "WINBINDD not reachable after 20 seconds\n";
1309 teardown_env($self, $envvars);
1314 if ($smbd eq "yes") {
1315 # make sure smbd is also up set
1316 print "wait for smbd\n";
1320 $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
1325 } while ($ret != 0 && $count < 10);
1327 print "SMBD failed to start up in a reasonable time (20sec)\n";
1328 teardown_env($self, $envvars);
1333 # Ensure we have domain users mapped.
1334 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
1338 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
1343 if ($winbindd eq "yes") {
1344 # note: creating builtin groups requires winbindd for the
1346 $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
1348 print "Failed to create BUILTIN\\Users group\n";
1353 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
1354 $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
1359 } while ($ret != 0 && $count < 10);
1361 print "WINBINDD not reachable after 20 seconds\n";
1362 teardown_env($self, $envvars);
1367 print $self->getlog_env($envvars);