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...";
122 my $vars = $self->provision($path,
128 $self->check_or_start($vars,
129 ($ENV{SMBD_MAXTIME} or 2700),
130 "yes", "yes", "yes");
132 $self->wait_for_start($vars);
134 $self->{vars}->{dc} = $vars;
139 sub setup_member($$$)
141 my ($self, $prefix, $dcvars) = @_;
143 print "PROVISIONING MEMBER...";
145 my $member_options = "
149 my $ret = $self->provision($prefix,
155 $ret or die("Unable to provision");
157 my $net = $self->binpath("net");
159 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
160 $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
161 $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
163 system($cmd) == 0 or die("Join failed\n$cmd");
165 $self->check_or_start($ret,
166 ($ENV{SMBD_MAXTIME} or 2700),
167 "yes", "yes", "yes");
169 $self->wait_for_start($ret);
171 $ret->{DC_SERVER} = $dcvars->{SERVER};
172 $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
173 $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
174 $ret->{DC_USERNAME} = $dcvars->{USERNAME};
175 $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
185 sub stop_sig_term($$) {
186 my ($self, $pid) = @_;
187 kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
190 sub stop_sig_kill($$) {
191 my ($self, $pid) = @_;
192 kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
197 my ($env_vars, $app, $pid) = @_;
199 open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
206 my ($env_vars, $app) = @_;
208 open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
214 sub check_or_start($$$$$) {
215 my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
217 unlink($env_vars->{NMBD_TEST_LOG});
218 print "STARTING NMBD...";
221 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
222 open STDERR, '>&STDOUT';
224 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
226 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
228 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
229 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
231 if ($nmbd ne "yes") {
232 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
234 print("Skip nmbd received signal $signame");
241 my @optargs = ("-d0");
242 if (defined($ENV{NMBD_OPTIONS})) {
243 @optargs = split(/ /, $ENV{NMBD_OPTIONS});
246 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
248 my @preargs = ($self->binpath("timelimit"), $maxtime);
249 if(defined($ENV{NMBD_VALGRIND})) {
250 @preargs = split(/ /, $ENV{NMBD_VALGRIND});
253 exec(@preargs, $self->binpath("nmbd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
255 write_pid($env_vars, "nmbd", $pid);
258 unlink($env_vars->{WINBINDD_TEST_LOG});
259 print "STARTING WINBINDD...";
262 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
263 open STDERR, '>&STDOUT';
265 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
267 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
269 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
270 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
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", "-S", "--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};
310 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
311 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
313 if ($smbd ne "yes") {
314 $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
316 print("Skip smbd received signal $signame");
323 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
324 my @optargs = ("-d0");
325 if (defined($ENV{SMBD_OPTIONS})) {
326 @optargs = split(/ /, $ENV{SMBD_OPTIONS});
328 my @preargs = ($self->binpath("timelimit"), $maxtime);
329 if(defined($ENV{SMBD_VALGRIND})) {
330 @preargs = split(/ /,$ENV{SMBD_VALGRIND});
332 exec(@preargs, $self->binpath("smbd"), "-F", "-S", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
334 write_pid($env_vars, "smbd", $pid);
340 sub create_clientconf($$$)
342 my ($self, $prefix, $domain) = @_;
344 my $lockdir = "$prefix/locks";
345 my $logdir = "$prefix/logs";
346 my $piddir = "$prefix/pid";
347 my $privatedir = "$prefix/private";
348 my $conffile = "$prefix/smb.conf";
350 my $torture_interfaces='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8';
351 open(CONF, ">$conffile");
356 private dir = $privatedir
357 pid directory = $piddir
358 lock directory = $lockdir
359 log file = $logdir/log.\%m
362 name resolve order = bcast
364 netbios name = TORTURE_6
365 interfaces = $torture_interfaces
366 panic action = $RealBin/gdb_backtrace \%d %\$(MAKE_TEST_BINARY)
368 passdb backend = tdbsam
373 sub provision($$$$$$)
375 my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
378 ## setup the various environment variables we need
382 my $server_ip = "127.0.0.$swiface";
383 my $domain = "SAMBA-TEST";
385 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
388 my $unix_gids_str = $);
389 my @unix_gids = split(" ", $unix_gids_str);
391 my $prefix_abs = abs_path($prefix);
392 my $bindir_abs = abs_path($self->{bindir});
396 my $shrdir="$prefix_abs/share";
399 my $libdir="$prefix_abs/lib";
402 my $piddir="$prefix_abs/pid";
405 my $privatedir="$prefix_abs/private";
406 push(@dirs,$privatedir);
408 my $lockdir="$prefix_abs/lockdir";
409 push(@dirs,$lockdir);
411 my $logdir="$prefix_abs/logs";
414 # this gets autocreated by winbindd
415 my $wbsockdir="$prefix_abs/winbindd";
416 my $wbsockprivdir="$lockdir/winbindd_privileged";
419 ## create the test directory layout
421 die ("prefix_abs = ''") if $prefix_abs eq "";
422 die ("prefix_abs = '/'") if $prefix_abs eq "/";
424 mkdir($prefix_abs, 0777);
425 print "CREATE TEST ENVIRONMENT IN '$prefix'...";
426 system("rm -rf $prefix_abs/*");
427 mkdir($_, 0777) foreach(@dirs);
429 my $conffile="$libdir/server.conf";
431 my $nss_wrapper_pl = "$ENV{PERL} $RealBin/../lib/nss_wrapper/nss_wrapper.pl";
432 my $nss_wrapper_passwd = "$privatedir/passwd";
433 my $nss_wrapper_group = "$privatedir/group";
435 open(CONF, ">$conffile") or die("Unable to open $conffile");
438 netbios name = $server
439 interfaces = $server_ip/8
440 bind interfaces only = yes
441 panic action = $RealBin/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
445 private dir = $privatedir
446 pid directory = $piddir
447 lock directory = $lockdir
448 log file = $logdir/log.\%m
451 name resolve order = bcast
453 state directory = $lockdir
454 cache directory = $lockdir
456 passdb backend = tdbsam
460 add user script = $nss_wrapper_pl --path $nss_wrapper_passwd --type passwd --action add --name %u
461 add machine script = $nss_wrapper_pl --path $nss_wrapper_passwd --type passwd --action add --name %u
462 delete user script = $nss_wrapper_pl --path $nss_wrapper_passwd --type passwd --action delete --name %u
465 kernel change notify = no
469 printcap name = /dev/null
471 winbindd:socket dir = $wbsockdir
472 idmap uid = 100000-200000
473 idmap gid = 100000-200000
475 # min receivefile size = 4000
478 smbd:sharedelay = 100000
479 smbd:writetimeupdatedelay = 500000
483 vfs objects = $bindir_abs/xattr_tdb.so $bindir_abs/streams_depot.so
485 # Begin extra options
489 #Include user defined custom parameters if set
492 if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
493 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
501 hide unreadable = yes
504 hide unwriteable files = yes
519 ## create a test account
522 open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
523 print PASSWD "nobody:x:65534:65533:nobody gecos:$prefix_abs:/bin/false
524 root:x:65533:65532:root gecos:$prefix_abs:/bin/false
525 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
529 open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
530 print GROUP "nobody:x:65533:
531 nogroup:x:65534:nobody
532 $unix_name-group:x:$unix_gids[0]:
536 $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
537 $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
539 open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
540 print PWD "$password\n$password\n";
541 close(PWD) or die("Unable to set password for test account");
543 delete $ENV{NSS_WRAPPER_PASSWD};
544 delete $ENV{NSS_WRAPPER_GROUP};
548 $ret{SERVER_IP} = $server_ip;
549 $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
550 $ret{NMBD_TEST_LOG_POS} = 0;
551 $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
552 $ret{WINBINDD_TEST_LOG_POS} = 0;
553 $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
554 $ret{SMBD_TEST_LOG_POS} = 0;
555 $ret{SERVERCONFFILE} = $conffile;
556 $ret{CONFIGURATION} ="-s $conffile";
557 $ret{SERVER} = $server;
558 $ret{USERNAME} = $unix_name;
559 $ret{DOMAIN} = $domain;
560 $ret{NETBIOSNAME} = $server;
561 $ret{PASSWORD} = $password;
562 $ret{PIDDIR} = $piddir;
563 $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
564 $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
565 $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
566 $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
567 $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
572 sub wait_for_start($$)
574 my ($self, $envvars) = @_;
576 # give time for nbt server to register its names
577 print "delaying for nbt name registration\n";
579 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init
580 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
581 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
582 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
583 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
584 system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
585 # make sure smbd is also up set
586 print "wait for smbd\n";
587 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
588 system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
590 print $self->getlog_env($envvars);