Add test suite for iconv conversion fail of bad names over SMB1/SMB3.
[Samba.git] / selftest / target / Samba3.pm
blobde40ced8164e8a3d6c219245b276b8bd23c70724
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_SERVER_IPV6} = $vars->{SERVER_IPV6};
233 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
234 $vars->{DC_USERNAME} = $vars->{USERNAME};
235 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
237 $self->{vars}->{s3dc} = $vars;
239 return $vars;
242 sub setup_member($$$)
244 my ($self, $prefix, $s3dcvars) = @_;
246 print "PROVISIONING MEMBER...";
248 my $member_options = "
249 security = domain
250 server signing = on
251 dbwrap_tdb_mutexes:* = yes
253 my $ret = $self->provision($prefix,
254 "LOCALMEMBER3",
255 "localmember3pass",
256 $member_options);
258 $ret or return undef;
260 my $net = Samba::bindir_path($self, "net");
261 my $cmd = "";
262 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
263 $cmd .= "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member";
264 $cmd .= " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}";
266 if (system($cmd) != 0) {
267 warn("Join failed\n$cmd");
268 return undef;
271 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
272 return undef;
275 $ret->{DC_SERVER} = $s3dcvars->{SERVER};
276 $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
277 $ret->{DC_SERVER_IPV6} = $s3dcvars->{SERVER_IPV6};
278 $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
279 $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
280 $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
282 return $ret;
285 sub setup_admember($$$$)
287 my ($self, $prefix, $dcvars) = @_;
289 # If we didn't build with ADS, pretend this env was never available
290 if (not $self->have_ads()) {
291 return "UNKNOWN";
294 print "PROVISIONING S3 AD MEMBER...";
296 my $member_options = "
297 security = ads
298 server signing = on
299 workgroup = $dcvars->{DOMAIN}
300 realm = $dcvars->{REALM}
303 my $ret = $self->provision($prefix,
304 "LOCALADMEMBER",
305 "loCalMemberPass",
306 $member_options);
308 $ret or return undef;
310 close(USERMAP);
311 $ret->{DOMAIN} = $dcvars->{DOMAIN};
312 $ret->{REALM} = $dcvars->{REALM};
314 my $ctx;
315 my $prefix_abs = abs_path($prefix);
316 $ctx = {};
317 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
318 $ctx->{domain} = $dcvars->{DOMAIN};
319 $ctx->{realm} = $dcvars->{REALM};
320 $ctx->{dnsname} = lc($dcvars->{REALM});
321 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
322 Samba::mk_krb5_conf($ctx, "");
324 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
326 my $net = Samba::bindir_path($self, "net");
327 my $cmd = "";
328 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
329 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
330 $cmd .= "$net join $ret->{CONFIGURATION}";
331 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
333 if (system($cmd) != 0) {
334 warn("Join failed\n$cmd");
335 return undef;
338 # We need world access to this share, as otherwise the domain
339 # administrator from the AD domain provided by Samba4 can't
340 # access the share for tests.
341 chmod 0777, "$prefix/share";
343 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
344 return undef;
347 $ret->{DC_SERVER} = $dcvars->{SERVER};
348 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
349 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
350 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
351 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
352 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
354 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
355 $ret->{target} = $self;
357 return $ret;
360 sub setup_admember_rfc2307($$$$)
362 my ($self, $prefix, $dcvars) = @_;
364 # If we didn't build with ADS, pretend this env was never available
365 if (not $self->have_ads()) {
366 return "UNKNOWN";
369 print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
371 my $member_options = "
372 security = ads
373 server signing = on
374 workgroup = $dcvars->{DOMAIN}
375 realm = $dcvars->{REALM}
376 idmap config $dcvars->{DOMAIN} : backend = rfc2307
377 idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
378 idmap config $dcvars->{DOMAIN} : ldap_server = ad
379 idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
380 idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
383 my $ret = $self->provision($prefix,
384 "RFC2307MEMBER",
385 "loCalMemberPass",
386 $member_options);
388 $ret or return undef;
390 close(USERMAP);
391 $ret->{DOMAIN} = $dcvars->{DOMAIN};
392 $ret->{REALM} = $dcvars->{REALM};
394 my $ctx;
395 my $prefix_abs = abs_path($prefix);
396 $ctx = {};
397 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
398 $ctx->{domain} = $dcvars->{DOMAIN};
399 $ctx->{realm} = $dcvars->{REALM};
400 $ctx->{dnsname} = lc($dcvars->{REALM});
401 $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
402 Samba::mk_krb5_conf($ctx, "");
404 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
406 my $net = Samba::bindir_path($self, "net");
407 my $cmd = "";
408 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
409 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
410 $cmd .= "$net join $ret->{CONFIGURATION}";
411 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
413 if (system($cmd) != 0) {
414 warn("Join failed\n$cmd");
415 return undef;
418 # We need world access to this share, as otherwise the domain
419 # administrator from the AD domain provided by Samba4 can't
420 # access the share for tests.
421 chmod 0777, "$prefix/share";
423 if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
424 return undef;
427 $ret->{DC_SERVER} = $dcvars->{SERVER};
428 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
429 $ret->{DC_SERVER_IPV6} = $dcvars->{SERVER_IPV6};
430 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
431 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
432 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
434 # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
435 $ret->{target} = $self;
437 return $ret;
440 sub setup_simpleserver($$)
442 my ($self, $path) = @_;
444 print "PROVISIONING server with security=share...";
446 my $prefix_abs = abs_path($path);
448 my $simpleserver_options = "
449 lanman auth = yes
450 vfs objects = xattr_tdb streams_depot
452 [vfs_aio_fork]
453 path = $prefix_abs/share
454 vfs objects = aio_fork
455 read only = no
456 vfs_aio_fork:erratic_testing_mode=yes
459 my $vars = $self->provision($path,
460 "LOCALSHARE4",
461 "local4pass",
462 $simpleserver_options);
464 $vars or return undef;
466 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
467 return undef;
470 $self->{vars}->{simpleserver} = $vars;
472 return $vars;
475 sub setup_ktest($$$)
477 my ($self, $prefix) = @_;
479 # If we didn't build with ADS, pretend this env was never available
480 if (not $self->have_ads()) {
481 return "UNKNOWN";
484 print "PROVISIONING server with security=ads...";
486 my $ktest_options = "
487 workgroup = KTEST
488 realm = ktest.samba.example.com
489 security = ads
490 username map = $prefix/lib/username.map
491 server signing = required
494 my $ret = $self->provision($prefix,
495 "LOCALKTEST6",
496 "localktest6pass",
497 $ktest_options);
499 $ret or return undef;
501 my $ctx;
502 my $prefix_abs = abs_path($prefix);
503 $ctx = {};
504 $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
505 $ctx->{domain} = "KTEST";
506 $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
507 $ctx->{dnsname} = lc($ctx->{realm});
508 $ctx->{kdc_ipv4} = "0.0.0.0";
509 Samba::mk_krb5_conf($ctx, "");
511 $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
513 open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
514 print USERMAP "
515 $ret->{USERNAME} = KTEST\\Administrator
517 close(USERMAP);
519 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
520 #Samba4 DC with the same parameters as are being used here. The
521 #domain SID is S-1-5-21-1071277805-689288055-3486227160
523 system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
524 chmod 0600, "$prefix/private/secrets.tdb";
526 #Make sure there's no old ntdb file.
527 system("rm -f $prefix/private/secrets.ntdb");
529 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
530 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
532 #and having in krb5.conf:
533 # ticket_lifetime = 799718400
534 # renew_lifetime = 799718400
536 # The commands for the -2 keytab where were:
537 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
538 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
539 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
540 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
541 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
543 # and then for the -3 keytab, I did
545 # net changetrustpw; kdestroy and the same again.
547 # This creates a credential cache with a very long lifetime (2036 at
548 # at 2011-04), and shows that running 'net changetrustpw' does not
549 # break existing logins (for the secrets.tdb method at least).
552 $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
554 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
555 chmod 0600, "$prefix/krb5_ccache-2";
557 system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
558 chmod 0600, "$prefix/krb5_ccache-3";
560 # We need world access to this share, as otherwise the domain
561 # administrator from the AD domain provided by ktest can't
562 # access the share for tests.
563 chmod 0777, "$prefix/share";
565 if (not $self->check_or_start($ret, "yes", "no", "yes")) {
566 return undef;
568 return $ret;
571 sub setup_maptoguest($$)
573 my ($self, $path) = @_;
575 print "PROVISIONING maptoguest...";
577 my $options = "
578 map to guest = bad user
581 my $vars = $self->provision($path,
582 "maptoguest",
583 "maptoguestpass",
584 $options);
586 $vars or return undef;
588 if (not $self->check_or_start($vars, "yes", "no", "yes")) {
589 return undef;
592 $self->{vars}->{s3maptoguest} = $vars;
594 return $vars;
597 sub stop_sig_term($$) {
598 my ($self, $pid) = @_;
599 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
602 sub stop_sig_kill($$) {
603 my ($self, $pid) = @_;
604 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
607 sub write_pid($$$)
609 my ($env_vars, $app, $pid) = @_;
611 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
612 print PID $pid;
613 close(PID);
616 sub read_pid($$)
618 my ($env_vars, $app) = @_;
620 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
621 my $pid = <PID>;
622 close(PID);
623 return $pid;
626 sub check_or_start($$$$$) {
627 my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
629 # use a pipe for stdin in the child processes. This allows
630 # those processes to monitor the pipe for EOF to ensure they
631 # exit when the test script exits
632 pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
634 unlink($env_vars->{NMBD_TEST_LOG});
635 print "STARTING NMBD...";
636 my $pid = fork();
637 if ($pid == 0) {
638 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
639 open STDERR, '>&STDOUT';
641 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
643 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
644 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
645 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
647 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
648 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
649 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
650 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
651 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
653 $ENV{ENVNAME} = "$ENV{ENVNAME}.nmbd";
655 if ($nmbd ne "yes") {
656 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
657 my $signame = shift;
658 print("Skip nmbd received signal $signame");
659 exit 0;
661 sleep($self->{server_maxtime});
662 exit 0;
665 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
666 my @optargs = ("-d0");
667 if (defined($ENV{NMBD_OPTIONS})) {
668 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
670 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
671 if(defined($ENV{NMBD_VALGRIND})) {
672 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
674 my @args = ("-F", "--no-process-group",
675 "-s", $env_vars->{SERVERCONFFILE},
676 "-l", $env_vars->{LOGDIR});
677 if (not defined($ENV{NMBD_DONT_LOG_STDOUT})) {
678 push(@args, "--log-stdout");
681 close($env_vars->{STDIN_PIPE});
682 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
684 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
685 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
687 $env_vars->{NMBD_TL_PID} = $pid;
688 write_pid($env_vars, "nmbd", $pid);
689 print "DONE\n";
691 unlink($env_vars->{WINBINDD_TEST_LOG});
692 print "STARTING WINBINDD...";
693 $pid = fork();
694 if ($pid == 0) {
695 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
696 open STDERR, '>&STDOUT';
698 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
700 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
701 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
702 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
704 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
705 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
706 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
707 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
708 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
710 $ENV{ENVNAME} = "$ENV{ENVNAME}.winbindd";
712 if ($winbindd ne "yes") {
713 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
714 my $signame = shift;
715 print("Skip winbindd received signal $signame");
716 exit 0;
718 sleep($self->{server_maxtime});
719 exit 0;
722 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
723 my @optargs = ("-d0");
724 if (defined($ENV{WINBINDD_OPTIONS})) {
725 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
727 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
728 if(defined($ENV{WINBINDD_VALGRIND})) {
729 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
731 my @args = ("-F", "--no-process-group",
732 "-s", $env_vars->{SERVERCONFFILE},
733 "-l", $env_vars->{LOGDIR});
734 if (not defined($ENV{WINBINDD_DONT_LOG_STDOUT})) {
735 push(@args, "--stdout");
738 close($env_vars->{STDIN_PIPE});
739 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
741 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
742 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
744 $env_vars->{WINBINDD_TL_PID} = $pid;
745 write_pid($env_vars, "winbindd", $pid);
746 print "DONE\n";
748 unlink($env_vars->{SMBD_TEST_LOG});
749 print "STARTING SMBD...";
750 $pid = fork();
751 if ($pid == 0) {
752 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
753 open STDERR, '>&STDOUT';
755 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
757 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
758 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
759 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
761 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
762 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
763 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
764 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
765 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
767 $ENV{ENVNAME} = "$ENV{ENVNAME}.smbd";
769 if ($smbd ne "yes") {
770 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
771 my $signame = shift;
772 print("Skip smbd received signal $signame");
773 exit 0;
775 sleep($self->{server_maxtime});
776 exit 0;
779 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
780 my @optargs = ("-d0");
781 if (defined($ENV{SMBD_OPTIONS})) {
782 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
784 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
785 if(defined($ENV{SMBD_VALGRIND})) {
786 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
788 my @args = ("-F", "--no-process-group",
789 "-s", $env_vars->{SERVERCONFFILE},
790 "-l", $env_vars->{LOGDIR});
791 if (not defined($ENV{SMBD_DONT_LOG_STDOUT})) {
792 push(@args, "--log-stdout");
795 close($env_vars->{STDIN_PIPE});
796 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
798 exec(@preargs, $ENV{MAKE_TEST_BINARY}, @args, @optargs)
799 or die("Unable to start $ENV{MAKE_TEST_BINARY}: $!");
801 $env_vars->{SMBD_TL_PID} = $pid;
802 write_pid($env_vars, "smbd", $pid);
803 print "DONE\n";
805 close(STDIN_READER);
807 return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
810 sub provision($$$$$$)
812 my ($self, $prefix, $server, $password, $extra_options, $no_delete_prefix) = @_;
815 ## setup the various environment variables we need
818 my $swiface = Samba::get_interface($server);
819 my %ret = ();
820 my $server_ip = "127.0.0.$swiface";
821 my $server_ipv6 = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
822 my $domain = "SAMBA-TEST";
824 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
825 chomp $unix_name;
826 my $unix_uid = $>;
827 my $unix_gids_str = $);
828 my @unix_gids = split(" ", $unix_gids_str);
830 my $prefix_abs = abs_path($prefix);
831 my $bindir_abs = abs_path($self->{bindir});
833 my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
835 my @dirs = ();
837 my $shrdir="$prefix_abs/share";
838 push(@dirs,$shrdir);
840 my $libdir="$prefix_abs/lib";
841 push(@dirs,$libdir);
843 my $piddir="$prefix_abs/pid";
844 push(@dirs,$piddir);
846 my $privatedir="$prefix_abs/private";
847 push(@dirs,$privatedir);
849 my $lockdir="$prefix_abs/lockdir";
850 push(@dirs,$lockdir);
852 my $eventlogdir="$prefix_abs/lockdir/eventlog";
853 push(@dirs,$eventlogdir);
855 my $logdir="$prefix_abs/logs";
856 push(@dirs,$logdir);
858 my $driver32dir="$shrdir/W32X86";
859 push(@dirs,$driver32dir);
861 my $driver64dir="$shrdir/x64";
862 push(@dirs,$driver64dir);
864 my $driver40dir="$shrdir/WIN40";
865 push(@dirs,$driver40dir);
867 my $ro_shrdir="$shrdir/root-tmp";
868 push(@dirs,$ro_shrdir);
870 my $msdfs_shrdir="$shrdir/msdfsshare";
871 push(@dirs,$msdfs_shrdir);
873 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
874 push(@dirs,$msdfs_deeppath);
876 my $badnames_shrdir="$shrdir/badnames";
877 push(@dirs,$badnames_shrdir);
879 # this gets autocreated by winbindd
880 my $wbsockdir="$prefix_abs/winbindd";
881 my $wbsockprivdir="$lockdir/winbindd_privileged";
883 my $nmbdsockdir="$prefix_abs/nmbd";
884 unlink($nmbdsockdir);
887 ## create the test directory layout
889 die ("prefix_abs = ''") if $prefix_abs eq "";
890 die ("prefix_abs = '/'") if $prefix_abs eq "/";
892 mkdir($prefix_abs, 0777);
893 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
894 if (not defined($no_delete_prefix) or not $no_delete_prefix) {
895 system("rm -rf $prefix_abs/*");
897 mkdir($_, 0777) foreach(@dirs);
899 my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
902 ## lockdir and piddir must be 0755
904 chmod 0755, $lockdir;
905 chmod 0755, $piddir;
909 ## create ro and msdfs share layout
912 chmod 0755, $ro_shrdir;
913 my $unreadable_file = "$ro_shrdir/unreadable_file";
914 unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
915 warn("Unable to open $unreadable_file");
916 return undef;
918 close(UNREADABLE_FILE);
919 chmod 0600, $unreadable_file;
921 my $msdfs_target = "$ro_shrdir/msdfs-target";
922 unless (open(MSDFS_TARGET, ">$msdfs_target")) {
923 warn("Unable to open $msdfs_target");
924 return undef;
926 close(MSDFS_TARGET);
927 chmod 0666, $msdfs_target;
928 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
929 symlink "msdfs:$server_ipv6\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
932 ## create bad names in $badnames_shrdir
934 ## (An invalid name, would be mangled to 8.3).
935 my $badname_target = "$badnames_shrdir/\340|\231\216\377\177";
936 unless (open(BADNAME_TARGET, ">$badname_target")) {
937 warn("Unable to open $badname_target");
938 return undef;
940 close(BADNAME_TARGET);
941 chmod 0666, $badname_target;
943 ## (A bad name, would not be mangled to 8.3).
944 my $badname_target = "$badnames_shrdir/\240\276\346\327\377\177";
945 unless (open(BADNAME_TARGET, ">$badname_target")) {
946 warn("Unable to open $badname_target");
947 return undef;
949 close(BADNAME_TARGET);
950 chmod 0666, $badname_target;
952 ## (A bad good name).
953 my $badname_target = "$badnames_shrdir/blank.txt";
954 unless (open(BADNAME_TARGET, ">$badname_target")) {
955 warn("Unable to open $badname_target");
956 return undef;
958 close(BADNAME_TARGET);
959 chmod 0666, $badname_target;
961 my $conffile="$libdir/server.conf";
963 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
964 my $nss_wrapper_passwd = "$privatedir/passwd";
965 my $nss_wrapper_group = "$privatedir/group";
966 my $nss_wrapper_hosts = "$ENV{SELFTEST_PREFIX}/hosts";
968 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
970 my @eventlog_list = ("dns server", "application");
973 ## calculate uids and gids
976 my ($max_uid, $max_gid);
977 my ($uid_nobody, $uid_root, $uid_pdbtest, $uid_pdbtest2);
978 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
980 if ($unix_uid < 0xffff - 4) {
981 $max_uid = 0xffff;
982 } else {
983 $max_uid = $unix_uid;
986 $uid_root = $max_uid - 1;
987 $uid_nobody = $max_uid - 2;
988 $uid_pdbtest = $max_uid - 3;
989 $uid_pdbtest2 = $max_uid - 4;
991 if ($unix_gids[0] < 0xffff - 5) {
992 $max_gid = 0xffff;
993 } else {
994 $max_gid = $unix_gids[0];
997 $gid_nobody = $max_gid - 1;
998 $gid_nogroup = $max_gid - 2;
999 $gid_root = $max_gid - 3;
1000 $gid_domusers = $max_gid - 4;
1001 $gid_domadmins = $max_gid - 5;
1004 ## create conffile
1007 unless (open(CONF, ">$conffile")) {
1008 warn("Unable to open $conffile");
1009 return undef;
1011 print CONF "
1012 [global]
1013 netbios name = $server
1014 interfaces = $server_ip/8 $server_ipv6/64
1015 bind interfaces only = yes
1016 panic action = cd $self->{srcdir} && $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
1017 smbd:suicide mode = yes
1019 workgroup = $domain
1021 private dir = $privatedir
1022 pid directory = $piddir
1023 lock directory = $lockdir
1024 log file = $logdir/log.\%m
1025 log level = 1
1026 debug pid = yes
1027 max log size = 0
1029 state directory = $lockdir
1030 cache directory = $lockdir
1032 passdb backend = tdbsam
1034 time server = yes
1036 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1037 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
1038 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
1039 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
1040 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
1041 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
1042 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
1044 addprinter command = $mod_printer_pl -a -s $conffile --
1045 deleteprinter command = $mod_printer_pl -d -s $conffile --
1047 eventlog list = application \"dns server\"
1049 kernel oplocks = no
1050 kernel change notify = no
1052 syslog = no
1053 printing = bsd
1054 printcap name = /dev/null
1056 winbindd socket directory = $wbsockdir
1057 nmbd:socket dir = $nmbdsockdir
1058 idmap config * : range = 100000-200000
1059 winbind enum users = yes
1060 winbind enum groups = yes
1061 winbind separator = /
1063 # min receivefile size = 4000
1065 read only = no
1066 server signing = auto
1068 smbd:sharedelay = 100000
1069 smbd:writetimeupdatedelay = 500000
1070 map hidden = no
1071 map system = no
1072 map readonly = no
1073 store dos attributes = yes
1074 create mask = 755
1075 dos filemode = yes
1076 vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
1078 printing = vlp
1079 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1080 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1081 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1082 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1083 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1084 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1085 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1086 lpq cache time = 0
1087 print notify backchannel = yes
1089 ncalrpc dir = $prefix_abs/ncalrpc
1090 resolv:host file = $dns_host_file
1092 # The samba3.blackbox.smbclient_s3 test uses this to test that
1093 # sending messages works, and that the %m sub works.
1094 message command = mv %s $shrdir/message.%m
1096 # Begin extra options
1097 $extra_options
1098 # End extra options
1100 #Include user defined custom parameters if set
1103 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1104 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1107 print CONF "
1108 [tmp]
1109 path = $shrdir
1110 comment = smb username is [%U]
1111 [tmpsort]
1112 path = $shrdir
1113 comment = Load dirsort module
1114 vfs objects = dirsort acl_xattr fake_acls xattr_tdb streams_depot
1115 [tmpenc]
1116 path = $shrdir
1117 comment = encrypt smb username is [%U]
1118 smb encrypt = required
1119 vfs objects = dirsort
1120 [tmpguest]
1121 path = $shrdir
1122 guest ok = yes
1123 [guestonly]
1124 path = $shrdir
1125 guest only = yes
1126 guest ok = yes
1127 [forceuser]
1128 path = $shrdir
1129 force user = $unix_name
1130 guest ok = yes
1131 [forcegroup]
1132 path = $shrdir
1133 force group = nogroup
1134 guest ok = yes
1135 [ro-tmp]
1136 path = $ro_shrdir
1137 guest ok = yes
1138 [write-list-tmp]
1139 path = $shrdir
1140 read only = yes
1141 write list = $unix_name
1142 [valid-users-tmp]
1143 path = $shrdir
1144 valid users = $unix_name
1145 [msdfs-share]
1146 path = $msdfs_shrdir
1147 msdfs root = yes
1148 guest ok = yes
1149 [hideunread]
1150 copy = tmp
1151 hide unreadable = yes
1152 [tmpcase]
1153 copy = tmp
1154 case sensitive = yes
1155 [hideunwrite]
1156 copy = tmp
1157 hide unwriteable files = yes
1158 [durable]
1159 copy = tmp
1160 kernel share modes = no
1161 kernel oplocks = no
1162 posix locking = no
1163 [fs_specific]
1164 copy = tmp
1165 $fs_specific_conf
1166 [print1]
1167 copy = tmp
1168 printable = yes
1170 [print2]
1171 copy = print1
1172 [print3]
1173 copy = print1
1174 default devmode = no
1175 [lp]
1176 copy = print1
1178 [nfs4acl_simple]
1179 path = $shrdir
1180 comment = smb username is [%U]
1181 nfs4:mode = simple
1182 vfs objects = nfs4acl_xattr xattr_tdb
1184 [nfs4acl_special]
1185 path = $shrdir
1186 comment = smb username is [%U]
1187 nfs4:mode = special
1188 vfs objects = nfs4acl_xattr xattr_tdb
1190 [xcopy_share]
1191 path = $shrdir
1192 comment = smb username is [%U]
1193 create mask = 777
1194 force create mode = 777
1195 [posix_share]
1196 path = $shrdir
1197 comment = smb username is [%U]
1198 create mask = 0777
1199 force create mode = 0
1200 directory mask = 0777
1201 force directory mode = 0
1202 vfs objects = xattr_tdb
1203 [aio]
1204 copy = tmp
1205 aio read size = 1
1206 aio write size = 1
1208 [print\$]
1209 copy = tmp
1211 [vfs_fruit]
1212 path = $shrdir
1213 vfs objects = catia fruit streams_xattr
1214 fruit:ressource = file
1215 fruit:metadata = netatalk
1216 fruit:locking = netatalk
1217 fruit:encoding = native
1219 [badname-tmp]
1220 path = $badnames_shrdir
1221 guest ok = yes
1223 close(CONF);
1226 ## create a test account
1229 unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1230 warn("Unable to open $nss_wrapper_passwd");
1231 return undef;
1233 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1234 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1235 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1236 pdbtest2:x:$uid_pdbtest2:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1238 if ($unix_uid != 0) {
1239 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false
1242 close(PASSWD);
1244 unless (open(GROUP, ">$nss_wrapper_group")) {
1245 warn("Unable to open $nss_wrapper_group");
1246 return undef;
1248 print GROUP "nobody:x:$gid_nobody:
1249 nogroup:x:$gid_nogroup:nobody
1250 $unix_name-group:x:$unix_gids[0]:
1251 domusers:X:$gid_domusers:
1252 domadmins:X:$gid_domadmins:
1254 if ($unix_gids[0] != 0) {
1255 print GROUP "root:x:$gid_root:
1259 close(GROUP);
1261 ## hosts
1262 my $hostname = lc($server);
1263 unless (open(HOSTS, ">>$nss_wrapper_hosts")) {
1264 warn("Unable to open $nss_wrapper_hosts");
1265 return undef;
1267 print HOSTS "${server_ip} ${hostname}.samba.example.com ${hostname}\n";
1268 print HOSTS "${server_ipv6} ${hostname}.samba.example.com ${hostname}\n";
1269 close(HOSTS);
1272 foreach my $evlog (@eventlog_list) {
1273 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1274 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1275 close(EVENTLOG);
1278 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1279 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1280 $ENV{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1282 my $cmd = "UID_WRAPPER_ROOT=1 " . Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
1283 unless (open(PWD, "|$cmd")) {
1284 warn("Unable to set password for test account\n$cmd");
1285 return undef;
1287 print PWD "$password\n$password\n";
1288 unless (close(PWD)) {
1289 warn("Unable to set password for test account\n$cmd");
1290 return undef;
1292 print "DONE\n";
1294 open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1295 print DNS_UPDATE_LIST "A $server. $server_ip\n";
1296 print DNS_UPDATE_LIST "AAAA $server. $server_ipv6\n";
1297 close(DNS_UPDATE_LIST);
1299 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 --update-cache=$prefix/dns_update_cache --no-substiutions --no-credentials") != 0) {
1300 die "Unable to update hostname into $dns_host_file";
1303 $ret{SERVER_IP} = $server_ip;
1304 $ret{SERVER_IPV6} = $server_ipv6;
1305 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1306 $ret{NMBD_TEST_LOG_POS} = 0;
1307 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1308 $ret{WINBINDD_TEST_LOG_POS} = 0;
1309 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1310 $ret{SMBD_TEST_LOG_POS} = 0;
1311 $ret{SERVERCONFFILE} = $conffile;
1312 $ret{CONFIGURATION} ="-s $conffile";
1313 $ret{SERVER} = $server;
1314 $ret{USERNAME} = $unix_name;
1315 $ret{USERID} = $unix_uid;
1316 $ret{DOMAIN} = $domain;
1317 $ret{NETBIOSNAME} = $server;
1318 $ret{PASSWORD} = $password;
1319 $ret{PIDDIR} = $piddir;
1320 $ret{SELFTEST_WINBINDD_SOCKET_DIR} = $wbsockdir;
1321 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
1322 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1323 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1324 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1325 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1326 $ret{NSS_WRAPPER_HOSTS} = $nss_wrapper_hosts;
1327 $ret{NSS_WRAPPER_MODULE_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1328 $ret{NSS_WRAPPER_MODULE_FN_PREFIX} = "winbind";
1329 $ret{LOCAL_PATH} = "$shrdir";
1330 $ret{LOGDIR} = $logdir;
1332 return \%ret;
1335 sub wait_for_start($$$$$)
1337 my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1338 my $ret;
1340 if ($nmbd eq "yes") {
1341 my $count = 0;
1343 # give time for nbt server to register its names
1344 print "checking for nmbd\n";
1346 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
1347 my $nmblookup = Samba::bindir_path($self, "nmblookup");
1349 do {
1350 $ret = system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
1351 if ($ret != 0) {
1352 sleep(1);
1353 } else {
1354 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
1355 system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
1356 system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
1357 system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
1359 $count++;
1360 } while ($ret != 0 && $count < 10);
1361 if ($count == 10) {
1362 print "NMBD not reachable after 10 retries\n";
1363 teardown_env($self, $envvars);
1364 return 0;
1368 if ($winbindd eq "yes") {
1369 print "checking for winbindd\n";
1370 my $count = 0;
1371 do {
1372 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --ping-dc");
1373 if ($ret != 0) {
1374 sleep(2);
1376 $count++;
1377 } while ($ret != 0 && $count < 10);
1378 if ($count == 10) {
1379 print "WINBINDD not reachable after 20 seconds\n";
1380 teardown_env($self, $envvars);
1381 return 0;
1385 if ($smbd eq "yes") {
1386 # make sure smbd is also up set
1387 print "wait for smbd\n";
1389 my $count = 0;
1390 do {
1391 $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
1392 if ($ret != 0) {
1393 sleep(2);
1395 $count++
1396 } while ($ret != 0 && $count < 10);
1397 if ($count == 10) {
1398 print "SMBD failed to start up in a reasonable time (20sec)\n";
1399 teardown_env($self, $envvars);
1400 return 0;
1404 # Ensure we have domain users mapped.
1405 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
1406 if ($ret != 0) {
1407 return 1;
1409 $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
1410 if ($ret != 0) {
1411 return 1;
1414 if ($winbindd eq "yes") {
1415 # note: creating builtin groups requires winbindd for the
1416 # unix id allocator
1417 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
1418 if ($ret != 0) {
1419 print "Failed to create BUILTIN\\Users group\n";
1420 return 0;
1422 my $count = 0;
1423 do {
1424 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
1425 $ret = system("SELFTEST_WINBINDD_SOCKET_DIR=" . $envvars->{SELFTEST_WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
1426 if ($ret != 0) {
1427 sleep(2);
1429 $count++;
1430 } while ($ret != 0 && $count < 10);
1431 if ($count == 10) {
1432 print "WINBINDD not reachable after 20 seconds\n";
1433 teardown_env($self, $envvars);
1434 return 0;
1438 print $self->getlog_env($envvars);
1440 return 1;