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};
181 sub stop_sig_term($$) {
182 my ($self, $pid) = @_;
183 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
186 sub stop_sig_kill($$) {
187 my ($self, $pid) = @_;
188 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
193 my ($env_vars, $app, $pid) = @_;
195 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
202 my ($env_vars, $app) = @_;
204 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
210 sub check_or_start($$$$$) {
211 my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
213 unlink($env_vars->{NMBD_TEST_LOG});
214 print "STARTING NMBD...";
217 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
218 open STDERR, '>&STDOUT';
220 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
222 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
223 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
225 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
226 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
227 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
229 if ($nmbd ne "yes") {
230 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
232 print("Skip nmbd received signal $signame");
239 my @optargs = ("-d0");
240 if (defined($ENV{NMBD_OPTIONS})) {
241 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
244 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
246 my @preargs = ($self->binpath("timelimit"), $maxtime);
247 if(defined($ENV{NMBD_VALGRIND})) {
248 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
251 exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
253 write_pid($env_vars, "nmbd", $pid);
256 unlink($env_vars->{WINBINDD_TEST_LOG});
257 print "STARTING WINBINDD...";
260 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
261 open STDERR, '>&STDOUT';
263 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
265 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
266 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
268 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
269 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
270 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
272 if ($winbindd ne "yes") {
273 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
275 print("Skip winbindd received signal $signame");
282 my @optargs = ("-d0");
283 if (defined($ENV{WINBINDD_OPTIONS})) {
284 @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
287 $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd");
289 my @preargs = ($self->binpath("timelimit"), $maxtime);
290 if(defined($ENV{WINBINDD_VALGRIND})) {
291 @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
294 exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
296 write_pid($env_vars, "winbindd", $pid);
299 unlink($env_vars->{SMBD_TEST_LOG});
300 print "STARTING SMBD...";
303 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
304 open STDERR, '>&STDOUT';
306 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
308 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
309 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
311 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
312 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
313 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
315 if ($smbd ne "yes") {
316 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
318 print("Skip smbd received signal $signame");
325 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
326 my @optargs = ("-d0");
327 if (defined($ENV{SMBD_OPTIONS})) {
328 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
330 my @preargs = ($self->binpath("timelimit"), $maxtime);
331 if(defined($ENV{SMBD_VALGRIND})) {
332 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
334 exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
336 write_pid($env_vars, "smbd", $pid);
342 sub provision($$$$$$)
344 my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
347 ## setup the various environment variables we need
351 my $server_ip = "127.0.0.$swiface";
352 my $domain = "SAMBA-TEST";
354 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
357 my $unix_gids_str = $);
358 my @unix_gids = split(" ", $unix_gids_str);
360 my $prefix_abs = abs_path($prefix);
361 my $bindir_abs = abs_path($self->{bindir});
362 my $vfs_modulesdir_abs = ($ENV{VFSLIBDIR} or $bindir_abs);
366 my $shrdir="$prefix_abs/share";
369 my $libdir="$prefix_abs/lib";
372 my $piddir="$prefix_abs/pid";
375 my $privatedir="$prefix_abs/private";
376 push(@dirs,$privatedir);
378 my $lockdir="$prefix_abs/lockdir";
379 push(@dirs,$lockdir);
381 my $eventlogdir="$prefix_abs/lockdir/eventlog";
382 push(@dirs,$eventlogdir);
384 my $logdir="$prefix_abs/logs";
387 my $driver32dir="$shrdir/W32X86";
388 push(@dirs,$driver32dir);
390 my $driver64dir="$shrdir/x64";
391 push(@dirs,$driver64dir);
393 my $driver40dir="$shrdir/WIN40";
394 push(@dirs,$driver40dir);
396 my $ro_shrdir="$shrdir/root-tmp";
397 push(@dirs,$ro_shrdir);
399 my $msdfs_shrdir="$shrdir/msdfsshare";
400 push(@dirs,$msdfs_shrdir);
402 my $msdfs_deeppath="$msdfs_shrdir/deeppath";
403 push(@dirs,$msdfs_deeppath);
405 # this gets autocreated by winbindd
406 my $wbsockdir="$prefix_abs/winbindd";
407 my $wbsockprivdir="$lockdir/winbindd_privileged";
409 my $nmbdsockdir="$prefix_abs/nmbd";
410 unlink($nmbdsockdir);
413 ## create the test directory layout
415 die ("prefix_abs = ''") if $prefix_abs eq "";
416 die ("prefix_abs = '/'") if $prefix_abs eq "/";
418 mkdir($prefix_abs, 0777);
419 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
420 system("rm -rf $prefix_abs/*");
421 mkdir($_, 0777) foreach(@dirs);
424 ## create ro and msdfs share layout
427 chmod 0755, $ro_shrdir;
428 my $unreadable_file = "$ro_shrdir/unreadable_file";
429 open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
430 close(UNREADABLE_FILE);
431 chmod 0600, $unreadable_file;
433 my $msdfs_target = "$ro_shrdir/msdfs-target";
434 open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
436 chmod 0666, $msdfs_target;
437 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
438 symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
440 my $conffile="$libdir/server.conf";
442 my $nss_wrapper_pl = "$ENV{PERL} $RealBin/../lib/nss_wrapper/nss_wrapper.pl";
443 my $nss_wrapper_passwd = "$privatedir/passwd";
444 my $nss_wrapper_group = "$privatedir/group";
446 my $mod_printer_pl = "$ENV{PERL} $RealBin/../source3/script/tests/printing/modprinter.pl";
448 my @eventlog_list = ("dns server", "application");
451 ## calculate uids and gids
454 my ($max_uid, $max_gid);
455 my ($uid_nobody, $uid_root);
456 my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers);
458 if ($unix_uid < 0xffff - 2) {
461 $max_uid = $unix_uid;
464 $uid_root = $max_uid - 1;
465 $uid_nobody = $max_uid - 2;
467 if ($unix_gids[0] < 0xffff - 3) {
470 $max_gid = $unix_gids[0];
473 $gid_nobody = $max_gid - 1;
474 $gid_nogroup = $max_gid - 2;
475 $gid_root = $max_gid - 3;
476 $gid_domusers = $max_gid - 4;
482 open(CONF, ">$conffile") or die("Unable to open $conffile");
485 netbios name = $server
486 interfaces = $server_ip/8
487 bind interfaces only = yes
488 panic action = $RealBin/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
492 private dir = $privatedir
493 pid directory = $piddir
494 lock directory = $lockdir
495 log file = $logdir/log.\%m
498 name resolve order = bcast
500 state directory = $lockdir
501 cache directory = $lockdir
503 passdb backend = tdbsam
507 add user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
508 add group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action add --name %g
509 add machine script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
510 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
511 delete user script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
512 delete group script = $nss_wrapper_pl --group_path $nss_wrapper_group --type group --action delete --name %g
513 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
515 addprinter command = $mod_printer_pl -a -s $conffile --
516 deleteprinter command = $mod_printer_pl -d -s $conffile --
518 eventlog list = application \"dns server\"
521 kernel change notify = no
525 printcap name = /dev/null
527 winbindd:socket dir = $wbsockdir
528 nmbd:socket dir = $nmbdsockdir
529 idmap uid = 100000-200000
530 idmap gid = 100000-200000
531 winbind enum users = yes
532 winbind enum groups = yes
534 # min receivefile size = 4000
538 server signing = auto
540 smbd:sharedelay = 100000
541 # smbd:writetimeupdatedelay = 500000
545 store dos attributes = yes
547 vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
550 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
551 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
552 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
553 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
554 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
555 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
556 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
559 rpc_server:epmapper = embedded
561 # Begin extra options
565 #Include user defined custom parameters if set
568 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
569 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
584 hide unreadable = yes
590 hide unwriteable files = yes
607 ## create a test account
610 open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
611 print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
612 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
614 if ($unix_uid != 0) {
615 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
619 open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
620 print GROUP "nobody:x:$gid_nobody:
621 nogroup:x:$gid_nogroup:nobody
622 $unix_name-group:x:$unix_gids[0]:
623 domusers:X:$gid_domusers:
625 if ($unix_gids[0] != 0) {
626 print GROUP "root:x:$gid_root:";
631 foreach my $evlog (@eventlog_list) {
632 my $evlogtdb = "$eventlogdir/$evlog.tdb";
633 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
637 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
638 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
640 open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
641 print PWD "$password\n$password\n";
642 close(PWD) or die("Unable to set password for test account");
646 $ret{SERVER_IP} = $server_ip;
647 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
648 $ret{NMBD_TEST_LOG_POS} = 0;
649 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
650 $ret{WINBINDD_TEST_LOG_POS} = 0;
651 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
652 $ret{SMBD_TEST_LOG_POS} = 0;
653 $ret{SERVERCONFFILE} = $conffile;
654 $ret{CONFIGURATION} ="-s $conffile";
655 $ret{SERVER} = $server;
656 $ret{USERNAME} = $unix_name;
657 $ret{USERID} = $unix_uid;
658 $ret{DOMAIN} = $domain;
659 $ret{NETBIOSNAME} = $server;
660 $ret{PASSWORD} = $password;
661 $ret{PIDDIR} = $piddir;
662 $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
663 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
664 $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
665 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
666 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
667 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
668 $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
669 $ret{LOCAL_PATH} = "$shrdir";
674 sub wait_for_start($$)
676 my ($self, $envvars) = @_;
678 # give time for nbt server to register its names
679 print "delaying for nbt name registration\n";
681 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
682 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
683 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
684 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
685 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
686 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
687 # make sure smbd is also up set
688 print "wait for smbd\n";
689 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
690 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
692 # Ensure we have domain users mapped.
693 system($self->binpath("net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
695 print $self->getlog_env($envvars);