DON'T PUSH: Don't log stdout for smbd/nmbd/winbindd.
[asn/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 use target::Samba;
13
14 sub have_ads($) {
15         my ($self) = @_;
16         my $found_ads = 0;
17         my $smbd_build_options = Samba::bindir_path($self, "smbd") . " -b|";
18         open(IN, $smbd_build_options) or die("Unable to run $smbd_build_options: $!");
19
20         while (<IN>) {
21                 if (/WITH_ADS/) {
22                        $found_ads = 1;
23                 }
24         }
25         close IN;
26
27         # If we were not built with ADS support, pretend we were never even available
28         return $found_ads;
29 }
30
31 sub new($$) {
32         my ($classname, $bindir, $binary_mapping, $srcdir, $server_maxtime) = @_;
33         my $self = { vars => {},
34                      bindir => $bindir,
35                      binary_mapping => $binary_mapping,
36                      srcdir => $srcdir,
37                      server_maxtime => $server_maxtime
38         };
39         bless $self;
40         return $self;
41 }
42
43 sub teardown_env($$)
44 {
45         my ($self, $envvars) = @_;
46         my $count = 0;
47         
48         # This should cause smbd to terminate gracefully
49         close($envvars->{STDIN_PIPE});
50
51         my $smbdpid = $envvars->{SMBD_TL_PID};
52         my $nmbdpid = $envvars->{NMBD_TL_PID};
53         my $winbinddpid = $envvars->{WINBINDD_TL_PID};
54
55         # This should give it time to write out the gcov data
56         until ($count > 20) {
57             my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
58             my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
59             my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
60             if ($smbdchild == -1
61                 && $nmbdchild == -1
62                 && $winbinddchild == -1) {
63                 last;
64             }
65             sleep(1);
66             $count++;
67         }
68
69         if ($count <= 20 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
70             return;
71         }
72
73         $self->stop_sig_term($smbdpid);
74         $self->stop_sig_term($nmbdpid);
75         $self->stop_sig_term($winbinddpid);
76
77         $count = 0;
78         until ($count > 10) {
79             my $smbdchild = Samba::cleanup_child($smbdpid, "smbd");
80             my $nmbdchild = Samba::cleanup_child($nmbdpid, "nmbd");
81             my $winbinddchild = Samba::cleanup_child($winbinddpid, "winbindd");
82             if ($smbdchild == -1
83                 && $nmbdchild == -1
84                 && $winbinddchild == -1) {
85                 last;
86             }
87             sleep(1);
88             $count++;
89         }
90
91         if ($count <= 10 && kill(0, $smbdpid, $nmbdpid, $winbinddpid) == 0) {
92             return;
93         }
94
95         warn("timelimit process did not quit on SIGTERM, sending SIGKILL");
96         $self->stop_sig_kill($smbdpid);
97         $self->stop_sig_kill($nmbdpid);
98         $self->stop_sig_kill($winbinddpid);
99
100         return 0;
101 }
102
103 sub getlog_env_app($$$)
104 {
105         my ($self, $envvars, $name) = @_;
106
107         my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
108         my $out = $title;
109
110         open(LOG, "<".$envvars->{$name."_TEST_LOG"});
111
112         seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
113         while (<LOG>) {
114                 $out .= $_;
115         }
116         $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
117         close(LOG);
118
119         return "" if $out eq $title;
120  
121         return $out;
122 }
123
124 sub getlog_env($$)
125 {
126         my ($self, $envvars) = @_;
127         my $ret = "";
128
129         $ret .= $self->getlog_env_app($envvars, "SMBD");
130         $ret .= $self->getlog_env_app($envvars, "NMBD");
131         $ret .= $self->getlog_env_app($envvars, "WINBINDD");
132
133         return $ret;
134 }
135
136 sub check_env($$)
137 {
138         my ($self, $envvars) = @_;
139
140         my $childpid = waitpid(-1, WNOHANG);
141
142         # TODO ...
143         return 1;
144 }
145
146 sub setup_env($$$)
147 {
148         my ($self, $envname, $path) = @_;
149         
150         if (defined($self->{vars}->{$envname})) {
151                 return $self->{vars}->{$envname};
152         }
153
154         if ($envname eq "s3dc") {
155                 return $self->setup_s3dc("$path/s3dc");
156         } elsif ($envname eq "simpleserver") {
157                 return $self->setup_simpleserver("$path/simpleserver");
158         } elsif ($envname eq "maptoguest") {
159                 return $self->setup_maptoguest("$path/maptoguest");
160         } elsif ($envname eq "ktest") {
161                 return $self->setup_ktest("$path/ktest");
162         } elsif ($envname eq "member") {
163                 if (not defined($self->{vars}->{s3dc})) {
164                         if (not defined($self->setup_s3dc("$path/s3dc"))) {
165                                 return undef;
166                         }
167                 }
168                 return $self->setup_member("$path/member", $self->{vars}->{s3dc});
169         } else {
170                 return "UNKNOWN";
171         }
172 }
173
174 sub setup_s3dc($$)
175 {
176         my ($self, $path) = @_;
177
178         print "PROVISIONING S3DC...";
179
180         my $s3dc_options = "
181         domain master = yes
182         domain logons = yes
183         lanman auth = yes
184
185         rpc_server:epmapper = external
186         rpc_server:spoolss = external
187         rpc_server:lsarpc = external
188         rpc_server:samr = external
189         rpc_server:netlogon = external
190         rpc_server:register_embedded_np = yes
191
192         rpc_daemon:epmd = fork
193         rpc_daemon:spoolssd = fork
194         rpc_daemon:lsasd = fork
195 ";
196
197         my $vars = $self->provision($path,
198                                     "LOCALS3DC2",
199                                     "locals3dc2pass",
200                                     $s3dc_options);
201
202         $vars or return undef;
203
204         if (not $self->check_or_start($vars, "yes", "yes", "yes")) {
205                return undef;
206         }
207
208         $vars->{DC_SERVER} = $vars->{SERVER};
209         $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
210         $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
211         $vars->{DC_USERNAME} = $vars->{USERNAME};
212         $vars->{DC_PASSWORD} = $vars->{PASSWORD};
213
214         $self->{vars}->{s3dc} = $vars;
215
216         return $vars;
217 }
218
219 sub setup_member($$$)
220 {
221         my ($self, $prefix, $s3dcvars) = @_;
222
223         print "PROVISIONING MEMBER...";
224
225         my $member_options = "
226         security = domain
227         server signing = on
228 ";
229         my $ret = $self->provision($prefix,
230                                    "LOCALMEMBER3",
231                                    "localmember3pass",
232                                    $member_options);
233
234         $ret or return undef;
235
236         my $net = Samba::bindir_path($self, "net");
237         my $cmd = "";
238         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
239         $cmd .= "$net join $ret->{CONFIGURATION} $s3dcvars->{DOMAIN} member";
240         $cmd .= " -U$s3dcvars->{USERNAME}\%$s3dcvars->{PASSWORD}";
241
242         if (system($cmd) != 0) {
243             warn("Join failed\n$cmd");
244             return undef;
245         }
246
247         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
248                return undef;
249         }
250
251         $ret->{DC_SERVER} = $s3dcvars->{SERVER};
252         $ret->{DC_SERVER_IP} = $s3dcvars->{SERVER_IP};
253         $ret->{DC_NETBIOSNAME} = $s3dcvars->{NETBIOSNAME};
254         $ret->{DC_USERNAME} = $s3dcvars->{USERNAME};
255         $ret->{DC_PASSWORD} = $s3dcvars->{PASSWORD};
256
257         return $ret;
258 }
259
260 sub setup_admember($$$$)
261 {
262         my ($self, $prefix, $dcvars) = @_;
263
264         # If we didn't build with ADS, pretend this env was never available
265         if (not $self->have_ads()) {
266                 return "UNKNOWN";
267         }
268
269         print "PROVISIONING S3 AD MEMBER...";
270
271         my $member_options = "
272         security = ads
273         server signing = on
274         workgroup = $dcvars->{DOMAIN}
275         realm = $dcvars->{REALM}
276 ";
277
278         my $ret = $self->provision($prefix,
279                                    "LOCALADMEMBER",
280                                    "loCalMemberPass",
281                                    $member_options);
282
283         $ret or return undef;
284
285         close(USERMAP);
286         $ret->{DOMAIN} = $dcvars->{DOMAIN};
287         $ret->{REALM} = $dcvars->{REALM};
288
289         my $ctx;
290         my $prefix_abs = abs_path($prefix);
291         $ctx = {};
292         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
293         $ctx->{domain} = $dcvars->{DOMAIN};
294         $ctx->{realm} = $dcvars->{REALM};
295         $ctx->{dnsname} = lc($dcvars->{REALM});
296         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
297         Samba::mk_krb5_conf($ctx, "");
298
299         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
300
301         my $net = Samba::bindir_path($self, "net");
302         my $cmd = "";
303         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
304         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
305         $cmd .= "$net join $ret->{CONFIGURATION}";
306         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
307
308         if (system($cmd) != 0) {
309             warn("Join failed\n$cmd");
310             return undef;
311         }
312
313         # We need world access to this share, as otherwise the domain
314         # administrator from the AD domain provided by Samba4 can't
315         # access the share for tests.
316         chmod 0777, "$prefix/share";
317
318         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
319                 return undef;
320         }
321
322         $ret->{DC_SERVER} = $dcvars->{SERVER};
323         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
324         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
325         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
326         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
327
328         # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
329         $ret->{target} = $self;
330
331         return $ret;
332 }
333
334 sub setup_admember_rfc2307($$$$)
335 {
336         my ($self, $prefix, $dcvars) = @_;
337
338         # If we didn't build with ADS, pretend this env was never available
339         if (not $self->have_ads()) {
340                 return "UNKNOWN";
341         }
342
343         print "PROVISIONING S3 AD MEMBER WITH idmap_rfc2307 config...";
344
345         my $member_options = "
346         security = ads
347         server signing = on
348         workgroup = $dcvars->{DOMAIN}
349         realm = $dcvars->{REALM}
350         idmap config $dcvars->{DOMAIN} : backend = rfc2307
351         idmap config $dcvars->{DOMAIN} : range = 2000000-2999999
352         idmap config $dcvars->{DOMAIN} : ldap_server = ad
353         idmap config $dcvars->{DOMAIN} : bind_path_user = ou=idmap,dc=samba,dc=example,dc=com
354         idmap config $dcvars->{DOMAIN} : bind_path_group = ou=idmap,dc=samba,dc=example,dc=com
355 ";
356
357         my $ret = $self->provision($prefix,
358                                    "RFC2307MEMBER",
359                                    "loCalMemberPass",
360                                    $member_options);
361
362         $ret or return undef;
363
364         close(USERMAP);
365         $ret->{DOMAIN} = $dcvars->{DOMAIN};
366         $ret->{REALM} = $dcvars->{REALM};
367
368         my $ctx;
369         my $prefix_abs = abs_path($prefix);
370         $ctx = {};
371         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
372         $ctx->{domain} = $dcvars->{DOMAIN};
373         $ctx->{realm} = $dcvars->{REALM};
374         $ctx->{dnsname} = lc($dcvars->{REALM});
375         $ctx->{kdc_ipv4} = $dcvars->{SERVER_IP};
376         Samba::mk_krb5_conf($ctx, "");
377
378         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
379
380         my $net = Samba::bindir_path($self, "net");
381         my $cmd = "";
382         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
383         $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
384         $cmd .= "$net join $ret->{CONFIGURATION}";
385         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
386
387         if (system($cmd) != 0) {
388             warn("Join failed\n$cmd");
389             return undef;
390         }
391
392         # We need world access to this share, as otherwise the domain
393         # administrator from the AD domain provided by Samba4 can't
394         # access the share for tests.
395         chmod 0777, "$prefix/share";
396
397         if (not $self->check_or_start($ret, "yes", "yes", "yes")) {
398                 return undef;
399         }
400
401         $ret->{DC_SERVER} = $dcvars->{SERVER};
402         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
403         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
404         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
405         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
406
407         # Special case, this is called from Samba4.pm but needs to use the Samba3 check_env and get_log_env
408         $ret->{target} = $self;
409
410         return $ret;
411 }
412
413 sub setup_simpleserver($$)
414 {
415         my ($self, $path) = @_;
416
417         print "PROVISIONING server with security=share...";
418
419         my $prefix_abs = abs_path($path);
420
421         my $simpleserver_options = "
422         lanman auth = yes
423         vfs objects = xattr_tdb streams_depot
424
425 [vfs_aio_fork]
426         path = $prefix_abs/share
427         vfs objects = aio_fork
428         read only = no
429         vfs_aio_fork:erratic_testing_mode=yes
430 ";
431
432         my $vars = $self->provision($path,
433                                     "LOCALSHARE4",
434                                     "local4pass",
435                                     $simpleserver_options);
436
437         $vars or return undef;
438
439         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
440                return undef;
441         }
442
443         $self->{vars}->{simpleserver} = $vars;
444
445         return $vars;
446 }
447
448 sub setup_ktest($$$)
449 {
450         my ($self, $prefix) = @_;
451
452         # If we didn't build with ADS, pretend this env was never available
453         if (not $self->have_ads()) {
454                 return "UNKNOWN";
455         }
456
457         print "PROVISIONING server with security=ads...";
458
459         my $ktest_options = "
460         workgroup = KTEST
461         realm = ktest.samba.example.com
462         security = ads
463         username map = $prefix/lib/username.map
464         server signing = required
465 ";
466
467         my $ret = $self->provision($prefix,
468                                    "LOCALKTEST6",
469                                    "localktest6pass",
470                                    $ktest_options);
471
472         $ret or return undef;
473
474         my $ctx;
475         my $prefix_abs = abs_path($prefix);
476         $ctx = {};
477         $ctx->{krb5_conf} = "$prefix_abs/lib/krb5.conf";
478         $ctx->{domain} = "KTEST";
479         $ctx->{realm} = "KTEST.SAMBA.EXAMPLE.COM";
480         $ctx->{dnsname} = lc($ctx->{realm});
481         $ctx->{kdc_ipv4} = "0.0.0.0";
482         Samba::mk_krb5_conf($ctx, "");
483
484         $ret->{KRB5_CONFIG} = $ctx->{krb5_conf};
485
486         open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
487         print USERMAP "
488 $ret->{USERNAME} = KTEST\\Administrator
489 ";
490         close(USERMAP);
491
492 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
493 #Samba4 DC with the same parameters as are being used here.  The
494 #domain SID is S-1-5-21-1071277805-689288055-3486227160
495
496         system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
497         chmod 0600, "$prefix/private/secrets.tdb";
498
499 #Make sure there's no old ntdb file.
500         system("rm -f $prefix/private/secrets.ntdb");
501
502 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
503 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
504 #
505 #and having in krb5.conf:
506 # ticket_lifetime = 799718400
507 # renew_lifetime = 799718400
508 #
509 # The commands for the -2 keytab where were:
510 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
511 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
512 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
513 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
514 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
515 #
516 # and then for the -3 keytab, I did
517 #
518 # net changetrustpw; kdestroy and the same again.
519 #
520 # This creates a credential cache with a very long lifetime (2036 at
521 # at 2011-04), and shows that running 'net changetrustpw' does not
522 # break existing logins (for the secrets.tdb method at least).
523 #
524
525         $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
526
527         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-2 $prefix/krb5_ccache-2");
528         chmod 0600, "$prefix/krb5_ccache-2";
529
530         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache-3 $prefix/krb5_ccache-3");
531         chmod 0600, "$prefix/krb5_ccache-3";
532
533         # We need world access to this share, as otherwise the domain
534         # administrator from the AD domain provided by ktest can't
535         # access the share for tests.
536         chmod 0777, "$prefix/share";
537
538         if (not $self->check_or_start($ret, "yes", "no", "yes")) {
539                return undef;
540         }
541         return $ret;
542 }
543
544 sub setup_maptoguest($$)
545 {
546         my ($self, $path) = @_;
547
548         print "PROVISIONING maptoguest...";
549
550         my $options = "
551 map to guest = bad user
552 ";
553
554         my $vars = $self->provision($path,
555                                     "maptoguest",
556                                     "maptoguestpass",
557                                     $options);
558
559         $vars or return undef;
560
561         if (not $self->check_or_start($vars, "yes", "no", "yes")) {
562                return undef;
563         }
564
565         $self->{vars}->{s3maptoguest} = $vars;
566
567         return $vars;
568 }
569
570 sub stop_sig_term($$) {
571         my ($self, $pid) = @_;
572         kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
573 }
574
575 sub stop_sig_kill($$) {
576         my ($self, $pid) = @_;
577         kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
578 }
579
580 sub write_pid($$$)
581 {
582         my ($env_vars, $app, $pid) = @_;
583
584         open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
585         print PID $pid;
586         close(PID);
587 }
588
589 sub read_pid($$)
590 {
591         my ($env_vars, $app) = @_;
592
593         open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
594         my $pid = <PID>;
595         close(PID);
596         return $pid;
597 }
598
599 sub check_or_start($$$$$) {
600         my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
601
602         # use a pipe for stdin in the child processes. This allows
603         # those processes to monitor the pipe for EOF to ensure they
604         # exit when the test script exits
605         pipe(STDIN_READER, $env_vars->{STDIN_PIPE});
606
607         unlink($env_vars->{NMBD_TEST_LOG});
608         print "STARTING NMBD...";
609         my $pid = fork();
610         if ($pid == 0) {
611                 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
612                 open STDERR, '>&STDOUT';
613
614                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
615
616                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
617                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
618                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
619
620                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
621                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
622                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
623
624                 $ENV{UID_WRAPPER} = "1";
625
626                 if ($nmbd ne "yes") {
627                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
628                                 my $signame = shift;
629                                 print("Skip nmbd received signal $signame");
630                                 exit 0;
631                         };
632                         sleep($self->{server_maxtime});
633                         exit 0;
634                 }
635
636                 my @optargs = ("-d0");
637                 if (defined($ENV{NMBD_OPTIONS})) {
638                         @optargs = split(/ /, $ENV{NMBD_OPTIONS});
639                 }
640
641                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "nmbd");
642
643                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
644                 if(defined($ENV{NMBD_VALGRIND})) { 
645                         @preargs = split(/ /, $ENV{NMBD_VALGRIND});
646                 }
647
648                 close($env_vars->{STDIN_PIPE});
649                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
650
651                 exec(@preargs, Samba::bindir_path($self, "nmbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
652         }
653         $env_vars->{NMBD_TL_PID} = $pid;
654         write_pid($env_vars, "nmbd", $pid);
655         print "DONE\n";
656
657         unlink($env_vars->{WINBINDD_TEST_LOG});
658         print "STARTING WINBINDD...";
659         $pid = fork();
660         if ($pid == 0) {
661                 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
662                 open STDERR, '>&STDOUT';
663
664                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
665
666                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
667                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
668                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
669
670                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
671                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
672                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
673
674                 $ENV{UID_WRAPPER} = "1";
675
676                 if ($winbindd ne "yes") {
677                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
678                                 my $signame = shift;
679                                 print("Skip winbindd received signal $signame");
680                                 exit 0;
681                         };
682                         sleep($self->{server_maxtime});
683                         exit 0;
684                 }
685
686                 my @optargs = ("-d0");
687                 if (defined($ENV{WINBINDD_OPTIONS})) {
688                         @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
689                 }
690
691                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "winbindd");
692
693                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
694                 if(defined($ENV{WINBINDD_VALGRIND})) {
695                         @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
696                 }
697
698                 print "Starting winbindd with config $env_vars->{SERVERCONFFILE}\n";
699
700                 close($env_vars->{STDIN_PIPE});
701                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
702
703                 exec(@preargs, Samba::bindir_path($self, "winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
704         }
705         $env_vars->{WINBINDD_TL_PID} = $pid;
706         write_pid($env_vars, "winbindd", $pid);
707         print "DONE\n";
708
709         unlink($env_vars->{SMBD_TEST_LOG});
710         print "STARTING SMBD...";
711         $pid = fork();
712         if ($pid == 0) {
713                 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
714                 open STDERR, '>&STDOUT';
715
716                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
717
718                 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
719                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
720                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
721
722                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
723                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
724                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
725
726                 $ENV{UID_WRAPPER} = "1";
727
728                 if ($smbd ne "yes") {
729                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
730                                 my $signame = shift;
731                                 print("Skip smbd received signal $signame");
732                                 exit 0;
733                         };
734                         sleep($self->{server_maxtime});
735                         exit 0;
736                 }
737
738                 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "smbd");
739                 my @optargs = ("-d0");
740                 if (defined($ENV{SMBD_OPTIONS})) {
741                         @optargs = split(/ /, $ENV{SMBD_OPTIONS});
742                 }
743                 my @preargs = (Samba::bindir_path($self, "timelimit"), $self->{server_maxtime});
744                 if(defined($ENV{SMBD_VALGRIND})) {
745                         @preargs = split(/ /,$ENV{SMBD_VALGRIND});
746                 }
747
748                 close($env_vars->{STDIN_PIPE});
749                 open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
750
751                 exec(@preargs, Samba::bindir_path($self, "smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
752         }
753         $env_vars->{SMBD_TL_PID} = $pid;
754         write_pid($env_vars, "smbd", $pid);
755         print "DONE\n";
756
757         close(STDIN_READER);
758
759         return $self->wait_for_start($env_vars, $nmbd, $winbindd, $smbd);
760 }
761
762 sub provision($$$$$$)
763 {
764         my ($self, $prefix, $server, $password, $extra_options, $no_delete_prefix) = @_;
765
766         ##
767         ## setup the various environment variables we need
768         ##
769
770         my $swiface = Samba::get_interface($server);
771         my %ret = ();
772         my $server_ip = "127.0.0.$swiface";
773         my $domain = "SAMBA-TEST";
774
775         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
776         chomp $unix_name;
777         my $unix_uid = $>;
778         my $unix_gids_str = $);
779         my @unix_gids = split(" ", $unix_gids_str);
780
781         my $prefix_abs = abs_path($prefix);
782         my $bindir_abs = abs_path($self->{bindir});
783
784         my $dns_host_file = "$ENV{SELFTEST_PREFIX}/dns_host_file";
785
786         my @dirs = ();
787
788         my $shrdir="$prefix_abs/share";
789         push(@dirs,$shrdir);
790
791         my $libdir="$prefix_abs/lib";
792         push(@dirs,$libdir);
793
794         my $piddir="$prefix_abs/pid";
795         push(@dirs,$piddir);
796
797         my $privatedir="$prefix_abs/private";
798         push(@dirs,$privatedir);
799
800         my $lockdir="$prefix_abs/lockdir";
801         push(@dirs,$lockdir);
802
803         my $eventlogdir="$prefix_abs/lockdir/eventlog";
804         push(@dirs,$eventlogdir);
805
806         my $logdir="$prefix_abs/logs";
807         push(@dirs,$logdir);
808
809         my $driver32dir="$shrdir/W32X86";
810         push(@dirs,$driver32dir);
811
812         my $driver64dir="$shrdir/x64";
813         push(@dirs,$driver64dir);
814
815         my $driver40dir="$shrdir/WIN40";
816         push(@dirs,$driver40dir);
817
818         my $ro_shrdir="$shrdir/root-tmp";
819         push(@dirs,$ro_shrdir);
820
821         my $msdfs_shrdir="$shrdir/msdfsshare";
822         push(@dirs,$msdfs_shrdir);
823
824         my $msdfs_deeppath="$msdfs_shrdir/deeppath";
825         push(@dirs,$msdfs_deeppath);
826
827         # this gets autocreated by winbindd
828         my $wbsockdir="$prefix_abs/winbindd";
829         my $wbsockprivdir="$lockdir/winbindd_privileged";
830
831         my $nmbdsockdir="$prefix_abs/nmbd";
832         unlink($nmbdsockdir);
833
834         ## 
835         ## create the test directory layout
836         ##
837         die ("prefix_abs = ''") if $prefix_abs eq "";
838         die ("prefix_abs = '/'") if $prefix_abs eq "/";
839
840         mkdir($prefix_abs, 0777);
841         print "CREATE TEST ENVIRONMENT IN '$prefix'...";
842         if (not defined($no_delete_prefix) or not $no_delete_prefix) {
843             system("rm -rf $prefix_abs/*");
844         }
845         mkdir($_, 0777) foreach(@dirs);
846
847         ##
848         ## lockdir and piddir must be 0755
849         ##
850         chmod 0755, $lockdir;
851         chmod 0755, $piddir;
852
853
854         ##
855         ## create ro and msdfs share layout
856         ##
857
858         chmod 0755, $ro_shrdir;
859         my $unreadable_file = "$ro_shrdir/unreadable_file";
860         unless (open(UNREADABLE_FILE, ">$unreadable_file")) {
861                 warn("Unable to open $unreadable_file");
862                 return undef;
863         }
864         close(UNREADABLE_FILE);
865         chmod 0600, $unreadable_file;
866
867         my $msdfs_target = "$ro_shrdir/msdfs-target";
868         unless (open(MSDFS_TARGET, ">$msdfs_target")) {
869                 warn("Unable to open $msdfs_target");
870                 return undef;
871         }
872         close(MSDFS_TARGET);
873         chmod 0666, $msdfs_target;
874         symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
875         symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
876
877         my $conffile="$libdir/server.conf";
878
879         my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
880         my $nss_wrapper_passwd = "$privatedir/passwd";
881         my $nss_wrapper_group = "$privatedir/group";
882
883         my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
884
885         my @eventlog_list = ("dns server", "application");
886
887         ##
888         ## calculate uids and gids
889         ##
890
891         my ($max_uid, $max_gid);
892         my ($uid_nobody, $uid_root, $uid_pdbtest);
893         my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers, $gid_domadmins);
894
895         if ($unix_uid < 0xffff - 2) {
896                 $max_uid = 0xffff;
897         } else {
898                 $max_uid = $unix_uid;
899         }
900
901         $uid_root = $max_uid - 1;
902         $uid_nobody = $max_uid - 2;
903         $uid_pdbtest = $max_uid - 3;
904
905         if ($unix_gids[0] < 0xffff - 3) {
906                 $max_gid = 0xffff;
907         } else {
908                 $max_gid = $unix_gids[0];
909         }
910
911         $gid_nobody = $max_gid - 1;
912         $gid_nogroup = $max_gid - 2;
913         $gid_root = $max_gid - 3;
914         $gid_domusers = $max_gid - 4;
915         $gid_domadmins = $max_gid - 5;
916
917         ##
918         ## create conffile
919         ##
920
921         unless (open(CONF, ">$conffile")) {
922                 warn("Unable to open $conffile");
923                 return undef;
924         }
925         print CONF "
926 [global]
927         netbios name = $server
928         interfaces = $server_ip/8
929         bind interfaces only = yes
930         panic action = $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
931         smbd:suicide mode = yes
932
933         workgroup = $domain
934
935         private dir = $privatedir
936         pid directory = $piddir
937         lock directory = $lockdir
938         log file = $logdir/log.\%m
939         log level = 1
940         debug pid = yes
941         max log size = 0
942
943         state directory = $lockdir
944         cache directory = $lockdir
945
946         passdb backend = tdbsam
947
948         time server = yes
949
950         add user script =               $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
951         add group script =              $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action add --name %g
952         add machine script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
953         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
954         delete user script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
955         delete group script =           $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action delete --name %g
956         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
957
958         addprinter command =            $mod_printer_pl -a -s $conffile --
959         deleteprinter command =         $mod_printer_pl -d -s $conffile --
960
961         eventlog list = application \"dns server\"
962
963         kernel oplocks = no
964         kernel change notify = no
965
966         syslog = no
967         printing = bsd
968         printcap name = /dev/null
969
970         winbindd:socket dir = $wbsockdir
971         nmbd:socket dir = $nmbdsockdir
972         idmap config * : range = 100000-200000
973         winbind enum users = yes
974         winbind enum groups = yes
975
976 #       min receivefile size = 4000
977
978         read only = no
979         server signing = auto
980
981         smbd:sharedelay = 100000
982         smbd:writetimeupdatedelay = 500000
983         map hidden = no
984         map system = no
985         map readonly = no
986         store dos attributes = yes
987         create mask = 755
988         dos filemode = yes
989         vfs objects = acl_xattr fake_acls xattr_tdb streams_depot
990
991         printing = vlp
992         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
993         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
994         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
995         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
996         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
997         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
998         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
999         lpq cache time = 0
1000
1001         ncalrpc dir = $prefix_abs/ncalrpc
1002         resolv:host file = $dns_host_file
1003
1004         # The samba3.blackbox.smbclient_s3 test uses this to test that
1005         # sending messages works, and that the %m sub works.
1006         message command = mv %s $shrdir/message.%m
1007
1008         # Begin extra options
1009         $extra_options
1010         # End extra options
1011
1012         #Include user defined custom parameters if set
1013 ";
1014
1015         if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
1016                 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
1017         }
1018
1019         print CONF "
1020 [tmp]
1021         path = $shrdir
1022         comment = smb username is [%U]
1023 [tmpenc]
1024         path = $shrdir
1025         comment = encrypt smb username is [%U]
1026         smb encrypt = required
1027         vfs objects = dirsort
1028 [tmpguest]
1029         path = $shrdir
1030         guest ok = yes
1031 [guestonly]
1032         path = $shrdir
1033         guest only = yes
1034         guest ok = yes
1035 [forceuser]
1036         path = $shrdir
1037         force user = $unix_name
1038         guest ok = yes
1039 [forcegroup]
1040         path = $shrdir
1041         force group = nogroup
1042         guest ok = yes
1043 [ro-tmp]
1044         path = $ro_shrdir
1045         guest ok = yes
1046 [write-list-tmp]
1047         path = $shrdir
1048         read only = yes
1049         write list = $unix_name
1050 [valid-users-tmp]
1051         path = $shrdir
1052         valid users = $unix_name
1053 [msdfs-share]
1054         path = $msdfs_shrdir
1055         msdfs root = yes
1056         guest ok = yes
1057 [hideunread]
1058         copy = tmp
1059         hide unreadable = yes
1060 [tmpcase]
1061         copy = tmp
1062         case sensitive = yes
1063 [hideunwrite]
1064         copy = tmp
1065         hide unwriteable files = yes
1066 [durable]
1067         copy = tmp
1068         kernel share modes = no
1069         kernel oplocks = no
1070         posix locking = no
1071 [print1]
1072         copy = tmp
1073         printable = yes
1074
1075 [print2]
1076         copy = print1
1077 [print3]
1078         copy = print1
1079         default devmode = no
1080 [lp]
1081         copy = print1
1082
1083 [nfs4acl_simple]
1084         path = $shrdir
1085         comment = smb username is [%U]
1086         nfs4:mode = simple
1087         vfs objects = nfs4acl_xattr xattr_tdb
1088
1089 [nfs4acl_special]
1090         path = $shrdir
1091         comment = smb username is [%U]
1092         nfs4:mode = special
1093         vfs objects = nfs4acl_xattr xattr_tdb
1094
1095 [xcopy_share]
1096         path = $shrdir
1097         comment = smb username is [%U]
1098         create mask = 777
1099         force create mode = 777
1100 [posix_share]
1101         path = $shrdir
1102         comment = smb username is [%U]
1103         create mask = 0777
1104         force create mode = 0
1105         directory mask = 0777
1106         force directory mode = 0
1107         vfs objects = xattr_tdb
1108
1109 [print\$]
1110         copy = tmp
1111         ";
1112         close(CONF);
1113
1114         ##
1115         ## create a test account
1116         ##
1117
1118         unless (open(PASSWD, ">$nss_wrapper_passwd")) {
1119            warn("Unable to open $nss_wrapper_passwd");
1120            return undef;
1121         } 
1122         print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
1123 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
1124 pdbtest:x:$uid_pdbtest:$gid_nogroup:pdbtest gecos:$prefix_abs:/bin/false
1125 ";
1126         if ($unix_uid != 0) {
1127                 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
1128         }
1129         close(PASSWD);
1130
1131         unless (open(GROUP, ">$nss_wrapper_group")) {
1132              warn("Unable to open $nss_wrapper_group");
1133              return undef;
1134         }
1135         print GROUP "nobody:x:$gid_nobody:
1136 nogroup:x:$gid_nogroup:nobody
1137 $unix_name-group:x:$unix_gids[0]:
1138 domusers:X:$gid_domusers:
1139 domadmins:X:$gid_domadmins:
1140 ";
1141         if ($unix_gids[0] != 0) {
1142                 print GROUP "root:x:$gid_root:";
1143         }
1144
1145         close(GROUP);
1146
1147         foreach my $evlog (@eventlog_list) {
1148                 my $evlogtdb = "$eventlogdir/$evlog.tdb";
1149                 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
1150                 close(EVENTLOG);
1151         }
1152
1153         $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1154         $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1155
1156         my $cmd = Samba::bindir_path($self, "smbpasswd")." -c $conffile -L -s -a $unix_name > /dev/null";
1157         unless (open(PWD, "|$cmd")) {
1158              warn("Unable to set password for test account\n$cmd");
1159              return undef;
1160         }
1161         print PWD "$password\n$password\n";
1162         unless (close(PWD)) {
1163              warn("Unable to set password for test account\n$cmd");
1164              return undef; 
1165         }
1166         print "DONE\n";
1167
1168         open(DNS_UPDATE_LIST, ">$prefix/dns_update_list") or die("Unable to open $$prefix/dns_update_list");
1169         print DNS_UPDATE_LIST "A $server. $server_ip";
1170         close(DNS_UPDATE_LIST);
1171
1172         if (system("$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate --all-interfaces --use-file=$dns_host_file -s $conffile --update-list=$prefix/dns_update_list --no-substiutions --no-credentials") != 0) {
1173                 die "Unable to update hostname into $dns_host_file";
1174         }
1175
1176         $ret{SERVER_IP} = $server_ip;
1177         $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
1178         $ret{NMBD_TEST_LOG_POS} = 0;
1179         $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
1180         $ret{WINBINDD_TEST_LOG_POS} = 0;
1181         $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
1182         $ret{SMBD_TEST_LOG_POS} = 0;
1183         $ret{SERVERCONFFILE} = $conffile;
1184         $ret{CONFIGURATION} ="-s $conffile";
1185         $ret{SERVER} = $server;
1186         $ret{USERNAME} = $unix_name;
1187         $ret{USERID} = $unix_uid;
1188         $ret{DOMAIN} = $domain;
1189         $ret{NETBIOSNAME} = $server;
1190         $ret{PASSWORD} = $password;
1191         $ret{PIDDIR} = $piddir;
1192         $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
1193         $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
1194         $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
1195         $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
1196         $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
1197         $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
1198         $ret{NSS_WRAPPER_WINBIND_SO_PATH} = Samba::nss_wrapper_winbind_so_path($self);
1199         $ret{LOCAL_PATH} = "$shrdir";
1200
1201         return \%ret;
1202 }
1203
1204 sub wait_for_start($$$$$)
1205 {
1206         my ($self, $envvars, $nmbd, $winbindd, $smbd) = @_;
1207         my $ret;
1208
1209         if ($nmbd eq "yes") {
1210             # give time for nbt server to register its names
1211             print "delaying for nbt name registration\n";
1212             sleep(10);
1213             # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
1214             my $nmblookup = Samba::bindir_path($self, "nmblookup3");
1215             system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
1216             system("$nmblookup $envvars->{CONFIGURATION} __SAMBA__");
1217             system("$nmblookup $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
1218             system("$nmblookup $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
1219             system("$nmblookup $envvars->{CONFIGURATION} $envvars->{SERVER}");
1220         }
1221
1222         if ($winbindd eq "yes") {
1223             print "checking for winbindd\n";
1224             my $count = 0;
1225             do {
1226                 $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " -p");
1227                 if ($ret != 0) {
1228                     sleep(2);
1229                 }
1230                 $count++;
1231             } while ($ret != 0 && $count < 10);
1232             if ($count == 10) {
1233                 print "WINBINDD not reachable after 20 seconds\n";
1234                 teardown_env($self, $envvars);
1235                 return 0;
1236             }
1237         }
1238
1239         if ($smbd eq "yes") {
1240             # make sure smbd is also up set
1241             print "wait for smbd\n";
1242
1243             my $count = 0;
1244             do {
1245                 $ret = system(Samba::bindir_path($self, "smbclient3") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER} -U% -p 139");
1246                 if ($ret != 0) {
1247                     sleep(2);
1248                 }
1249                 $count++
1250             } while ($ret != 0 && $count < 10);
1251             if ($count == 10) {
1252                 print "SMBD failed to start up in a reasonable time (20sec)\n";
1253                 teardown_env($self, $envvars);
1254                 return 0;
1255             }
1256         }
1257
1258         # Ensure we have domain users mapped.
1259         $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
1260         if ($ret != 0) {
1261             return 1;
1262         }
1263         $ret = system(Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} groupmap add rid=512 unixgroup=domadmins type=domain");
1264         if ($ret != 0) {
1265             return 1;
1266         }
1267
1268         if ($winbindd eq "yes") {
1269             # note: creating builtin groups requires winbindd for the
1270             # unix id allocator
1271             $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "net") ." $envvars->{CONFIGURATION} sam createbuiltingroup Users");
1272             if ($ret != 0) {
1273                 print "Failed to create BUILTIN\\Users group\n";
1274                 return 0;
1275             }
1276             my $count = 0;
1277             do {
1278                 system(Samba::bindir_path($self, "net") . " $envvars->{CONFIGURATION} cache flush");
1279                 $ret = system("WINBINDD_SOCKET_DIR=" . $envvars->{WINBINDD_SOCKET_DIR} . " " . Samba::bindir_path($self, "wbinfo") . " --sid-to-gid=S-1-5-32-545");
1280                 if ($ret != 0) {
1281                     sleep(2);
1282                 }
1283                 $count++;
1284             } while ($ret != 0 && $count < 10);
1285             if ($count == 10) {
1286                 print "WINBINDD not reachable after 20 seconds\n";
1287                 teardown_env($self, $envvars);
1288                 return 0;
1289             }
1290         }
1291
1292         print $self->getlog_env($envvars);
1293
1294         return 1;
1295 }
1296
1297 1;