selftest: Ensure winbindd is fully operating before running tests
[Samba/wip.git] / selftest / target / Samba3.pm
blob59ad4d5dcbb942fd3e055435500a993e37e32ba8
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
6 package Samba3;
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12 use target::Samba;
14 sub have_ads($) {
15 my ($self) = @_;
16 my $found_ads = 0;
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: $!");
20 while (<IN>) {
21 if (/WITH_ADS/) {
22 $found_ads = 1;
25 close IN;
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;
29 return $found_ads;
32 # return smb.conf parameters applicable to @path, based on the underlying
33 # filesystem type
34 sub get_fs_specific_conf($$)
36 my ($self, $path) = @_;
37 my $mods = "";
38 my $stat_out = `stat --file-system $path` or return "";
40 if ($stat_out =~ m/Type:\s+btrfs/) {
41 $mods .= "btrfs ";
44 if ($mods) {
45 return "vfs objects = $mods";
48 return undef;
51 sub new($$) {
52 my ($classname, $bindir, $binary_mapping, $srcdir, $server_maxtime) = @_;
53 my $self = { vars => {},
54 bindir => $bindir,
55 binary_mapping => $binary_mapping,
56 srcdir => $srcdir,
57 server_maxtime => $server_maxtime
59 bless $self;
60 return $self;
63 sub teardown_env($$)
65 my ($self, $envvars) = @_;
66 my $count = 0;
68 # This should cause smbd to terminate gracefully
69 close($envvars->{STDIN_PIPE});
71 my $smbdpid = $envvars->{SMBD_TL_PID};
72 my $nmbdpid = $envvars->{NMBD_TL_PID};
73 my $winbinddpid = $envvars->{WINBINDD_TL_PID};
75 # This should give it time to write out the gcov data
76 until ($count > 20) {
77 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
78 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
79 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
80 if ($smbdchild == -1
81 && $nmbdchild == -1
82 && $winbinddchild == -1) {
83 last;
85 sleep(1);
86 $count++;
89 if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
90 return;
93 $self->stop_sig_term($smbdpid);
94 $self->stop_sig_term($nmbdpid);
95 $self->stop_sig_term($winbinddpid);
97 $count = 0;
98 until ($count > 10) {
99 my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
100 my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
101 my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
102 if ($smbdchild == -1
103 && $nmbdchild == -1
104 && $winbinddchild == -1) {
105 last;
107 sleep(1);
108 $count++;
111 if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
112 return;
115 warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
116 $self->stop_sig_kill($smbdpid);
117 $self->stop_sig_kill($nmbdpid);
118 $self->stop_sig_kill($winbinddpid);
120 return 0;
123 sub getlog_env_app($$$)
125 my ($self, $envvars, $name) = @_;
127 my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
128 my $out = $title;
130 open(LOG, "<".$envvars->{$name."_TEST_LOG"});
132 seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
133 while (<LOG>) {
134 $out .= $_;
136 $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
137 close(LOG);
139 return "" if $out eq $title;
141 return $out;
144 sub getlog_env($$)
146 my ($self, $envvars) = @_;
147 my $ret = "";
149 $ret .= $self->getlog_env_app($envvars, "SMBD");
150 $ret .= $self->getlog_env_app($envvars, "NMBD");
151 $ret .= $self->getlog_env_app($envvars, "WINBINDD");
153 return $ret;
156 sub check_env($$)
158 my ($self, $envvars) = @_;
160 my $childpid = waitpid(-1, WNOHANG);
162 # TODO ...
163 return 1;
166 sub setup_env($$$)
168 my ($self, $envname, $path) = @_;
170 $ENV{ENVNAME} = $envname;
172 if (defined($self->{vars}->{$envname})) {
173 return $self->{vars}->{$envname};
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"))) {
187 return undef;
190 return $self->setup_member("$path/member", $self->{vars}->{s3dc});
191 } else {
192 return "UNKNOWN";
196 sub setup_s3dc($$)
198 my ($self, $path) = @_;
200 print "PROVISIONING S3DC...";
202 my $s3dc_options = "
203 domain master = yes
204 domain logons = yes
205 lanman auth = yes
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,
220 "LOCALS3DC2",
221 "locals3dc2pass",
222 $s3dc_options);
224 $vars or return undef;
226 if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
227 return undef;
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;
238 return $vars;
241 sub setup_member($$$)
243 my ($self, $prefix, $s3dcvars) = @_;
245 print "PROVISIONING MEMBER...";
247 my $member_options = "
248 security = domain
249 server signing = on
250 dbwrap_tdb_mutexes:* = yes
252 my $ret = $self->provision($prefix,
253 "LOCALMEMBER3",
254 "localmember3pass",
255 $member_options);
257 $ret or return undef;
259 my $net = Samba::bindir_path($self, "net");
260 my $cmd = "";
261 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
262 $cmd .= "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member";
263 $cmd .= " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}";
265 if (system($cmd) != 0) {
266 warn("Join failed\n$cmd");
267 return undef;
270 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
271 return undef;
274 $ret->{DC_SERVER} = $s3dcvars->{SERVER};
275 $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
276 $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
277 $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
278 $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
280 return $ret;
283 sub setup_admember($$$$)
285 my ($self, $prefix, $dcvars) = @_;
287 # If we didn't build with ADS, pretend this env was never available
288 if (not $self->have_ads()) {
289 return "UNKNOWN";
292 print "PROVISIONING S3 AD MEMBER...";
294 my $member_options = "
295 security = ads
296 server signing = on
297 workgroup = $dcvars->{DOMAIN}
298 realm = $dcvars->{REALM}
301 my $ret = $self->provision($prefix,
302 "LOCALADMEMBER",
303 "loCalMemberPass",
304 $member_options);
306 $ret or return undef;
308 close(USERMAP);
309 $ret->{DOMAIN} = $dcvars->{DOMAIN};
310 $ret->{REALM} = $dcvars->{REALM};
312 my $ctx;
313 my $prefix_abs = abs_path($prefix);
314 $ctx = {};
315 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
316 $ctx->{domain} = $dcvars->{DOMAIN};
317 $ctx->{realm} = $dcvars->{REALM};
318 $ctx->{dnsname} = lc($dcvars->{REALM});
319 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
320 Samba::mk_krb5_conf($ctx, "");
322 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
324 my $net = Samba::bindir_path($self, "net");
325 my $cmd = "";
326 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
327 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
328 $cmd .= "$net join $ret->{CONFIGURATION}";
329 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
331 if (system($cmd) != 0) {
332 warn("Join failed\n$cmd");
333 return undef;
336 # We need world access to this share, as otherwise the domain
337 # administrator from the AD domain provided by Samba4 can't
338 # access the share for tests.
339 chmod 0777, "$prefix/share";
341 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
342 return undef;
345 $ret->{DC_SERVER} = $dcvars->{SERVER};
346 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
347 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
348 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
349 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
351 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
352 $ret->{target} = $self;
354 return $ret;
357 sub setup_admember_rfc2307($$$$)
359 my ($self, $prefix, $dcvars) = @_;
361 # If we didn't build with ADS, pretend this env was never available
362 if (not $self->have_ads()) {
363 return "UNKNOWN";
366 print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
368 my $member_options = "
369 security = ads
370 server signing = on
371 workgroup = $dcvars->{DOMAIN}
372 realm = $dcvars->{REALM}
373 idmap config $dcvars->{DOMAIN} : backend = rfc2307
374 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
375 idmap config $dcvars->{DOMAIN} : ldap_server = ad
376 idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
377 idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
380 my $ret = $self->provision($prefix,
381 "RFC2307MEMBER",
382 "loCalMemberPass",
383 $member_options);
385 $ret or return undef;
387 close(USERMAP);
388 $ret->{DOMAIN} = $dcvars->{DOMAIN};
389 $ret->{REALM} = $dcvars->{REALM};
391 my $ctx;
392 my $prefix_abs = abs_path($prefix);
393 $ctx = {};
394 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
395 $ctx->{domain} = $dcvars->{DOMAIN};
396 $ctx->{realm} = $dcvars->{REALM};
397 $ctx->{dnsname} = lc($dcvars->{REALM});
398 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
399 Samba::mk_krb5_conf($ctx, "");
401 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
403 my $net = Samba::bindir_path($self, "net");
404 my $cmd = "";
405 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
406 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
407 $cmd .= "$net join $ret->{CONFIGURATION}";
408 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
410 if (system($cmd) != 0) {
411 warn("Join failed\n$cmd");
412 return undef;
415 # We need world access to this share, as otherwise the domain
416 # administrator from the AD domain provided by Samba4 can't
417 # access the share for tests.
418 chmod 0777, "$prefix/share";
420 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
421 return undef;
424 $ret->{DC_SERVER} = $dcvars->{SERVER};
425 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
426 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
427 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
428 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
430 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
431 $ret->{target} = $self;
433 return $ret;
436 sub setup_simpleserver($$)
438 my ($self, $path) = @_;
440 print "PROVISIONING server with security=share...";
442 my $prefix_abs = abs_path($path);
444 my $simpleserver_options = "
445 lanman auth = yes
446 vfs objects = xattr_tdb streams_depot
448 [vfs_aio_fork]
449 path = $prefix_abs/share
450 vfs objects = aio_fork
451 read only = no
452 vfs_aio_fork:erratic_testing_mode=yes
455 my $vars = $self->provision($path,
456 "LOCALSHARE4",
457 "local4pass",
458 $simpleserver_options);
460 $vars or return undef;
462 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
463 return undef;
466 $self->{vars}->{simpleserver} = $vars;
468 return $vars;
471 sub setup_ktest($$$)
473 my ($self, $prefix) = @_;
475 # If we didn't build with ADS, pretend this env was never available
476 if (not $self->have_ads()) {
477 return "UNKNOWN";
480 print "PROVISIONING server with security=ads...";
482 my $ktest_options = "
483 workgroup = KTEST
484 realm = ktest.samba.example.com
485 security = ads
486 username map = $prefix/lib/username.map
487 server signing = required
490 my $ret = $self->provision($prefix,
491 "LOCALKTEST6",
492 "localktest6pass",
493 $ktest_options);
495 $ret or return undef;
497 my $ctx;
498 my $prefix_abs = abs_path($prefix);
499 $ctx = {};
500 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
501 $ctx->{domain} = "KTEST";
502 $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
503 $ctx->{dnsname} = lc($ctx->{realm});
504 $ctx->{kdc_ipv4} = "0.0.0.0";
505 Samba::mk_krb5_conf($ctx, "");
507 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
509 open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
510 print USERMAP "
511 $ret->{USERNAME} = KTEST\\Administrator
513 close(USERMAP);
515 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
516 #Samba4 DC with the same parameters as are being used here. The
517 #domain SID is S-1-5-21-1071277805-689288055-3486227160
519 system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
520 chmod 0600, "$prefix/private/secrets.tdb";
522 #Make sure there's no old ntdb file.
523 system("rm -f $prefix/private/secrets.ntdb");
525 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
526 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
528 #and having in krb5.conf:
529 # ticket_lifetime = 799718400
530 # renew_lifetime = 799718400
532 # The commands for the -2 keytab where were:
533 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
534 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
535 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
536 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
537 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
539 # and then for the -3 keytab, I did
541 # net changetrustpw; kdestroy and the same again.
543 # This creates a credential cache with a very long lifetime (2036 at
544 # at 2011-04), and shows that running 'net changetrustpw' does not
545 # break existing logins (for the secrets.tdb method at least).
548 $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
550 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
551 chmod 0600, "$prefix/krb5_ccache-2";
553 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
554 chmod 0600, "$prefix/krb5_ccache-3";
556 # We need world access to this share, as otherwise the domain
557 # administrator from the AD domain provided by ktest can't
558 # access the share for tests.
559 chmod 0777, "$prefix/share";
561 if (not $self->check_or_start($ret, "yes", "no", "yes")) {
562 return undef;
564 return $ret;
567 sub setup_maptoguest($$)
569 my ($self, $path) = @_;
571 print "PROVISIONING maptoguest...";
573 my $options = "
574 map to guest = bad user
577 my $vars = $self->provision($path,
578 "maptoguest",
579 "maptoguestpass",
580 $options);
582 $vars or return undef;
584 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
585 return undef;
588 $self->{vars}->{s3maptoguest} = $vars;
590 return $vars;
593 sub stop_sig_term($$) {
594 my ($self, $pid) = @_;
595 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
598 sub stop_sig_kill($$) {
599 my ($self, $pid) = @_;
600 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
603 sub write_pid($$$)
605 my ($env_vars, $app, $pid) = @_;
607 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
608 print PID $pid;
609 close(PID);
612 sub read_pid($$)
614 my ($env_vars, $app) = @_;
616 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
617 my $pid = <PID>;
618 close(PID);
619 return $pid;
622 sub check_or_start($$$$$) {
623 my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
625 # use a pipe for stdin in the child processes. This allows
626 # those processes to monitor the pipe for EOF to ensure they
627 # exit when the test script exits
628 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
630 unlink($env_vars->{NMBD_TEST_LOG});
631 print "STARTING NMBD...";
632 my $pid = fork();
633 if ($pid == 0) {
634 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
635 open STDERR, '>&STDOUT';
637 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
639 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
640 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
641 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
643 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
644 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
645 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
646 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
647 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
649 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
651 if ($nmbd ne "yes") {
652 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
653 my $signame = shift;
654 print("Skip nmbd received signal $signame");
655 exit 0;
657 sleep($self->{server_maxtime});
658 exit 0;
661 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
662 my @optargs = ("-d0");
663 if (defined($ENV{NMBD_OPTIONS})) {
664 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
666 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
667 if(defined($ENV{NMBD_VALGRIND})) {
668 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
670 my @args = ("-F", "--no-process-group",
671 "-s", $env_vars->{SERVERCONFFILE},
672 "-l", $env_vars->{LOGDIR});
673 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
674 push(@args, "--log-stdout");
677 close($env_vars->{STDIN_PIPE});
678 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
680 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
681 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
683 $env_vars->{NMBD_TL_PID} = $pid;
684 write_pid($env_vars, "nmbd", $pid);
685 print "DONE\n";
687 unlink($env_vars->{WINBINDD_TEST_LOG});
688 print "STARTING WINBINDD...";
689 $pid = fork();
690 if ($pid == 0) {
691 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
692 open STDERR, '>&STDOUT';
694 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
696 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
697 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
698 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
700 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
701 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
702 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
703 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
704 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
706 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
708 if ($winbindd ne "yes") {
709 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
710 my $signame = shift;
711 print("Skip winbindd received signal $signame");
712 exit 0;
714 sleep($self->{server_maxtime});
715 exit 0;
718 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
719 my @optargs = ("-d0");
720 if (defined($ENV{WINBINDD_OPTIONS})) {
721 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
723 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
724 if(defined($ENV{WINBINDD_VALGRIND})) {
725 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
727 my @args = ("-F", "--no-process-group",
728 "-s", $env_vars->{SERVERCONFFILE},
729 "-l", $env_vars->{LOGDIR});
730 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
731 push(@args, "--stdout");
734 close($env_vars->{STDIN_PIPE});
735 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
737 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
738 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
740 $env_vars->{WINBINDD_TL_PID} = $pid;
741 write_pid($env_vars, "winbindd", $pid);
742 print "DONE\n";
744 unlink($env_vars->{SMBD_TEST_LOG});
745 print "STARTING SMBD...";
746 $pid = fork();
747 if ($pid == 0) {
748 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
749 open STDERR, '>&STDOUT';
751 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
753 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
754 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
755 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
757 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
758 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
759 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
760 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
761 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
763 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
765 if ($smbd ne "yes") {
766 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
767 my $signame = shift;
768 print("Skip smbd received signal $signame");
769 exit 0;
771 sleep($self->{server_maxtime});
772 exit 0;
775 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
776 my @optargs = ("-d0");
777 if (defined($ENV{SMBD_OPTIONS})) {
778 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
780 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
781 if(defined($ENV{SMBD_VALGRIND})) {
782 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
784 my @args = ("-F", "--no-process-group",
785 "-s", $env_vars->{SERVERCONFFILE},
786 "-l", $env_vars->{LOGDIR});
787 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
788 push(@args, "--log-stdout");
791 close($env_vars->{STDIN_PIPE});
792 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
794 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
795 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
797 $env_vars->{SMBD_TL_PID} = $pid;
798 write_pid($env_vars, "smbd", $pid);
799 print "DONE\n";
801 close(STDIN_READER);
803 return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
806 sub provision($$$$$$)
808 my ($self, $prefix, $server, $password, $extra_options, $no_delete_prefix) = @_;
811 ## setup the various environment variables we need
814 my $swiface = Samba::get_interface($server);
815 my %ret = ();
816 my $server_ip = "127.0.0.$swiface";
817 my $domain = "SAMBA-TEST";
819 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
820 chomp $unix_name;
821 my $unix_uid = $>;
822 my $unix_gids_str = $);
823 my @unix_gids = split(" ", $unix_gids_str);
825 my $prefix_abs = abs_path($prefix);
826 my $bindir_abs = abs_path($self->{bindir});
828 my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
830 my @dirs = ();
832 my $shrdir="$prefix_abs/share";
833 push(@dirs,$shrdir);
835 my $libdir="$prefix_abs/lib";
836 push(@dirs,$libdir);
838 my $piddir="$prefix_abs/pid";
839 push(@dirs,$piddir);
841 my $privatedir="$prefix_abs/private";
842 push(@dirs,$privatedir);
844 my $lockdir="$prefix_abs/lockdir";
845 push(@dirs,$lockdir);
847 my $eventlogdir="$prefix_abs/lockdir/eventlog";
848 push(@dirs,$eventlogdir);
850 my $logdir="$prefix_abs/logs";
851 push(@dirs,$logdir);
853 my $driver32dir="$shrdir/W32X86";
854 push(@dirs,$driver32dir);
856 my $driver64dir="$shrdir/x64";
857 push(@dirs,$driver64dir);
859 my $driver40dir="$shrdir/WIN40";
860 push(@dirs,$driver40dir);
862 my $ro_shrdir="$shrdir/root-tmp";
863 push(@dirs,$ro_shrdir);
865 my $msdfs_shrdir="$shrdir/msdfsshare";
866 push(@dirs,$msdfs_shrdir);
868 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
869 push(@dirs,$msdfs_deeppath);
871 # this gets autocreated by winbindd
872 my $wbsockdir="$prefix_abs/winbindd";
873 my $wbsockprivdir="$lockdir/winbindd_privileged";
875 my $nmbdsockdir="$prefix_abs/nmbd";
876 unlink($nmbdsockdir);
878 my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
881 ## create the test directory layout
883 die ("prefix_abs = ''") if $prefix_abs eq "";
884 die ("prefix_abs = '/'") if $prefix_abs eq "/";
886 mkdir($prefix_abs, 0777);
887 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
888 if (not defined($no_delete_prefix) or not $no_delete_prefix) {
889 system("rm -rf $prefix_abs/*");
891 mkdir($_, 0777) foreach(@dirs);
894 ## lockdir and piddir must be 0755
896 chmod 0755, $lockdir;
897 chmod 0755, $piddir;
901 ## create ro and msdfs share layout
904 chmod 0755, $ro_shrdir;
905 my $unreadable_file = "$ro_shrdir/unreadable_file";
906 unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
907 warn("Unable to open $unreadable_file");
908 return undef;
910 close(UNREADABLE_FILE);
911 chmod 0600, $unreadable_file;
913 my $msdfs_target = "$ro_shrdir/msdfs-target";
914 unless (open(MSDFS_TARGET, ">$msdfs_target")) {
915 warn("Unable to open $msdfs_target");
916 return undef;
918 close(MSDFS_TARGET);
919 chmod 0666, $msdfs_target;
920 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
921 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
923 my $conffile="$libdir/server.conf";
925 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
926 my $nss_wrapper_passwd = "$privatedir/passwd";
927 my $nss_wrapper_group = "$privatedir/group";
928 my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
930 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
932 my @eventlog_list = ("dns server", "application");
935 ## calculate uids and gids
938 my ($max_uid, $max_gid);
939 my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2);
940 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
942 if ($unix_uid < 0xffff - 4) {
943 $max_uid = 0xffff;
944 } else {
945 $max_uid = $unix_uid;
948 $uid_root = $max_uid - 1;
949 $uid_nobody = $max_uid - 2;
950 $uid_pdbtest = $max_uid - 3;
951 $uid_pdbtest2 = $max_uid - 4;
953 if ($unix_gids[0] < 0xffff - 5) {
954 $max_gid = 0xffff;
955 } else {
956 $max_gid = $unix_gids[0];
959 $gid_nobody = $max_gid - 1;
960 $gid_nogroup = $max_gid - 2;
961 $gid_root = $max_gid - 3;
962 $gid_domusers = $max_gid - 4;
963 $gid_domadmins = $max_gid - 5;
966 ## create conffile
969 unless (open(CONF, ">$conffile")) {
970 warn("Unable to open $conffile");
971 return undef;
973 print CONF "
974 [global]
975 netbios name = $server
976 interfaces = $server_ip/8
977 bind interfaces only = yes
978 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
979 smbd:suicide mode = yes
981 workgroup = $domain
983 private dir = $privatedir
984 pid directory = $piddir
985 lock directory = $lockdir
986 log file = $logdir/log.\%m
987 log level = 1
988 debug pid = yes
989 max log size = 0
991 state directory = $lockdir
992 cache directory = $lockdir
994 passdb backend = tdbsam
996 time server = yes
998 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
999 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
1000 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1001 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
1002 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1003 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1004 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
1006 addprinter command = $mod_printer_pl -a -s $conffile --
1007 deleteprinter command = $mod_printer_pl -d -s $conffile --
1009 eventlog list = application \"dns server\"
1011 kernel oplocks = no
1012 kernel change notify = no
1014 syslog = no
1015 printing = bsd
1016 printcap name = /dev/null
1018 winbindd socket directory = $wbsockdir
1019 nmbd:socket dir = $nmbdsockdir
1020 idmap config * : range = 100000-200000
1021 winbind enum users = yes
1022 winbind enum groups = yes
1024 # min receivefile size = 4000
1026 read only = no
1027 server signing = auto
1029 smbd:sharedelay = 100000
1030 smbd:writetimeupdatedelay = 500000
1031 map hidden = no
1032 map system = no
1033 map readonly = no
1034 store dos attributes = yes
1035 create mask = 755
1036 dos filemode = yes
1037 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1039 printing = vlp
1040 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1041 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1042 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1043 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1044 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1045 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1046 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1047 lpq cache time = 0
1048 print notify backchannel = yes
1050 ncalrpc dir = $prefix_abs/ncalrpc
1051 resolv:host file = $dns_host_file
1053 # The samba3.blackbox.smbclient_s3 test uses this to test that
1054 # sending messages works, and that the %m sub works.
1055 message command = mv %s $shrdir/message.%m
1057 # Begin extra options
1058 $extra_options
1059 # End extra options
1061 #Include user defined custom parameters if set
1064 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1065 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1068 print CONF "
1069 [tmp]
1070 path = $shrdir
1071 comment = smb username is [%U]
1072 [tmpsort]
1073 path = $shrdir
1074 comment = Load dirsort module
1075 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1076 [tmpenc]
1077 path = $shrdir
1078 comment = encrypt smb username is [%U]
1079 smb encrypt = required
1080 vfs objects = dirsort
1081 [tmpguest]
1082 path = $shrdir
1083 guest ok = yes
1084 [guestonly]
1085 path = $shrdir
1086 guest only = yes
1087 guest ok = yes
1088 [forceuser]
1089 path = $shrdir
1090 force user = $unix_name
1091 guest ok = yes
1092 [forcegroup]
1093 path = $shrdir
1094 force group = nogroup
1095 guest ok = yes
1096 [ro-tmp]
1097 path = $ro_shrdir
1098 guest ok = yes
1099 [write-list-tmp]
1100 path = $shrdir
1101 read only = yes
1102 write list = $unix_name
1103 [valid-users-tmp]
1104 path = $shrdir
1105 valid users = $unix_name
1106 [msdfs-share]
1107 path = $msdfs_shrdir
1108 msdfs root = yes
1109 guest ok = yes
1110 [hideunread]
1111 copy = tmp
1112 hide unreadable = yes
1113 [tmpcase]
1114 copy = tmp
1115 case sensitive = yes
1116 [hideunwrite]
1117 copy = tmp
1118 hide unwriteable files = yes
1119 [durable]
1120 copy = tmp
1121 kernel share modes = no
1122 kernel oplocks = no
1123 posix locking = no
1124 [fs_specific]
1125 copy = tmp
1126 $fs_specific_conf
1127 [print1]
1128 copy = tmp
1129 printable = yes
1131 [print2]
1132 copy = print1
1133 [print3]
1134 copy = print1
1135 default devmode = no
1136 [lp]
1137 copy = print1
1139 [nfs4acl_simple]
1140 path = $shrdir
1141 comment = smb username is [%U]
1142 nfs4:mode = simple
1143 vfs objects = nfs4acl_xattr xattr_tdb
1145 [nfs4acl_special]
1146 path = $shrdir
1147 comment = smb username is [%U]
1148 nfs4:mode = special
1149 vfs objects = nfs4acl_xattr xattr_tdb
1151 [xcopy_share]
1152 path = $shrdir
1153 comment = smb username is [%U]
1154 create mask = 777
1155 force create mode = 777
1156 [posix_share]
1157 path = $shrdir
1158 comment = smb username is [%U]
1159 create mask = 0777
1160 force create mode = 0
1161 directory mask = 0777
1162 force directory mode = 0
1163 vfs objects = xattr_tdb
1164 [aio]
1165 copy = tmp
1166 aio read size = 1
1167 aio write size = 1
1169 [print\$]
1170 copy = tmp
1172 close(CONF);
1175 ## create a test account
1178 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1179 warn("Unable to open $nss_wrapper_passwd");
1180 return undef;
1182 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1183 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1184 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1185 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1187 if ($unix_uid != 0) {
1188 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
1191 close(PASSWD);
1193 unless (open(GROUP, ">$nss_wrapper_group")) {
1194 warn("Unable to open $nss_wrapper_group");
1195 return undef;
1197 print GROUP "nobody:x:$gid_nobody:
1198 nogroup:x:$gid_nogroup:nobody
1199 $unix_name-group:x:$unix_gids[0]:
1200 domusers:X:$gid_domusers:
1201 domadmins:X:$gid_domadmins:
1203 if ($unix_gids[0] != 0) {
1204 print GROUP "root:x:$gid_root:
1208 close(GROUP);
1210 ## hosts
1211 my $hostname = lc($server);
1212 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
1213 warn("Unable to open $nss_wrapper_hosts");
1214 return undef;
1216 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}
1218 close(HOSTS);
1221 foreach my $evlog (@eventlog_list) {
1222 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1223 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1224 close(EVENTLOG);
1227 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1228 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1229 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1231 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
1232 unless (open(PWD, "|$cmd")) {
1233 warn("Unable to set password for test account\n$cmd");
1234 return undef;
1236 print PWD "$password\n$password\n";
1237 unless (close(PWD)) {
1238 warn("Unable to set password for test account\n$cmd");
1239 return undef;
1241 print "DONE\n";
1243 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1244 print DNS_UPDATE_LIST "A $server. $server_ip";
1245 close(DNS_UPDATE_LIST);
1247 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) {
1248 die "Unable to update hostname into $dns_host_file";
1251 $ret{SERVER_IP} = $server_ip;
1252 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1253 $ret{NMBD_TEST_LOG_POS} = 0;
1254 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1255 $ret{WINBINDD_TEST_LOG_POS} = 0;
1256 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1257 $ret{SMBD_TEST_LOG_POS} = 0;
1258 $ret{SERVERCONFFILE} = $conffile;
1259 $ret{CONFIGURATION} ="-s $conffile";
1260 $ret{SERVER} = $server;
1261 $ret{USERNAME} = $unix_name;
1262 $ret{USERID} = $unix_uid;
1263 $ret{DOMAIN} = $domain;
1264 $ret{NETBIOSNAME} = $server;
1265 $ret{PASSWORD} = $password;
1266 $ret{PIDDIR} = $piddir;
1267 $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
1268 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
1269 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1270 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1271 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1272 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1273 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1274 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1275 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
1276 $ret{LOCAL_PATH} = "$shrdir";
1277 $ret{LOGDIR} = $logdir;
1279 return \%ret;
1282 sub wait_for_start($$$$$)
1284 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1285 my $ret;
1287 if ($nmbd eq "yes") {
1288 # give time for nbt server to register its names
1289 print "delaying for nbt name registration\n";
1290 sleep(10);
1291 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
1292 my $nmblookup = Samba::bindir_path($self, "nmblookup3");
1293 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
1294 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
1295 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
1296 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
1297 system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
1300 if ($winbindd eq "yes") {
1301 print "checking for winbindd\n";
1302 my $count = 0;
1303 do {
1304 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --ping-dc");
1305 if ($ret != 0) {
1306 sleep(2);
1308 $count++;
1309 } while ($ret != 0 && $count < 10);
1310 if ($count == 10) {
1311 print "WINBINDD not reachable after 20 seconds\n";
1312 teardown_env($self, $envvars);
1313 return 0;
1317 if ($smbd eq "yes") {
1318 # make sure smbd is also up set
1319 print "wait for smbd\n";
1321 my $count = 0;
1322 do {
1323 $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
1324 if ($ret != 0) {
1325 sleep(2);
1327 $count++
1328 } while ($ret != 0 && $count < 10);
1329 if ($count == 10) {
1330 print "SMBD failed to start up in a reasonable time (20sec)\n";
1331 teardown_env($self, $envvars);
1332 return 0;
1336 # Ensure we have domain users mapped.
1337 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
1338 if ($ret != 0) {
1339 return 1;
1341 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
1342 if ($ret != 0) {
1343 return 1;
1346 if ($winbindd eq "yes") {
1347 # note: creating builtin groups requires winbindd for the
1348 # unix id allocator
1349 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
1350 if ($ret != 0) {
1351 print "Failed to create BUILTIN\\Users group\n";
1352 return 0;
1354 my $count = 0;
1355 do {
1356 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
1357 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
1358 if ($ret != 0) {
1359 sleep(2);
1361 $count++;
1362 } while ($ret != 0 && $count < 10);
1363 if ($count == 10) {
1364 print "WINBINDD not reachable after 20 seconds\n";
1365 teardown_env($self, $envvars);
1366 return 0;
1370 print $self->getlog_env($envvars);
1372 return 1;