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) = @_;
28 my $self = { bindir => $bindir };
35 my ($self, $envvars) = @_;
37 my $smbdpid = read_pid($envvars, "smbd");
38 my $nmbdpid = read_pid($envvars, "nmbd");
39 my $winbinddpid = read_pid($envvars, "winbindd");
41 $self->stop_sig_term($smbdpid);
42 $self->stop_sig_term($nmbdpid);
43 $self->stop_sig_term($winbinddpid);
47 $self->stop_sig_kill($smbdpid);
48 $self->stop_sig_kill($nmbdpid);
49 $self->stop_sig_kill($winbinddpid);
54 sub getlog_env_app($$$)
56 my ($self, $envvars, $name) = @_;
58 my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
61 open(LOG, "<".$envvars->{$name."_TEST_LOG"});
63 seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
67 $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
70 return "" if $out eq $title;
77 my ($self, $envvars) = @_;
80 $ret .= $self->getlog_env_app($envvars, "SMBD");
81 $ret .= $self->getlog_env_app($envvars, "NMBD");
82 $ret .= $self->getlog_env_app($envvars, "WINBINDD");
89 my ($self, $envvars) = @_;
97 my ($self, $envname, $path) = @_;
99 if ($envname eq "dc") {
100 return $self->setup_dc("$path/dc");
101 } elsif ($envname eq "member") {
102 if (not defined($self->{vars}->{dc})) {
103 $self->setup_dc("$path/dc");
105 return $self->setup_member("$path/member", $self->{vars}->{dc});
113 my ($self, $path) = @_;
115 print "PROVISIONING DC...";
123 my $vars = $self->provision($path,
129 $self->check_or_start($vars,
130 ($ENV{SMBD_MAXTIME} or 2700),
131 "yes", "yes", "yes");
133 $self->wait_for_start($vars);
135 $self->{vars}->{dc} = $vars;
140 sub setup_member($$$)
142 my ($self, $prefix, $dcvars) = @_;
144 print "PROVISIONING MEMBER...";
146 my $member_options = "
150 my $ret = $self->provision($prefix,
156 $ret or die("Unable to provision");
158 my $net = $self->binpath("net");
160 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
161 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
162 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
164 system($cmd) == 0 or die("Join failed\n$cmd");
166 $self->check_or_start($ret,
167 ($ENV{SMBD_MAXTIME} or 2700),
168 "yes", "yes", "yes");
170 $self->wait_for_start($ret);
172 $ret->{DC_SERVER} = $dcvars->{SERVER};
173 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
174 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
175 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
176 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
186 sub stop_sig_term($$) {
187 my ($self, $pid) = @_;
188 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
191 sub stop_sig_kill($$) {
192 my ($self, $pid) = @_;
193 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
198 my ($env_vars, $app, $pid) = @_;
200 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
207 my ($env_vars, $app) = @_;
209 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
215 sub check_or_start($$$$$) {
216 my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
218 unlink($env_vars->{NMBD_TEST_LOG});
219 print "STARTING NMBD...";
222 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
223 open STDERR, '>&STDOUT';
225 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
227 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
229 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
230 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
231 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
233 if ($nmbd ne "yes") {
234 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
236 print("Skip nmbd received signal $signame");
243 my @optargs = ("-d0");
244 if (defined($ENV{NMBD_OPTIONS})) {
245 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
248 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
250 my @preargs = ($self->binpath("timelimit"), $maxtime);
251 if(defined($ENV{NMBD_VALGRIND})) {
252 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
255 exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
257 write_pid($env_vars, "nmbd", $pid);
260 unlink($env_vars->{WINBINDD_TEST_LOG});
261 print "STARTING WINBINDD...";
264 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
265 open STDERR, '>&STDOUT';
267 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
269 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
271 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
272 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
273 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
275 if ($winbindd ne "yes") {
276 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
278 print("Skip winbindd received signal $signame");
285 my @optargs = ("-d0");
286 if (defined($ENV{WINBINDD_OPTIONS})) {
287 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
290 $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd");
292 my @preargs = ($self->binpath("timelimit"), $maxtime);
293 if(defined($ENV{WINBINDD_VALGRIND})) {
294 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
297 exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
299 write_pid($env_vars, "winbindd", $pid);
302 unlink($env_vars->{SMBD_TEST_LOG});
303 print "STARTING SMBD...";
306 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
307 open STDERR, '>&STDOUT';
309 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
311 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
313 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
314 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
315 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
317 if ($smbd ne "yes") {
318 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
320 print("Skip smbd received signal $signame");
327 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
328 my @optargs = ("-d0");
329 if (defined($ENV{SMBD_OPTIONS})) {
330 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
332 my @preargs = ($self->binpath("timelimit"), $maxtime);
333 if(defined($ENV{SMBD_VALGRIND})) {
334 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
336 exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
338 write_pid($env_vars, "smbd", $pid);
344 sub provision($$$$$$)
346 my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
349 ## setup the various environment variables we need
353 my $server_ip = "127.0.0.$swiface";
354 my $domain = "SAMBA-TEST";
356 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
359 my $unix_gids_str = $);
360 my @unix_gids = split(" ", $unix_gids_str);
362 my $prefix_abs = abs_path($prefix);
363 my $bindir_abs = abs_path($self->{bindir});
367 my $shrdir="$prefix_abs/share";
370 my $libdir="$prefix_abs/lib";
373 my $piddir="$prefix_abs/pid";
376 my $privatedir="$prefix_abs/private";
377 push(@dirs,$privatedir);
379 my $lockdir="$prefix_abs/lockdir";
380 push(@dirs,$lockdir);
382 my $eventlogdir="$prefix_abs/lockdir/eventlog";
383 push(@dirs,$eventlogdir);
385 my $logdir="$prefix_abs/logs";
388 my $driver32dir="$shrdir/W32X86";
389 push(@dirs,$driver32dir);
391 my $driver64dir="$shrdir/x64";
392 push(@dirs,$driver64dir);
394 my $ro_shrdir="$shrdir/root-tmp";
395 push(@dirs,$ro_shrdir);
397 my $msdfs_shrdir="$shrdir/msdfsshare";
398 push(@dirs,$msdfs_shrdir);
400 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
401 push(@dirs,$msdfs_deeppath);
403 # this gets autocreated by winbindd
404 my $wbsockdir="$prefix_abs/winbindd";
405 my $wbsockprivdir="$lockdir/winbindd_privileged";
408 ## create the test directory layout
410 die ("prefix_abs = ''") if $prefix_abs eq "";
411 die ("prefix_abs = '/'") if $prefix_abs eq "/";
413 mkdir($prefix_abs, 0777);
414 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
415 system("rm -rf $prefix_abs/*");
416 mkdir($_, 0777) foreach(@dirs);
419 ## create ro and msdfs share layout
422 chmod 0755, $ro_shrdir;
423 my $unreadable_file = "$ro_shrdir/unreadable_file";
424 open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
425 close(UNREADABLE_FILE);
426 chmod 0600, $unreadable_file;
428 my $msdfs_target = "$ro_shrdir/msdfs-target";
429 open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
431 chmod 0666, $msdfs_target;
432 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
433 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
435 my $conffile="$libdir/server.conf";
437 my $nss_wrapper_pl = "$ENV{PERL} $RealBin/../lib/nss_wrapper/nss_wrapper.pl";
438 my $nss_wrapper_passwd = "$privatedir/passwd";
439 my $nss_wrapper_group = "$privatedir/group";
441 my $mod_printer_pl = "$ENV{PERL} $RealBin/../source3/script/tests/printing/modprinter.pl";
443 my @eventlog_list = ("dns server", "application");
446 ## calculate uids and gids
449 my ($max_uid, $max_gid);
450 my ($uid_nobody, $uid_root);
451 my ($gid_nobody, $gid_nogroup, $gid_root);
453 if ($unix_uid < 0xffff - 2) {
456 $max_uid = $unix_uid;
459 $uid_root = $max_uid - 1;
460 $uid_nobody = $max_uid - 2;
462 if ($unix_gids[0] < 0xffff - 3) {
465 $max_gid = $unix_gids[0];
468 $gid_nobody = $max_gid - 1;
469 $gid_nogroup = $max_gid - 2;
470 $gid_root = $max_gid - 3;
476 open(CONF, ">$conffile") or die("Unable to open $conffile");
479 netbios name = $server
480 interfaces = $server_ip/8
481 bind interfaces only = yes
482 panic action = $RealBin/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
486 private dir = $privatedir
487 pid directory = $piddir
488 lock directory = $lockdir
489 log file = $logdir/log.\%m
492 name resolve order = bcast
494 state directory = $lockdir
495 cache directory = $lockdir
497 passdb backend = tdbsam
501 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
502 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
503 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
504 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
505 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
506 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
507 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
509 addprinter command = $mod_printer_pl -a -s $conffile --
510 deleteprinter command = $mod_printer_pl -d -s $conffile --
512 eventlog list = application \"dns server\"
515 kernel change notify = no
519 printcap name = /dev/null
521 winbindd:socket dir = $wbsockdir
522 idmap uid = 100000-200000
523 idmap gid = 100000-200000
524 winbind enum users = yes
525 winbind enum groups = yes
527 # min receivefile size = 4000
530 smbd:sharedelay = 100000
531 # smbd:writetimeupdatedelay = 500000
535 store dos attributes = yes
537 vfs objects = $bindir_abs/xattr_tdb.so $bindir_abs/streams_depot.so
540 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
541 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
542 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
543 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
544 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
545 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
546 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
549 # Begin extra options
553 #Include user defined custom parameters if set
556 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
557 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
572 hide unreadable = yes
578 hide unwriteable files = yes
595 ## create a test account
598 open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
599 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
600 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
602 if ($unix_uid != 0) {
603 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
607 open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
608 print GROUP "nobody:x:$gid_nobody:
609 nogroup:x:$gid_nogroup:nobody
610 $unix_name-group:x:$unix_gids[0]:
612 if ($unix_gids[0] != 0) {
613 print GROUP "root:x:$gid_root:";
618 foreach my $evlog (@eventlog_list) {
619 my $evlogtdb = "$eventlogdir/$evlog.tdb";
620 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
624 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
625 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
627 open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
628 print PWD "$password\n$password\n";
629 close(PWD) or die("Unable to set password for test account");
633 $ret{SERVER_IP} = $server_ip;
634 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
635 $ret{NMBD_TEST_LOG_POS} = 0;
636 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
637 $ret{WINBINDD_TEST_LOG_POS} = 0;
638 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
639 $ret{SMBD_TEST_LOG_POS} = 0;
640 $ret{SERVERCONFFILE} = $conffile;
641 $ret{CONFIGURATION} ="-s $conffile";
642 $ret{SERVER} = $server;
643 $ret{USERNAME} = $unix_name;
644 $ret{USERID} = $unix_uid;
645 $ret{DOMAIN} = $domain;
646 $ret{NETBIOSNAME} = $server;
647 $ret{PASSWORD} = $password;
648 $ret{PIDDIR} = $piddir;
649 $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
650 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
651 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
652 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
653 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
654 $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
655 $ret{LOCAL_PATH} = "$shrdir";
660 sub wait_for_start($$)
662 my ($self, $envvars) = @_;
664 # give time for nbt server to register its names
665 print "delaying for nbt name registration\n";
667 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
668 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
669 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
670 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
671 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
672 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
673 # make sure smbd is also up set
674 print "wait for smbd\n";
675 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
676 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
678 print $self->getlog_env($envvars);