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 "member") {
106 if (not defined($self->{vars}->{dc})) {
107 $self->setup_dc("$path/dc");
109 return $self->setup_member("$path/member", $self->{vars}->{dc});
117 my ($self, $path) = @_;
119 print "PROVISIONING DC...";
127 my $vars = $self->provision($path,
133 $self->check_or_start($vars,
134 ($ENV{SMBD_MAXTIME} or 2700),
135 "yes", "yes", "yes");
137 $self->wait_for_start($vars);
139 $vars->{DC_SERVER} = $vars->{SERVER};
140 $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
141 $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
142 $vars->{DC_USERNAME} = $vars->{USERNAME};
143 $vars->{DC_PASSWORD} = $vars->{PASSWORD};
145 $self->{vars}->{dc} = $vars;
150 sub setup_member($$$)
152 my ($self, $prefix, $dcvars) = @_;
154 print "PROVISIONING MEMBER...";
156 my $member_options = "
160 my $ret = $self->provision($prefix,
166 $ret or die("Unable to provision");
168 my $net = $self->binpath("net");
170 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
171 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
172 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
174 system($cmd) == 0 or die("Join failed\n$cmd");
176 $self->check_or_start($ret,
177 ($ENV{SMBD_MAXTIME} or 2700),
178 "yes", "yes", "yes");
180 $self->wait_for_start($ret);
182 $ret->{DC_SERVER} = $dcvars->{SERVER};
183 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
184 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
185 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
186 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
191 sub setup_secshare($$)
193 my ($self, $path) = @_;
195 print "PROVISIONING server with security=share...";
197 my $secshare_options = "
202 my $vars = $self->provision($path,
208 $self->check_or_start($vars,
209 ($ENV{SMBD_MAXTIME} or 2700),
212 $self->wait_for_start($vars);
214 $self->{vars}->{secshare} = $vars;
219 sub stop_sig_term($$) {
220 my ($self, $pid) = @_;
221 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
224 sub stop_sig_kill($$) {
225 my ($self, $pid) = @_;
226 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
231 my ($env_vars, $app, $pid) = @_;
233 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
240 my ($env_vars, $app) = @_;
242 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
248 sub check_or_start($$$$$) {
249 my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
251 unlink($env_vars->{NMBD_TEST_LOG});
252 print "STARTING NMBD...";
255 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
256 open STDERR, '>&STDOUT';
258 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
260 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
261 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
263 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
264 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
265 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
267 if ($nmbd ne "yes") {
268 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
270 print("Skip nmbd received signal $signame");
277 my @optargs = ("-d0");
278 if (defined($ENV{NMBD_OPTIONS})) {
279 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
282 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
284 my @preargs = ($self->binpath("timelimit"), $maxtime);
285 if(defined($ENV{NMBD_VALGRIND})) {
286 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
289 exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
291 write_pid($env_vars, "nmbd", $pid);
294 unlink($env_vars->{WINBINDD_TEST_LOG});
295 print "STARTING WINBINDD...";
298 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
299 open STDERR, '>&STDOUT';
301 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
303 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
304 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
306 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
307 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
308 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
310 if ($winbindd ne "yes") {
311 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
313 print("Skip winbindd received signal $signame");
320 my @optargs = ("-d0");
321 if (defined($ENV{WINBINDD_OPTIONS})) {
322 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
325 $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd");
327 my @preargs = ($self->binpath("timelimit"), $maxtime);
328 if(defined($ENV{WINBINDD_VALGRIND})) {
329 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
332 exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
334 write_pid($env_vars, "winbindd", $pid);
337 unlink($env_vars->{SMBD_TEST_LOG});
338 print "STARTING SMBD...";
341 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
342 open STDERR, '>&STDOUT';
344 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
346 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
347 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
349 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
350 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
351 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
353 if ($smbd ne "yes") {
354 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
356 print("Skip smbd received signal $signame");
363 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
364 my @optargs = ("-d0");
365 if (defined($ENV{SMBD_OPTIONS})) {
366 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
368 my @preargs = ($self->binpath("timelimit"), $maxtime);
369 if(defined($ENV{SMBD_VALGRIND})) {
370 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
372 exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
374 write_pid($env_vars, "smbd", $pid);
380 sub provision($$$$$$)
382 my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
385 ## setup the various environment variables we need
389 my $server_ip = "127.0.0.$swiface";
390 my $domain = "SAMBA-TEST";
392 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
395 my $unix_gids_str = $);
396 my @unix_gids = split(" ", $unix_gids_str);
398 my $prefix_abs = abs_path($prefix);
399 my $bindir_abs = abs_path($self->{bindir});
400 my $vfs_modulesdir_abs = ($ENV{VFSLIBDIR} or $bindir_abs);
404 my $shrdir="$prefix_abs/share";
407 my $libdir="$prefix_abs/lib";
410 my $piddir="$prefix_abs/pid";
413 my $privatedir="$prefix_abs/private";
414 push(@dirs,$privatedir);
416 my $lockdir="$prefix_abs/lockdir";
417 push(@dirs,$lockdir);
419 my $eventlogdir="$prefix_abs/lockdir/eventlog";
420 push(@dirs,$eventlogdir);
422 my $logdir="$prefix_abs/logs";
425 my $driver32dir="$shrdir/W32X86";
426 push(@dirs,$driver32dir);
428 my $driver64dir="$shrdir/x64";
429 push(@dirs,$driver64dir);
431 my $driver40dir="$shrdir/WIN40";
432 push(@dirs,$driver40dir);
434 my $ro_shrdir="$shrdir/root-tmp";
435 push(@dirs,$ro_shrdir);
437 my $msdfs_shrdir="$shrdir/msdfsshare";
438 push(@dirs,$msdfs_shrdir);
440 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
441 push(@dirs,$msdfs_deeppath);
443 # this gets autocreated by winbindd
444 my $wbsockdir="$prefix_abs/winbindd";
445 my $wbsockprivdir="$lockdir/winbindd_privileged";
447 my $nmbdsockdir="$prefix_abs/nmbd";
448 unlink($nmbdsockdir);
451 ## create the test directory layout
453 die ("prefix_abs = ''") if $prefix_abs eq "";
454 die ("prefix_abs = '/'") if $prefix_abs eq "/";
456 mkdir($prefix_abs, 0777);
457 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
458 system("rm -rf $prefix_abs/*");
459 mkdir($_, 0777) foreach(@dirs);
462 ## create ro and msdfs share layout
465 chmod 0755, $ro_shrdir;
466 my $unreadable_file = "$ro_shrdir/unreadable_file";
467 open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
468 close(UNREADABLE_FILE);
469 chmod 0600, $unreadable_file;
471 my $msdfs_target = "$ro_shrdir/msdfs-target";
472 open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
474 chmod 0666, $msdfs_target;
475 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
476 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
478 my $conffile="$libdir/server.conf";
480 my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
481 my $nss_wrapper_passwd = "$privatedir/passwd";
482 my $nss_wrapper_group = "$privatedir/group";
484 my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
486 my @eventlog_list = ("dns server", "application");
489 ## calculate uids and gids
492 my ($max_uid, $max_gid);
493 my ($uid_nobody, $uid_root);
494 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers);
496 if ($unix_uid < 0xffff - 2) {
499 $max_uid = $unix_uid;
502 $uid_root = $max_uid - 1;
503 $uid_nobody = $max_uid - 2;
505 if ($unix_gids[0] < 0xffff - 3) {
508 $max_gid = $unix_gids[0];
511 $gid_nobody = $max_gid - 1;
512 $gid_nogroup = $max_gid - 2;
513 $gid_root = $max_gid - 3;
514 $gid_domusers = $max_gid - 4;
520 open(CONF, ">$conffile") or die("Unable to open $conffile");
523 netbios name = $server
524 interfaces = $server_ip/8
525 bind interfaces only = yes
526 panic action = $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
530 private dir = $privatedir
531 pid directory = $piddir
532 lock directory = $lockdir
533 log file = $logdir/log.\%m
537 name resolve order = bcast
539 state directory = $lockdir
540 cache directory = $lockdir
542 passdb backend = tdbsam
546 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
547 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
548 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
549 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
550 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
551 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
552 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
554 addprinter command = $mod_printer_pl -a -s $conffile --
555 deleteprinter command = $mod_printer_pl -d -s $conffile --
557 eventlog list = application \"dns server\"
560 kernel change notify = no
564 printcap name = /dev/null
566 winbindd:socket dir = $wbsockdir
567 nmbd:socket dir = $nmbdsockdir
568 idmap config * : range = 100000-200000
569 winbind enum users = yes
570 winbind enum groups = yes
572 # min receivefile size = 4000
576 server signing = auto
578 smbd:sharedelay = 100000
579 # smbd:writetimeupdatedelay = 500000
583 store dos attributes = yes
585 vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
588 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
589 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
590 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
591 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
592 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
593 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
594 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
597 ncalrpc dir = $lockdir/ncalrpc
598 rpc_server:epmapper = embedded
600 # Begin extra options
604 #Include user defined custom parameters if set
607 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
608 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
623 force user = $unix_name
627 force group = nogroup
638 hide unreadable = yes
644 hide unwriteable files = yes
661 ## create a test account
664 open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
665 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
666 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
668 if ($unix_uid != 0) {
669 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
673 open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
674 print GROUP "nobody:x:$gid_nobody:
675 nogroup:x:$gid_nogroup:nobody
676 $unix_name-group:x:$unix_gids[0]:
677 domusers:X:$gid_domusers:
679 if ($unix_gids[0] != 0) {
680 print GROUP "root:x:$gid_root:";
685 foreach my $evlog (@eventlog_list) {
686 my $evlogtdb = "$eventlogdir/$evlog.tdb";
687 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
691 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
692 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
694 open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
695 print PWD "$password\n$password\n";
696 close(PWD) or die("Unable to set password for test account");
700 $ret{SERVER_IP} = $server_ip;
701 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
702 $ret{NMBD_TEST_LOG_POS} = 0;
703 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
704 $ret{WINBINDD_TEST_LOG_POS} = 0;
705 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
706 $ret{SMBD_TEST_LOG_POS} = 0;
707 $ret{SERVERCONFFILE} = $conffile;
708 $ret{CONFIGURATION} ="-s $conffile";
709 $ret{SERVER} = $server;
710 $ret{USERNAME} = $unix_name;
711 $ret{USERID} = $unix_uid;
712 $ret{DOMAIN} = $domain;
713 $ret{NETBIOSNAME} = $server;
714 $ret{PASSWORD} = $password;
715 $ret{PIDDIR} = $piddir;
716 $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
717 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
718 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
719 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
720 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
721 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
722 $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
723 $ret{LOCAL_PATH} = "$shrdir";
728 sub wait_for_start($$)
730 my ($self, $envvars) = @_;
732 # give time for nbt server to register its names
733 print "delaying for nbt name registration\n";
735 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
736 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
737 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
738 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
739 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
740 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
741 # make sure smbd is also up set
742 print "wait for smbd\n";
743 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
744 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
746 # Ensure we have domain users mapped.
747 system($self->binpath("net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
749 print $self->getlog_env($envvars);