s3-selftest: support differing VFSLIBDIR in autoconf and waf build.
[amitay/samba.git] / selftest / target / Samba3.pm
1 #!/usr/bin/perl
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.
5
6 package Samba3;
7
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12
13 sub binpath($$)
14 {
15         my ($self, $binary) = @_;
16
17         if (defined($self->{bindir})) {
18                 my $path = "$self->{bindir}/$binary";
19                 -f $path or die("File $path doesn't exist");
20                 return $path;
21         }
22
23         return $binary;
24 }
25
26 sub new($$) {
27         my ($classname, $bindir) = @_;
28         my $self = { bindir => $bindir };
29         bless $self;
30         return $self;
31 }
32
33 sub teardown_env($$)
34 {
35         my ($self, $envvars) = @_;
36
37         my $smbdpid = read_pid($envvars, "smbd");
38         my $nmbdpid = read_pid($envvars, "nmbd");
39         my $winbinddpid = read_pid($envvars, "winbindd");
40
41         $self->stop_sig_term($smbdpid);
42         $self->stop_sig_term($nmbdpid);
43         $self->stop_sig_term($winbinddpid);
44
45         sleep(2);
46
47         $self->stop_sig_kill($smbdpid);
48         $self->stop_sig_kill($nmbdpid);
49         $self->stop_sig_kill($winbinddpid);
50
51         return 0;
52 }
53
54 sub getlog_env_app($$$)
55 {
56         my ($self, $envvars, $name) = @_;
57
58         my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
59         my $out = $title;
60
61         open(LOG, "<".$envvars->{$name."_TEST_LOG"});
62
63         seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
64         while (<LOG>) {
65                 $out .= $_;
66         }
67         $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
68         close(LOG);
69
70         return "" if $out eq $title;
71  
72         return $out;
73 }
74
75 sub getlog_env($$)
76 {
77         my ($self, $envvars) = @_;
78         my $ret = "";
79
80         $ret .= $self->getlog_env_app($envvars, "SMBD");
81         $ret .= $self->getlog_env_app($envvars, "NMBD");
82         $ret .= $self->getlog_env_app($envvars, "WINBINDD");
83
84         return $ret;
85 }
86
87 sub check_env($$)
88 {
89         my ($self, $envvars) = @_;
90
91         # TODO ...
92         return 1;
93 }
94
95 sub setup_env($$$)
96 {
97         my ($self, $envname, $path) = @_;
98         
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");
104                 }
105                 return $self->setup_member("$path/member", $self->{vars}->{dc});
106         } else {
107                 return undef;
108         }
109 }
110
111 sub setup_dc($$)
112 {
113         my ($self, $path) = @_;
114
115         print "PROVISIONING DC...";
116
117         my $dc_options = "
118         domain master = yes
119         domain logons = yes
120         lanman auth = yes
121 ";
122
123         my $vars = $self->provision($path,
124                                     "LOCALDC2",
125                                     2,
126                                     "localdc2pass",
127                                     $dc_options);
128
129         $self->check_or_start($vars,
130                               ($ENV{SMBD_MAXTIME} or 2700),
131                                "yes", "yes", "yes");
132
133         $self->wait_for_start($vars);
134
135         $self->{vars}->{dc} = $vars;
136
137         return $vars;
138 }
139
140 sub setup_member($$$)
141 {
142         my ($self, $prefix, $dcvars) = @_;
143
144         print "PROVISIONING MEMBER...";
145
146         my $member_options = "
147         security = domain
148         server signing = on
149 ";
150         my $ret = $self->provision($prefix,
151                                    "LOCALMEMBER3",
152                                    3,
153                                    "localmember3pass",
154                                    $member_options);
155
156         $ret or die("Unable to provision");
157
158         my $net = $self->binpath("net");
159         my $cmd = "";
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}";
163
164         system($cmd) == 0 or die("Join failed\n$cmd");
165
166         $self->check_or_start($ret,
167                               ($ENV{SMBD_MAXTIME} or 2700),
168                                "yes", "yes", "yes");
169
170         $self->wait_for_start($ret);
171
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};
177
178         return $ret;
179 }
180
181 sub stop_sig_term($$) {
182         my ($self, $pid) = @_;
183         kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
184 }
185
186 sub stop_sig_kill($$) {
187         my ($self, $pid) = @_;
188         kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
189 }
190
191 sub write_pid($$$)
192 {
193         my ($env_vars, $app, $pid) = @_;
194
195         open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
196         print PID $pid;
197         close(PID);
198 }
199
200 sub read_pid($$)
201 {
202         my ($env_vars, $app) = @_;
203
204         open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
205         my $pid = <PID>;
206         close(PID);
207         return $pid;
208 }
209
210 sub check_or_start($$$$$) {
211         my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
212
213         unlink($env_vars->{NMBD_TEST_LOG});
214         print "STARTING NMBD...";
215         my $pid = fork();
216         if ($pid == 0) {
217                 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
218                 open STDERR, '>&STDOUT';
219
220                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
221
222                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
223
224                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
225                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
226                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
227
228                 if ($nmbd ne "yes") {
229                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
230                                 my $signame = shift;
231                                 print("Skip nmbd received signal $signame");
232                                 exit 0;
233                         };
234                         sleep($maxtime);
235                         exit 0;
236                 }
237
238                 my @optargs = ("-d0");
239                 if (defined($ENV{NMBD_OPTIONS})) {
240                         @optargs = split(/ /, $ENV{NMBD_OPTIONS});
241                 }
242
243                 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
244
245                 my @preargs = ($self->binpath("timelimit"), $maxtime);
246                 if(defined($ENV{NMBD_VALGRIND})) { 
247                         @preargs = split(/ /, $ENV{NMBD_VALGRIND});
248                 }
249
250                 exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
251         }
252         write_pid($env_vars, "nmbd", $pid);
253         print "DONE\n";
254
255         unlink($env_vars->{WINBINDD_TEST_LOG});
256         print "STARTING WINBINDD...";
257         $pid = fork();
258         if ($pid == 0) {
259                 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
260                 open STDERR, '>&STDOUT';
261
262                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
263
264                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
265
266                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
267                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
268                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
269
270                 if ($winbindd ne "yes") {
271                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
272                                 my $signame = shift;
273                                 print("Skip winbindd received signal $signame");
274                                 exit 0;
275                         };
276                         sleep($maxtime);
277                         exit 0;
278                 }
279
280                 my @optargs = ("-d0");
281                 if (defined($ENV{WINBINDD_OPTIONS})) {
282                         @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
283                 }
284
285                 $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd");
286
287                 my @preargs = ($self->binpath("timelimit"), $maxtime);
288                 if(defined($ENV{WINBINDD_VALGRIND})) {
289                         @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
290                 }
291
292                 exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
293         }
294         write_pid($env_vars, "winbindd", $pid);
295         print "DONE\n";
296
297         unlink($env_vars->{SMBD_TEST_LOG});
298         print "STARTING SMBD...";
299         $pid = fork();
300         if ($pid == 0) {
301                 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
302                 open STDERR, '>&STDOUT';
303
304                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
305
306                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
307
308                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
309                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
310                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
311
312                 if ($smbd ne "yes") {
313                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
314                                 my $signame = shift;
315                                 print("Skip smbd received signal $signame");
316                                 exit 0;
317                         };
318                         sleep($maxtime);
319                         exit 0;
320                 }
321
322                 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
323                 my @optargs = ("-d0");
324                 if (defined($ENV{SMBD_OPTIONS})) {
325                         @optargs = split(/ /, $ENV{SMBD_OPTIONS});
326                 }
327                 my @preargs = ($self->binpath("timelimit"), $maxtime);
328                 if(defined($ENV{SMBD_VALGRIND})) {
329                         @preargs = split(/ /,$ENV{SMBD_VALGRIND});
330                 }
331                 exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
332         }
333         write_pid($env_vars, "smbd", $pid);
334         print "DONE\n";
335
336         return 0;
337 }
338
339 sub provision($$$$$$)
340 {
341         my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
342
343         ##
344         ## setup the various environment variables we need
345         ##
346
347         my %ret = ();
348         my $server_ip = "127.0.0.$swiface";
349         my $domain = "SAMBA-TEST";
350
351         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
352         chomp $unix_name;
353         my $unix_uid = $>;
354         my $unix_gids_str = $);
355         my @unix_gids = split(" ", $unix_gids_str);
356
357         my $prefix_abs = abs_path($prefix);
358         my $bindir_abs = abs_path($self->{bindir});
359         my $vfs_modulesdir_abs = ($ENV{VFSLIBDIR} or $bindir_abs);
360
361         my @dirs = ();
362
363         my $shrdir="$prefix_abs/share";
364         push(@dirs,$shrdir);
365
366         my $libdir="$prefix_abs/lib";
367         push(@dirs,$libdir);
368
369         my $piddir="$prefix_abs/pid";
370         push(@dirs,$piddir);
371
372         my $privatedir="$prefix_abs/private";
373         push(@dirs,$privatedir);
374
375         my $lockdir="$prefix_abs/lockdir";
376         push(@dirs,$lockdir);
377
378         my $eventlogdir="$prefix_abs/lockdir/eventlog";
379         push(@dirs,$eventlogdir);
380
381         my $logdir="$prefix_abs/logs";
382         push(@dirs,$logdir);
383
384         my $driver32dir="$shrdir/W32X86";
385         push(@dirs,$driver32dir);
386
387         my $driver64dir="$shrdir/x64";
388         push(@dirs,$driver64dir);
389
390         my $driver40dir="$shrdir/WIN40";
391         push(@dirs,$driver40dir);
392
393         my $ro_shrdir="$shrdir/root-tmp";
394         push(@dirs,$ro_shrdir);
395
396         my $msdfs_shrdir="$shrdir/msdfsshare";
397         push(@dirs,$msdfs_shrdir);
398
399         my $msdfs_deeppath="$msdfs_shrdir/deeppath";
400         push(@dirs,$msdfs_deeppath);
401
402         # this gets autocreated by winbindd
403         my $wbsockdir="$prefix_abs/winbindd";
404         my $wbsockprivdir="$lockdir/winbindd_privileged";
405
406         ## 
407         ## create the test directory layout
408         ##
409         die ("prefix_abs = ''") if $prefix_abs eq "";
410         die ("prefix_abs = '/'") if $prefix_abs eq "/";
411
412         mkdir($prefix_abs, 0777);
413         print "CREATE TEST ENVIRONMENT IN '$prefix'...";
414         system("rm -rf $prefix_abs/*");
415         mkdir($_, 0777) foreach(@dirs);
416
417         ##
418         ## create ro and msdfs share layout
419         ##
420
421         chmod 0755, $ro_shrdir;
422         my $unreadable_file = "$ro_shrdir/unreadable_file";
423         open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
424         close(UNREADABLE_FILE);
425         chmod 0600, $unreadable_file;
426
427         my $msdfs_target = "$ro_shrdir/msdfs-target";
428         open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
429         close(MSDFS_TARGET);
430         chmod 0666, $msdfs_target;
431         symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
432         symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
433
434         my $conffile="$libdir/server.conf";
435
436         my $nss_wrapper_pl = "$ENV{PERL} $RealBin/../lib/nss_wrapper/nss_wrapper.pl";
437         my $nss_wrapper_passwd = "$privatedir/passwd";
438         my $nss_wrapper_group = "$privatedir/group";
439
440         my $mod_printer_pl = "$ENV{PERL} $RealBin/../source3/script/tests/printing/modprinter.pl";
441
442         my @eventlog_list = ("dns server", "application");
443
444         ##
445         ## calculate uids and gids
446         ##
447
448         my ($max_uid, $max_gid);
449         my ($uid_nobody, $uid_root);
450         my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers);
451
452         if ($unix_uid < 0xffff - 2) {
453                 $max_uid = 0xffff;
454         } else {
455                 $max_uid = $unix_uid;
456         }
457
458         $uid_root = $max_uid - 1;
459         $uid_nobody = $max_uid - 2;
460
461         if ($unix_gids[0] < 0xffff - 3) {
462                 $max_gid = 0xffff;
463         } else {
464                 $max_gid = $unix_gids[0];
465         }
466
467         $gid_nobody = $max_gid - 1;
468         $gid_nogroup = $max_gid - 2;
469         $gid_root = $max_gid - 3;
470         $gid_domusers = $max_gid - 4;
471
472         ##
473         ## create conffile
474         ##
475
476         open(CONF, ">$conffile") or die("Unable to open $conffile");
477         print CONF "
478 [global]
479         netbios name = $server
480         interfaces = $server_ip/8
481         bind interfaces only = yes
482         panic action = $RealBin/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
483
484         workgroup = $domain
485
486         private dir = $privatedir
487         pid directory = $piddir
488         lock directory = $lockdir
489         log file = $logdir/log.\%m
490         log level = 0
491
492         name resolve order = bcast
493
494         state directory = $lockdir
495         cache directory = $lockdir
496
497         passdb backend = tdbsam
498
499         time server = yes
500
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
508
509         addprinter command =            $mod_printer_pl -a -s $conffile --
510         deleteprinter command =         $mod_printer_pl -d -s $conffile --
511
512         eventlog list = application \"dns server\"
513
514         kernel oplocks = no
515         kernel change notify = no
516
517         syslog = no
518         printing = bsd
519         printcap name = /dev/null
520
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
526
527 #       min receivefile size = 4000
528
529         max protocol = SMB2
530         read only = no
531         server signing = auto
532
533         smbd:sharedelay = 100000
534 #       smbd:writetimeupdatedelay = 500000
535         map hidden = no
536         map system = no
537         map readonly = no
538         store dos attributes = yes
539         create mask = 755
540         vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
541
542         printing = vlp
543         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
544         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
545         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
546         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
547         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
548         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
549         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
550         lpq cache time = 0
551
552         # Begin extra options
553         $extra_options
554         # End extra options
555
556         #Include user defined custom parameters if set
557 ";
558
559         if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
560                 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
561         }
562
563         print CONF "
564 [tmp]
565         path = $shrdir
566 [ro-tmp]
567         path = $ro_shrdir
568         guest ok = yes
569 [msdfs-share]
570         path = $msdfs_shrdir
571         msdfs root = yes
572         guest ok = yes
573 [hideunread]
574         copy = tmp
575         hide unreadable = yes
576 [tmpcase]
577         copy = tmp
578         case sensitive = yes
579 [hideunwrite]
580         copy = tmp
581         hide unwriteable files = yes
582 [print1]
583         copy = tmp
584         printable = yes
585
586 [print2]
587         copy = print1
588 [print3]
589         copy = print1
590 [lp]
591         copy = print1
592 [print\$]
593         copy = tmp
594         ";
595         close(CONF);
596
597         ##
598         ## create a test account
599         ##
600
601         open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
602         print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
603 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
604 ";
605         if ($unix_uid != 0) {
606                 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
607         }
608         close(PASSWD);
609
610         open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
611         print GROUP "nobody:x:$gid_nobody:
612 nogroup:x:$gid_nogroup:nobody
613 $unix_name-group:x:$unix_gids[0]:
614 domusers:X:$gid_domusers:
615 ";
616         if ($unix_gids[0] != 0) {
617                 print GROUP "root:x:$gid_root:";
618         }
619
620         close(GROUP);
621
622         foreach my $evlog (@eventlog_list) {
623                 my $evlogtdb = "$eventlogdir/$evlog.tdb";
624                 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
625                 close(EVENTLOG);
626         }
627
628         $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
629         $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
630
631         open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
632         print PWD "$password\n$password\n";
633         close(PWD) or die("Unable to set password for test account");
634
635         print "DONE\n";
636
637         $ret{SERVER_IP} = $server_ip;
638         $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
639         $ret{NMBD_TEST_LOG_POS} = 0;
640         $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
641         $ret{WINBINDD_TEST_LOG_POS} = 0;
642         $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
643         $ret{SMBD_TEST_LOG_POS} = 0;
644         $ret{SERVERCONFFILE} = $conffile;
645         $ret{CONFIGURATION} ="-s $conffile";
646         $ret{SERVER} = $server;
647         $ret{USERNAME} = $unix_name;
648         $ret{USERID} = $unix_uid;
649         $ret{DOMAIN} = $domain;
650         $ret{NETBIOSNAME} = $server;
651         $ret{PASSWORD} = $password;
652         $ret{PIDDIR} = $piddir;
653         $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
654         $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
655         $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
656         $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
657         $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
658         $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
659         $ret{LOCAL_PATH} = "$shrdir";
660
661         return \%ret;
662 }
663
664 sub wait_for_start($$)
665 {
666         my ($self, $envvars) = @_;
667
668         # give time for nbt server to register its names
669         print "delaying for nbt name registration\n";
670         sleep(10);
671         # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
672         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
673         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
674         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
675         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
676         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
677         # make sure smbd is also up set
678         print "wait for smbd\n";
679         system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
680         system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
681
682         # Ensure we have domain users mapped.
683         system($self->binpath("net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
684
685         print $self->getlog_env($envvars);
686 }
687
688 1;