selftest: Test auth_wbc, the auth4 winbind and winbind_wbclient modules using pdbtest
[Samba.git] / selftest / target / Samba3.pm
blob489fec1c1320c7e7bf179a11f87f25e66a8143aa
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
251 my $ret = $self->provision($prefix,
252 "LOCALMEMBER3",
253 "localmember3pass",
254 $member_options);
256 $ret or return undef;
258 my $net = Samba::bindir_path($self, "net");
259 my $cmd = "";
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");
266 return undef;
269 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
270 return undef;
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};
279 return $ret;
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()) {
288 return "UNKNOWN";
291 print "PROVISIONING S3 AD MEMBER...";
293 my $member_options = "
294 security = ads
295 server signing = on
296 workgroup = $dcvars->{DOMAIN}
297 realm = $dcvars->{REALM}
300 my $ret = $self->provision($prefix,
301 "LOCALADMEMBER",
302 "loCalMemberPass",
303 $member_options);
305 $ret or return undef;
307 close(USERMAP);
308 $ret->{DOMAIN} = $dcvars->{DOMAIN};
309 $ret->{REALM} = $dcvars->{REALM};
311 my $ctx;
312 my $prefix_abs = abs_path($prefix);
313 $ctx = {};
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");
324 my $cmd = "";
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");
332 return undef;
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")) {
341 return undef;
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;
353 return $ret;
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()) {
362 return "UNKNOWN";
365 print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
367 my $member_options = "
368 security = ads
369 server signing = on
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,
380 "RFC2307MEMBER",
381 "loCalMemberPass",
382 $member_options);
384 $ret or return undef;
386 close(USERMAP);
387 $ret->{DOMAIN} = $dcvars->{DOMAIN};
388 $ret->{REALM} = $dcvars->{REALM};
390 my $ctx;
391 my $prefix_abs = abs_path($prefix);
392 $ctx = {};
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");
403 my $cmd = "";
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");
411 return undef;
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")) {
420 return undef;
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;
432 return $ret;
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 = "
444 lanman auth = yes
445 vfs objects = xattr_tdb streams_depot
447 [vfs_aio_fork]
448 path = $prefix_abs/share
449 vfs objects = aio_fork
450 read only = no
451 vfs_aio_fork:erratic_testing_mode=yes
454 my $vars = $self->provision($path,
455 "LOCALSHARE4",
456 "local4pass",
457 $simpleserver_options);
459 $vars or return undef;
461 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
462 return undef;
465 $self->{vars}->{simpleserver} = $vars;
467 return $vars;
470 sub setup_ktest($$$)
472 my ($self, $prefix) = @_;
474 # If we didn't build with ADS, pretend this env was never available
475 if (not $self->have_ads()) {
476 return "UNKNOWN";
479 print "PROVISIONING server with security=ads...";
481 my $ktest_options = "
482 workgroup = KTEST
483 realm = ktest.samba.example.com
484 security = ads
485 username map = $prefix/lib/username.map
486 server signing = required
489 my $ret = $self->provision($prefix,
490 "LOCALKTEST6",
491 "localktest6pass",
492 $ktest_options);
494 $ret or return undef;
496 my $ctx;
497 my $prefix_abs = abs_path($prefix);
498 $ctx = {};
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");
509 print USERMAP "
510 $ret->{USERNAME} = KTEST\\Administrator
512 close(USERMAP);
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")) {
561 return undef;
563 return $ret;
566 sub setup_maptoguest($$)
568 my ($self, $path) = @_;
570 print "PROVISIONING maptoguest...";
572 my $options = "
573 map to guest = bad user
576 my $vars = $self->provision($path,
577 "maptoguest",
578 "maptoguestpass",
579 $options);
581 $vars or return undef;
583 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
584 return undef;
587 $self->{vars}->{s3maptoguest} = $vars;
589 return $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: $!");
602 sub write_pid($$$)
604 my ($env_vars, $app, $pid) = @_;
606 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
607 print PID $pid;
608 close(PID);
611 sub read_pid($$)
613 my ($env_vars, $app) = @_;
615 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
616 my $pid = <PID>;
617 close(PID);
618 return $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...";
631 my $pid = fork();
632 if ($pid == 0) {
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{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_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 {
652 my $signame = shift;
653 print("Skip nmbd received signal $signame");
654 exit 0;
656 sleep($self->{server_maxtime});
657 exit 0;
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);
684 print "DONE\n";
686 unlink($env_vars->{WINBINDD_TEST_LOG});
687 print "STARTING WINBINDD...";
688 $pid = fork();
689 if ($pid == 0) {
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{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_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 {
709 my $signame = shift;
710 print("Skip winbindd received signal $signame");
711 exit 0;
713 sleep($self->{server_maxtime});
714 exit 0;
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);
741 print "DONE\n";
743 unlink($env_vars->{SMBD_TEST_LOG});
744 print "STARTING SMBD...";
745 $pid = fork();
746 if ($pid == 0) {
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{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_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 {
766 my $signame = shift;
767 print("Skip smbd received signal $signame");
768 exit 0;
770 sleep($self->{server_maxtime});
771 exit 0;
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);
798 print "DONE\n";
800 close(STDIN_READER);
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);
814 my %ret = ();
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`);
819 chomp $unix_name;
820 my $unix_uid = $>;
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";
829 my @dirs = ();
831 my $shrdir="$prefix_abs/share";
832 push(@dirs,$shrdir);
834 my $libdir="$prefix_abs/lib";
835 push(@dirs,$libdir);
837 my $piddir="$prefix_abs/pid";
838 push(@dirs,$piddir);
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";
850 push(@dirs,$logdir);
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;
896 chmod 0755, $piddir;
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");
907 return undef;
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");
915 return undef;
917 close(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, $uid_pdbtest2);
939 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
941 if ($unix_uid < 0xffff - 4) {
942 $max_uid = 0xffff;
943 } else {
944 $max_uid = $unix_uid;
947 $uid_root = $max_uid - 1;
948 $uid_nobody = $max_uid - 2;
949 $uid_pdbtest = $max_uid - 3;
950 $uid_pdbtest2 = $max_uid - 4;
952 if ($unix_gids[0] < 0xffff - 5) {
953 $max_gid = 0xffff;
954 } else {
955 $max_gid = $unix_gids[0];
958 $gid_nobody = $max_gid - 1;
959 $gid_nogroup = $max_gid - 2;
960 $gid_root = $max_gid - 3;
961 $gid_domusers = $max_gid - 4;
962 $gid_domadmins = $max_gid - 5;
965 ## create conffile
968 unless (open(CONF, ">$conffile")) {
969 warn("Unable to open $conffile");
970 return undef;
972 print CONF "
973 [global]
974 netbios name = $server
975 interfaces = $server_ip/8
976 bind interfaces only = yes
977 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
978 smbd:suicide mode = yes
980 workgroup = $domain
982 private dir = $privatedir
983 pid directory = $piddir
984 lock directory = $lockdir
985 log file = $logdir/log.\%m
986 log level = 1
987 debug pid = yes
988 max log size = 0
990 state directory = $lockdir
991 cache directory = $lockdir
993 passdb backend = tdbsam
995 time server = yes
997 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
998 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
999 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1000 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
1001 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1002 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1003 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
1005 addprinter command = $mod_printer_pl -a -s $conffile --
1006 deleteprinter command = $mod_printer_pl -d -s $conffile --
1008 eventlog list = application \"dns server\"
1010 kernel oplocks = no
1011 kernel change notify = no
1013 syslog = no
1014 printing = bsd
1015 printcap name = /dev/null
1017 winbindd socket directory = $wbsockdir
1018 nmbd:socket dir = $nmbdsockdir
1019 idmap config * : range = 100000-200000
1020 winbind enum users = yes
1021 winbind enum groups = yes
1023 # min receivefile size = 4000
1025 read only = no
1026 server signing = auto
1028 smbd:sharedelay = 100000
1029 smbd:writetimeupdatedelay = 500000
1030 map hidden = no
1031 map system = no
1032 map readonly = no
1033 store dos attributes = yes
1034 create mask = 755
1035 dos filemode = yes
1036 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1038 printing = vlp
1039 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1040 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1041 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1042 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1043 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1044 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1045 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1046 lpq cache time = 0
1047 print notify backchannel = yes
1049 ncalrpc dir = $prefix_abs/ncalrpc
1050 resolv:host file = $dns_host_file
1052 # The samba3.blackbox.smbclient_s3 test uses this to test that
1053 # sending messages works, and that the %m sub works.
1054 message command = mv %s $shrdir/message.%m
1056 # Begin extra options
1057 $extra_options
1058 # End extra options
1060 #Include user defined custom parameters if set
1063 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1064 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1067 print CONF "
1068 [tmp]
1069 path = $shrdir
1070 comment = smb username is [%U]
1071 [tmpsort]
1072 path = $shrdir
1073 comment = Load dirsort module
1074 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1075 [tmpenc]
1076 path = $shrdir
1077 comment = encrypt smb username is [%U]
1078 smb encrypt = required
1079 vfs objects = dirsort
1080 [tmpguest]
1081 path = $shrdir
1082 guest ok = yes
1083 [guestonly]
1084 path = $shrdir
1085 guest only = yes
1086 guest ok = yes
1087 [forceuser]
1088 path = $shrdir
1089 force user = $unix_name
1090 guest ok = yes
1091 [forcegroup]
1092 path = $shrdir
1093 force group = nogroup
1094 guest ok = yes
1095 [ro-tmp]
1096 path = $ro_shrdir
1097 guest ok = yes
1098 [write-list-tmp]
1099 path = $shrdir
1100 read only = yes
1101 write list = $unix_name
1102 [valid-users-tmp]
1103 path = $shrdir
1104 valid users = $unix_name
1105 [msdfs-share]
1106 path = $msdfs_shrdir
1107 msdfs root = yes
1108 guest ok = yes
1109 [hideunread]
1110 copy = tmp
1111 hide unreadable = yes
1112 [tmpcase]
1113 copy = tmp
1114 case sensitive = yes
1115 [hideunwrite]
1116 copy = tmp
1117 hide unwriteable files = yes
1118 [durable]
1119 copy = tmp
1120 kernel share modes = no
1121 kernel oplocks = no
1122 posix locking = no
1123 [fs_specific]
1124 copy = tmp
1125 $fs_specific_conf
1126 [print1]
1127 copy = tmp
1128 printable = yes
1130 [print2]
1131 copy = print1
1132 [print3]
1133 copy = print1
1134 default devmode = no
1135 [lp]
1136 copy = print1
1138 [nfs4acl_simple]
1139 path = $shrdir
1140 comment = smb username is [%U]
1141 nfs4:mode = simple
1142 vfs objects = nfs4acl_xattr xattr_tdb
1144 [nfs4acl_special]
1145 path = $shrdir
1146 comment = smb username is [%U]
1147 nfs4:mode = special
1148 vfs objects = nfs4acl_xattr xattr_tdb
1150 [xcopy_share]
1151 path = $shrdir
1152 comment = smb username is [%U]
1153 create mask = 777
1154 force create mode = 777
1155 [posix_share]
1156 path = $shrdir
1157 comment = smb username is [%U]
1158 create mask = 0777
1159 force create mode = 0
1160 directory mask = 0777
1161 force directory mode = 0
1162 vfs objects = xattr_tdb
1163 [aio]
1164 copy = tmp
1165 aio read size = 1
1166 aio write size = 1
1168 [print\$]
1169 copy = tmp
1171 close(CONF);
1174 ## create a test account
1177 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1178 warn("Unable to open $nss_wrapper_passwd");
1179 return undef;
1181 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1182 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1183 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1184 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1186 if ($unix_uid != 0) {
1187 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
1190 close(PASSWD);
1192 unless (open(GROUP, ">$nss_wrapper_group")) {
1193 warn("Unable to open $nss_wrapper_group");
1194 return undef;
1196 print GROUP "nobody:x:$gid_nobody:
1197 nogroup:x:$gid_nogroup:nobody
1198 $unix_name-group:x:$unix_gids[0]:
1199 domusers:X:$gid_domusers:
1200 domadmins:X:$gid_domadmins:
1202 if ($unix_gids[0] != 0) {
1203 print GROUP "root:x:$gid_root:
1207 close(GROUP);
1209 ## hosts
1210 my $hostname = lc($server);
1211 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
1212 warn("Unable to open $nss_wrapper_hosts");
1213 return undef;
1215 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}
1217 close(HOSTS);
1220 foreach my $evlog (@eventlog_list) {
1221 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1222 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1223 close(EVENTLOG);
1226 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1227 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1228 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1230 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
1231 unless (open(PWD, "|$cmd")) {
1232 warn("Unable to set password for test account\n$cmd");
1233 return undef;
1235 print PWD "$password\n$password\n";
1236 unless (close(PWD)) {
1237 warn("Unable to set password for test account\n$cmd");
1238 return undef;
1240 print "DONE\n";
1242 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1243 print DNS_UPDATE_LIST "A $server. $server_ip";
1244 close(DNS_UPDATE_LIST);
1246 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) {
1247 die "Unable to update hostname into $dns_host_file";
1250 $ret{SERVER_IP} = $server_ip;
1251 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1252 $ret{NMBD_TEST_LOG_POS} = 0;
1253 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1254 $ret{WINBINDD_TEST_LOG_POS} = 0;
1255 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1256 $ret{SMBD_TEST_LOG_POS} = 0;
1257 $ret{SERVERCONFFILE} = $conffile;
1258 $ret{CONFIGURATION} ="-s $conffile";
1259 $ret{SERVER} = $server;
1260 $ret{USERNAME} = $unix_name;
1261 $ret{USERID} = $unix_uid;
1262 $ret{DOMAIN} = $domain;
1263 $ret{NETBIOSNAME} = $server;
1264 $ret{PASSWORD} = $password;
1265 $ret{PIDDIR} = $piddir;
1266 $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
1267 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
1268 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1269 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1270 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1271 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1272 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1273 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1274 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
1275 $ret{LOCAL_PATH} = "$shrdir";
1276 $ret{LOGDIR} = $logdir;
1278 return \%ret;
1281 sub wait_for_start($$$$$)
1283 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1284 my $ret;
1286 if ($nmbd eq "yes") {
1287 # give time for nbt server to register its names
1288 print "delaying for nbt name registration\n";
1289 sleep(10);
1290 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
1291 my $nmblookup = Samba::bindir_path($self, "nmblookup3");
1292 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
1293 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
1294 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
1295 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
1296 system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
1299 if ($winbindd eq "yes") {
1300 print "checking for winbindd\n";
1301 my $count = 0;
1302 do {
1303 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " -p");
1304 if ($ret != 0) {
1305 sleep(2);
1307 $count++;
1308 } while ($ret != 0 && $count < 10);
1309 if ($count == 10) {
1310 print "WINBINDD not reachable after 20 seconds\n";
1311 teardown_env($self, $envvars);
1312 return 0;
1316 if ($smbd eq "yes") {
1317 # make sure smbd is also up set
1318 print "wait for smbd\n";
1320 my $count = 0;
1321 do {
1322 $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
1323 if ($ret != 0) {
1324 sleep(2);
1326 $count++
1327 } while ($ret != 0 && $count < 10);
1328 if ($count == 10) {
1329 print "SMBD failed to start up in a reasonable time (20sec)\n";
1330 teardown_env($self, $envvars);
1331 return 0;
1335 # Ensure we have domain users mapped.
1336 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
1337 if ($ret != 0) {
1338 return 1;
1340 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
1341 if ($ret != 0) {
1342 return 1;
1345 if ($winbindd eq "yes") {
1346 # note: creating builtin groups requires winbindd for the
1347 # unix id allocator
1348 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
1349 if ($ret != 0) {
1350 print "Failed to create BUILTIN\\Users group\n";
1351 return 0;
1353 my $count = 0;
1354 do {
1355 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
1356 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
1357 if ($ret != 0) {
1358 sleep(2);
1360 $count++;
1361 } while ($ret != 0 && $count < 10);
1362 if ($count == 10) {
1363 print "WINBINDD not reachable after 20 seconds\n";
1364 teardown_env($self, $envvars);
1365 return 0;
1369 print $self->getlog_env($envvars);
1371 return 1;