2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
10 use FindBin
qw($RealBin);
15 my ($self, $binary) = @_;
17 if (defined($self->{bindir})) {
18 my $path = "$self->{bindir}/$binary";
19 -f $path or die("File $path doesn't exist");
27 my ($classname, $bindir, $srcdir) = @_;
28 my $self = { bindir => $bindir,
37 my ($self, $envvars) = @_;
39 my $smbdpid = read_pid($envvars, "smbd");
40 my $nmbdpid = read_pid($envvars, "nmbd");
41 my $winbinddpid = read_pid($envvars, "winbindd");
43 $self->stop_sig_term($smbdpid);
44 $self->stop_sig_term($nmbdpid);
45 $self->stop_sig_term($winbinddpid);
49 $self->stop_sig_kill($smbdpid);
50 $self->stop_sig_kill($nmbdpid);
51 $self->stop_sig_kill($winbinddpid);
56 sub getlog_env_app($$$)
58 my ($self, $envvars, $name) = @_;
60 my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
63 open(LOG, "<".$envvars->{$name."_TEST_LOG"});
65 seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
69 $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
72 return "" if $out eq $title;
79 my ($self, $envvars) = @_;
82 $ret .= $self->getlog_env_app($envvars, "SMBD");
83 $ret .= $self->getlog_env_app($envvars, "NMBD");
84 $ret .= $self->getlog_env_app($envvars, "WINBINDD");
91 my ($self, $envvars) = @_;
99 my ($self, $envname, $path) = @_;
101 if ($envname eq "dc") {
102 return $self->setup_dc("$path/dc");
103 } elsif ($envname eq "secshare") {
104 return $self->setup_secshare("$path/secshare");
105 } elsif ($envname eq "secserver") {
106 if (not defined($self->{vars}->{dc})) {
107 $self->setup_dc("$path/dc");
109 return $self->setup_secserver("$path/secserver", $self->{vars}->{dc});
110 } elsif ($envname eq "member") {
111 if (not defined($self->{vars}->{dc})) {
112 $self->setup_dc("$path/dc");
114 return $self->setup_member("$path/member", $self->{vars}->{dc});
122 my ($self, $path) = @_;
124 print "PROVISIONING DC...";
132 my $vars = $self->provision($path,
138 $self->check_or_start($vars,
139 ($ENV{SMBD_MAXTIME} or 2700),
140 "yes", "yes", "yes");
142 $self->wait_for_start($vars);
144 $vars->{DC_SERVER} = $vars->{SERVER};
145 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
146 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
147 $vars->{DC_USERNAME} = $vars->{USERNAME};
148 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
150 $self->{vars}->{dc} = $vars;
155 sub setup_member($$$)
157 my ($self, $prefix, $dcvars) = @_;
159 print "PROVISIONING MEMBER...";
161 my $member_options = "
165 my $ret = $self->provision($prefix,
171 $ret or die("Unable to provision");
173 my $net = $self->binpath("net");
175 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
176 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
177 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
179 system($cmd) == 0 or die("Join failed\n$cmd");
181 $self->check_or_start($ret,
182 ($ENV{SMBD_MAXTIME} or 2700),
183 "yes", "yes", "yes");
185 $self->wait_for_start($ret);
187 $ret->{DC_SERVER} = $dcvars->{SERVER};
188 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
189 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
190 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
191 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
196 sub setup_secshare($$)
198 my ($self, $path) = @_;
200 print "PROVISIONING server with security=share...";
202 my $secshare_options = "
207 my $vars = $self->provision($path,
213 $self->check_or_start($vars,
214 ($ENV{SMBD_MAXTIME} or 2700),
217 $self->wait_for_start($vars);
219 $self->{vars}->{secshare} = $vars;
224 sub setup_secserver($$$)
226 my ($self, $prefix, $dcvars) = @_;
228 print "PROVISIONING server with security=server...";
230 my $secserver_options = "
232 password server = $dcvars->{SERVER_IP}
235 my $ret = $self->provision($prefix,
241 $ret or die("Unable to provision");
243 $self->check_or_start($ret,
244 ($ENV{SMBD_MAXTIME} or 2700),
247 $self->wait_for_start($ret);
249 $ret->{DC_SERVER} = $dcvars->{SERVER};
250 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
251 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
252 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
253 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
258 sub stop_sig_term($$) {
259 my ($self, $pid) = @_;
260 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
263 sub stop_sig_kill($$) {
264 my ($self, $pid) = @_;
265 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
270 my ($env_vars, $app, $pid) = @_;
272 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
279 my ($env_vars, $app) = @_;
281 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
287 sub check_or_start($$$$$) {
288 my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
290 unlink($env_vars->{NMBD_TEST_LOG});
291 print "STARTING NMBD...";
294 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
295 open STDERR, '>&STDOUT';
297 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
299 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
300 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
302 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
303 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
304 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
306 if ($nmbd ne "yes") {
307 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
309 print("Skip nmbd received signal $signame");
316 my @optargs = ("-d0");
317 if (defined($ENV{NMBD_OPTIONS})) {
318 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
321 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
323 my @preargs = ($self->binpath("timelimit"), $maxtime);
324 if(defined($ENV{NMBD_VALGRIND})) {
325 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
328 exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
330 write_pid($env_vars, "nmbd", $pid);
333 unlink($env_vars->{WINBINDD_TEST_LOG});
334 print "STARTING WINBINDD...";
337 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
338 open STDERR, '>&STDOUT';
340 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
342 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
343 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
345 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
346 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
347 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
349 if ($winbindd ne "yes") {
350 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
352 print("Skip winbindd received signal $signame");
359 my @optargs = ("-d0");
360 if (defined($ENV{WINBINDD_OPTIONS})) {
361 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
364 $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd");
366 my @preargs = ($self->binpath("timelimit"), $maxtime);
367 if(defined($ENV{WINBINDD_VALGRIND})) {
368 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
371 exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
373 write_pid($env_vars, "winbindd", $pid);
376 unlink($env_vars->{SMBD_TEST_LOG});
377 print "STARTING SMBD...";
380 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
381 open STDERR, '>&STDOUT';
383 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
385 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
386 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
388 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
389 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
390 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
392 if ($smbd ne "yes") {
393 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
395 print("Skip smbd received signal $signame");
402 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
403 my @optargs = ("-d0");
404 if (defined($ENV{SMBD_OPTIONS})) {
405 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
407 my @preargs = ($self->binpath("timelimit"), $maxtime);
408 if(defined($ENV{SMBD_VALGRIND})) {
409 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
411 exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
413 write_pid($env_vars, "smbd", $pid);
419 sub provision($$$$$$)
421 my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
424 ## setup the various environment variables we need
428 my $server_ip = "127.0.0.$swiface";
429 my $domain = "SAMBA-TEST";
431 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
434 my $unix_gids_str = $);
435 my @unix_gids = split(" ", $unix_gids_str);
437 my $prefix_abs = abs_path($prefix);
438 my $bindir_abs = abs_path($self->{bindir});
439 my $vfs_modulesdir_abs = ($ENV{VFSLIBDIR} or $bindir_abs);
443 my $shrdir="$prefix_abs/share";
446 my $libdir="$prefix_abs/lib";
449 my $piddir="$prefix_abs/pid";
452 my $privatedir="$prefix_abs/private";
453 push(@dirs,$privatedir);
455 my $lockdir="$prefix_abs/lockdir";
456 push(@dirs,$lockdir);
458 my $eventlogdir="$prefix_abs/lockdir/eventlog";
459 push(@dirs,$eventlogdir);
461 my $logdir="$prefix_abs/logs";
464 my $driver32dir="$shrdir/W32X86";
465 push(@dirs,$driver32dir);
467 my $driver64dir="$shrdir/x64";
468 push(@dirs,$driver64dir);
470 my $driver40dir="$shrdir/WIN40";
471 push(@dirs,$driver40dir);
473 my $ro_shrdir="$shrdir/root-tmp";
474 push(@dirs,$ro_shrdir);
476 my $msdfs_shrdir="$shrdir/msdfsshare";
477 push(@dirs,$msdfs_shrdir);
479 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
480 push(@dirs,$msdfs_deeppath);
482 # this gets autocreated by winbindd
483 my $wbsockdir="$prefix_abs/winbindd";
484 my $wbsockprivdir="$lockdir/winbindd_privileged";
486 my $nmbdsockdir="$prefix_abs/nmbd";
487 unlink($nmbdsockdir);
490 ## create the test directory layout
492 die ("prefix_abs = ''") if $prefix_abs eq "";
493 die ("prefix_abs = '/'") if $prefix_abs eq "/";
495 mkdir($prefix_abs, 0777);
496 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
497 system("rm -rf $prefix_abs/*");
498 mkdir($_, 0777) foreach(@dirs);
501 ## create ro and msdfs share layout
504 chmod 0755, $ro_shrdir;
505 my $unreadable_file = "$ro_shrdir/unreadable_file";
506 open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
507 close(UNREADABLE_FILE);
508 chmod 0600, $unreadable_file;
510 my $msdfs_target = "$ro_shrdir/msdfs-target";
511 open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
513 chmod 0666, $msdfs_target;
514 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
515 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
517 my $conffile="$libdir/server.conf";
519 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
520 my $nss_wrapper_passwd = "$privatedir/passwd";
521 my $nss_wrapper_group = "$privatedir/group";
523 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
525 my @eventlog_list = ("dns server", "application");
528 ## calculate uids and gids
531 my ($max_uid, $max_gid);
532 my ($uid_nobody, $uid_root);
533 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers);
535 if ($unix_uid < 0xffff - 2) {
538 $max_uid = $unix_uid;
541 $uid_root = $max_uid - 1;
542 $uid_nobody = $max_uid - 2;
544 if ($unix_gids[0] < 0xffff - 3) {
547 $max_gid = $unix_gids[0];
550 $gid_nobody = $max_gid - 1;
551 $gid_nogroup = $max_gid - 2;
552 $gid_root = $max_gid - 3;
553 $gid_domusers = $max_gid - 4;
559 open(CONF, ">$conffile") or die("Unable to open $conffile");
562 netbios name = $server
563 interfaces = $server_ip/8
564 bind interfaces only = yes
565 panic action = $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
569 private dir = $privatedir
570 pid directory = $piddir
571 lock directory = $lockdir
572 log file = $logdir/log.\%m
576 name resolve order = bcast
578 state directory = $lockdir
579 cache directory = $lockdir
581 passdb backend = tdbsam
585 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
586 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
587 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
588 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
589 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
590 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
591 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
593 addprinter command = $mod_printer_pl -a -s $conffile --
594 deleteprinter command = $mod_printer_pl -d -s $conffile --
596 eventlog list = application \"dns server\"
599 kernel change notify = no
603 printcap name = /dev/null
605 winbindd:socket dir = $wbsockdir
606 nmbd:socket dir = $nmbdsockdir
607 idmap config * : range = 100000-200000
608 winbind enum users = yes
609 winbind enum groups = yes
611 # min receivefile size = 4000
615 server signing = auto
617 smbd:sharedelay = 100000
618 # smbd:writetimeupdatedelay = 500000
622 store dos attributes = yes
624 vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
627 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
628 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
629 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
630 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
631 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
632 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
633 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
636 ncalrpc dir = $lockdir/ncalrpc
637 rpc_server:epmapper = embedded
639 # Begin extra options
643 #Include user defined custom parameters if set
646 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
647 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
662 force user = $unix_name
666 force group = nogroup
677 hide unreadable = yes
683 hide unwriteable files = yes
700 ## create a test account
703 open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
704 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
705 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
707 if ($unix_uid != 0) {
708 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
712 open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
713 print GROUP "nobody:x:$gid_nobody:
714 nogroup:x:$gid_nogroup:nobody
715 $unix_name-group:x:$unix_gids[0]:
716 domusers:X:$gid_domusers:
718 if ($unix_gids[0] != 0) {
719 print GROUP "root:x:$gid_root:";
724 foreach my $evlog (@eventlog_list) {
725 my $evlogtdb = "$eventlogdir/$evlog.tdb";
726 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
730 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
731 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
733 open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
734 print PWD "$password\n$password\n";
735 close(PWD) or die("Unable to set password for test account");
739 $ret{SERVER_IP} = $server_ip;
740 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
741 $ret{NMBD_TEST_LOG_POS} = 0;
742 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
743 $ret{WINBINDD_TEST_LOG_POS} = 0;
744 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
745 $ret{SMBD_TEST_LOG_POS} = 0;
746 $ret{SERVERCONFFILE} = $conffile;
747 $ret{CONFIGURATION} ="-s $conffile";
748 $ret{SERVER} = $server;
749 $ret{USERNAME} = $unix_name;
750 $ret{USERID} = $unix_uid;
751 $ret{DOMAIN} = $domain;
752 $ret{NETBIOSNAME} = $server;
753 $ret{PASSWORD} = $password;
754 $ret{PIDDIR} = $piddir;
755 $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
756 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
757 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
758 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
759 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
760 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
761 $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
762 $ret{LOCAL_PATH} = "$shrdir";
767 sub wait_for_start($$)
769 my ($self, $envvars) = @_;
771 # give time for nbt server to register its names
772 print "delaying for nbt name registration\n";
774 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
775 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
776 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
777 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
778 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
779 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
780 # make sure smbd is also up set
781 print "wait for smbd\n";
782 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
783 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
785 # Ensure we have domain users mapped.
786 system($self->binpath("net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
788 print $self->getlog_env($envvars);