s3-selftest Add testing of kerberos login
[nivanova/samba-autobuild/.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, $srcdir) = @_;
28         my $self = { bindir => $bindir,
29                      srcdir => $srcdir
30         };
31         bless $self;
32         return $self;
33 }
34
35 sub teardown_env($$)
36 {
37         my ($self, $envvars) = @_;
38
39         my $smbdpid = read_pid($envvars, "smbd");
40         my $nmbdpid = read_pid($envvars, "nmbd");
41         my $winbinddpid = read_pid($envvars, "winbindd");
42
43         $self->stop_sig_term($smbdpid);
44         $self->stop_sig_term($nmbdpid);
45         $self->stop_sig_term($winbinddpid);
46
47         sleep(2);
48
49         $self->stop_sig_kill($smbdpid);
50         $self->stop_sig_kill($nmbdpid);
51         $self->stop_sig_kill($winbinddpid);
52
53         return 0;
54 }
55
56 sub getlog_env_app($$$)
57 {
58         my ($self, $envvars, $name) = @_;
59
60         my $title = "$name LOG of: $envvars->{NETBIOSNAME}\n";
61         my $out = $title;
62
63         open(LOG, "<".$envvars->{$name."_TEST_LOG"});
64
65         seek(LOG, $envvars->{$name."_TEST_LOG_POS"}, SEEK_SET);
66         while (<LOG>) {
67                 $out .= $_;
68         }
69         $envvars->{$name."_TEST_LOG_POS"} = tell(LOG);
70         close(LOG);
71
72         return "" if $out eq $title;
73  
74         return $out;
75 }
76
77 sub getlog_env($$)
78 {
79         my ($self, $envvars) = @_;
80         my $ret = "";
81
82         $ret .= $self->getlog_env_app($envvars, "SMBD");
83         $ret .= $self->getlog_env_app($envvars, "NMBD");
84         $ret .= $self->getlog_env_app($envvars, "WINBINDD");
85
86         return $ret;
87 }
88
89 sub check_env($$)
90 {
91         my ($self, $envvars) = @_;
92
93         # TODO ...
94         return 1;
95 }
96
97 sub setup_env($$$)
98 {
99         my ($self, $envname, $path) = @_;
100         
101         if ($envname eq "dc") {
102                 return $self->setup_dc("$path/dc");
103         } elsif ($envname eq "secshare") {
104                 return $self->setup_secshare("$path/secshare");
105         } elsif ($envname eq "ktest") {
106                 return $self->setup_ktest("$path/ktest");
107         } elsif ($envname eq "secserver") {
108                 if (not defined($self->{vars}->{dc})) {
109                         $self->setup_dc("$path/dc");
110                 }
111                 return $self->setup_secserver("$path/secserver", $self->{vars}->{dc});
112         } elsif ($envname eq "member") {
113                 if (not defined($self->{vars}->{dc})) {
114                         $self->setup_dc("$path/dc");
115                 }
116                 return $self->setup_member("$path/member", $self->{vars}->{dc});
117         } else {
118                 return undef;
119         }
120 }
121
122 sub setup_dc($$)
123 {
124         my ($self, $path) = @_;
125
126         print "PROVISIONING DC...";
127
128         my $dc_options = "
129         domain master = yes
130         domain logons = yes
131         lanman auth = yes
132 ";
133
134         my $vars = $self->provision($path,
135                                     "LOCALDC2",
136                                     2,
137                                     "localdc2pass",
138                                     $dc_options);
139
140         $self->check_or_start($vars,
141                               ($ENV{SMBD_MAXTIME} or 2700),
142                                "yes", "yes", "yes");
143
144         $self->wait_for_start($vars);
145
146         $vars->{DC_SERVER} = $vars->{SERVER};
147         $vars->{DC_SERVER_IP} = $vars->{SERVER_IP};
148         $vars->{DC_NETBIOSNAME} = $vars->{NETBIOSNAME};
149         $vars->{DC_USERNAME} = $vars->{USERNAME};
150         $vars->{DC_PASSWORD} = $vars->{PASSWORD};
151
152         $self->{vars}->{dc} = $vars;
153
154         return $vars;
155 }
156
157 sub setup_member($$$)
158 {
159         my ($self, $prefix, $dcvars) = @_;
160
161         print "PROVISIONING MEMBER...";
162
163         my $member_options = "
164         security = domain
165         server signing = on
166 ";
167         my $ret = $self->provision($prefix,
168                                    "LOCALMEMBER3",
169                                    3,
170                                    "localmember3pass",
171                                    $member_options);
172
173         $ret or die("Unable to provision");
174
175         my $net = $self->binpath("net");
176         my $cmd = "";
177         $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
178         $cmd .= "$net join $ret->{CONFIGURATION} $dcvars->{DOMAIN} member";
179         $cmd .= " -U$dcvars->{USERNAME}\%$dcvars->{PASSWORD}";
180
181         system($cmd) == 0 or die("Join failed\n$cmd");
182
183         $self->check_or_start($ret,
184                               ($ENV{SMBD_MAXTIME} or 2700),
185                                "yes", "yes", "yes");
186
187         $self->wait_for_start($ret);
188
189         $ret->{DC_SERVER} = $dcvars->{SERVER};
190         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
191         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
192         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
193         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
194
195         return $ret;
196 }
197
198 sub setup_secshare($$)
199 {
200         my ($self, $path) = @_;
201
202         print "PROVISIONING server with security=share...";
203
204         my $secshare_options = "
205         security = share
206         lanman auth = yes
207 ";
208
209         my $vars = $self->provision($path,
210                                     "LOCALSHARE4",
211                                     4,
212                                     "local4pass",
213                                     $secshare_options);
214
215         $self->check_or_start($vars,
216                               ($ENV{SMBD_MAXTIME} or 2700),
217                                "yes", "no", "yes");
218
219         $self->wait_for_start($vars);
220
221         $self->{vars}->{secshare} = $vars;
222
223         return $vars;
224 }
225
226 sub setup_secserver($$$)
227 {
228         my ($self, $prefix, $dcvars) = @_;
229
230         print "PROVISIONING server with security=server...";
231
232         my $secserver_options = "
233         security = server
234         password server = $dcvars->{SERVER_IP}
235 ";
236
237         my $ret = $self->provision($prefix,
238                                    "LOCALSERVER5",
239                                    5,
240                                    "localserver5pass",
241                                    $secserver_options);
242
243         $ret or die("Unable to provision");
244
245         $self->check_or_start($ret,
246                               ($ENV{SMBD_MAXTIME} or 2700),
247                                "yes", "no", "yes");
248
249         $self->wait_for_start($ret);
250
251         $ret->{DC_SERVER} = $dcvars->{SERVER};
252         $ret->{DC_SERVER_IP} = $dcvars->{SERVER_IP};
253         $ret->{DC_NETBIOSNAME} = $dcvars->{NETBIOSNAME};
254         $ret->{DC_USERNAME} = $dcvars->{USERNAME};
255         $ret->{DC_PASSWORD} = $dcvars->{PASSWORD};
256
257         return $ret;
258 }
259
260 sub setup_ktest($$$)
261 {
262         my ($self, $prefix, $dcvars) = @_;
263
264         print "PROVISIONING server with security=ads...";
265
266         my $ktest_options = "
267         workgroup = KTEST
268         realm = ktest.samba.example.com
269         security = ads
270         username map = $prefix/lib/username.map
271 ";
272
273         my $ret = $self->provision($prefix,
274                                    "LOCALKTEST6",
275                                    5,
276                                    "localktest6pass",
277                                    $ktest_options);
278
279         $ret or die("Unable to provision");
280
281         open(USERMAP, ">$prefix/lib/username.map") or die("Unable to open $prefix/lib/username.map");
282         print USERMAP "
283 $ret->{USERNAME} = KTEST\\Administrator
284 ";
285         close(USERMAP);
286
287 #This is the secrets.tdb created by 'net ads join' from Samba3 to a
288 #Samba4 DC with the same parameters as are being used here.  The
289 #domain SID is S-1-5-21-1071277805-689288055-3486227160
290
291         system("cp $self->{srcdir}/source3/selftest/ktest-secrets.tdb $prefix/private/secrets.tdb");
292         chmod 0600, "$prefix/private/secrets.tdb";
293
294 #This uses a pre-calculated krb5 credentials cache, obtained by running Samba4 with:
295 # "--option=kdc:service ticket lifetime=239232" "--option=kdc:user ticket lifetime=239232" "--option=kdc:renewal lifetime=239232"
296 #
297 #and having in krb5.conf:
298 # ticket_lifetime = 799718400
299 # renew_lifetime = 799718400
300 #
301 # The commands run were:
302 # kinit administrator@KTEST.SAMBA.EXAMPLE.COM
303 # kvno host/localktest6@KTEST.SAMBA.EXAMPLE.COM
304 # kvno cifs/localktest6@KTEST.SAMBA.EXAMPLE.COM
305 # kvno host/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
306 # kvno cifs/LOCALKTEST6@KTEST.SAMBA.EXAMPLE.COM
307 #
308 # This creates a credential cache with a very long lifetime (2036 at at 2011-04)
309
310         $ret->{KRB5_CCACHE}="FILE:$prefix/krb5_ccache";
311
312         system("cp $self->{srcdir}/source3/selftest/ktest-krb5_ccache $prefix/krb5_ccache");
313         chmod 0600, "$prefix/krb5_ccache";
314
315         $self->check_or_start($ret,
316                               ($ENV{SMBD_MAXTIME} or 2700),
317                                "yes", "no", "yes");
318
319         $self->wait_for_start($ret);
320         return $ret;
321 }
322
323 sub stop_sig_term($$) {
324         my ($self, $pid) = @_;
325         kill("USR1", $pid) or kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
326 }
327
328 sub stop_sig_kill($$) {
329         my ($self, $pid) = @_;
330         kill("ALRM", $pid) or warn("Unable to kill $pid: $!");
331 }
332
333 sub write_pid($$$)
334 {
335         my ($env_vars, $app, $pid) = @_;
336
337         open(PID, ">$env_vars->{PIDDIR}/timelimit.$app.pid");
338         print PID $pid;
339         close(PID);
340 }
341
342 sub read_pid($$)
343 {
344         my ($env_vars, $app) = @_;
345
346         open(PID, "<$env_vars->{PIDDIR}/timelimit.$app.pid");
347         my $pid = <PID>;
348         close(PID);
349         return $pid;
350 }
351
352 sub check_or_start($$$$$) {
353         my ($self, $env_vars, $maxtime, $nmbd, $winbindd, $smbd) = @_;
354
355         unlink($env_vars->{NMBD_TEST_LOG});
356         print "STARTING NMBD...";
357         my $pid = fork();
358         if ($pid == 0) {
359                 open STDOUT, ">$env_vars->{NMBD_TEST_LOG}";
360                 open STDERR, '>&STDOUT';
361
362                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
363
364                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
365                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
366
367                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
368                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
369                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
370
371                 if ($nmbd ne "yes") {
372                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
373                                 my $signame = shift;
374                                 print("Skip nmbd received signal $signame");
375                                 exit 0;
376                         };
377                         sleep($maxtime);
378                         exit 0;
379                 }
380
381                 my @optargs = ("-d0");
382                 if (defined($ENV{NMBD_OPTIONS})) {
383                         @optargs = split(/ /, $ENV{NMBD_OPTIONS});
384                 }
385
386                 $ENV{MAKE_TEST_BINARY} = $self->binpath("nmbd");
387
388                 my @preargs = ($self->binpath("timelimit"), $maxtime);
389                 if(defined($ENV{NMBD_VALGRIND})) { 
390                         @preargs = split(/ /, $ENV{NMBD_VALGRIND});
391                 }
392
393                 exec(@preargs, $self->binpath("nmbd"), "-F", "--no-process-group", "-S", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
394         }
395         write_pid($env_vars, "nmbd", $pid);
396         print "DONE\n";
397
398         unlink($env_vars->{WINBINDD_TEST_LOG});
399         print "STARTING WINBINDD...";
400         $pid = fork();
401         if ($pid == 0) {
402                 open STDOUT, ">$env_vars->{WINBINDD_TEST_LOG}";
403                 open STDERR, '>&STDOUT';
404
405                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
406
407                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
408                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
409
410                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
411                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
412                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
413
414                 if ($winbindd ne "yes") {
415                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
416                                 my $signame = shift;
417                                 print("Skip winbindd received signal $signame");
418                                 exit 0;
419                         };
420                         sleep($maxtime);
421                         exit 0;
422                 }
423
424                 my @optargs = ("-d0");
425                 if (defined($ENV{WINBINDD_OPTIONS})) {
426                         @optargs = split(/ /, $ENV{WINBINDD_OPTIONS});
427                 }
428
429                 $ENV{MAKE_TEST_BINARY} = $self->binpath("winbindd");
430
431                 my @preargs = ($self->binpath("timelimit"), $maxtime);
432                 if(defined($ENV{WINBINDD_VALGRIND})) {
433                         @preargs = split(/ /, $ENV{WINBINDD_VALGRIND});
434                 }
435
436                 exec(@preargs, $self->binpath("winbindd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
437         }
438         write_pid($env_vars, "winbindd", $pid);
439         print "DONE\n";
440
441         unlink($env_vars->{SMBD_TEST_LOG});
442         print "STARTING SMBD...";
443         $pid = fork();
444         if ($pid == 0) {
445                 open STDOUT, ">$env_vars->{SMBD_TEST_LOG}";
446                 open STDERR, '>&STDOUT';
447
448                 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
449
450                 $ENV{WINBINDD_SOCKET_DIR} = $env_vars->{WINBINDD_SOCKET_DIR};
451                 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
452
453                 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
454                 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
455                 $ENV{NSS_WRAPPER_WINBIND_SO_PATH} = $env_vars->{NSS_WRAPPER_WINBIND_SO_PATH};
456
457                 if ($smbd ne "yes") {
458                         $SIG{USR1} = $SIG{ALRM} = $SIG{INT} = $SIG{QUIT} = $SIG{TERM} = sub {
459                                 my $signame = shift;
460                                 print("Skip smbd received signal $signame");
461                                 exit 0;
462                         };
463                         sleep($maxtime);
464                         exit 0;
465                 }
466
467                 $ENV{MAKE_TEST_BINARY} = $self->binpath("smbd");
468                 my @optargs = ("-d0");
469                 if (defined($ENV{SMBD_OPTIONS})) {
470                         @optargs = split(/ /, $ENV{SMBD_OPTIONS});
471                 }
472                 my @preargs = ($self->binpath("timelimit"), $maxtime);
473                 if(defined($ENV{SMBD_VALGRIND})) {
474                         @preargs = split(/ /,$ENV{SMBD_VALGRIND});
475                 }
476                 exec(@preargs, $self->binpath("smbd"), "-F", "--no-process-group", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
477         }
478         write_pid($env_vars, "smbd", $pid);
479         print "DONE\n";
480
481         return 0;
482 }
483
484 sub provision($$$$$$)
485 {
486         my ($self, $prefix, $server, $swiface, $password, $extra_options) = @_;
487
488         ##
489         ## setup the various environment variables we need
490         ##
491
492         my %ret = ();
493         my $server_ip = "127.0.0.$swiface";
494         my $domain = "SAMBA-TEST";
495
496         my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `PATH=/usr/ucb:$ENV{PATH} whoami`);
497         chomp $unix_name;
498         my $unix_uid = $>;
499         my $unix_gids_str = $);
500         my @unix_gids = split(" ", $unix_gids_str);
501
502         my $prefix_abs = abs_path($prefix);
503         my $bindir_abs = abs_path($self->{bindir});
504         my $vfs_modulesdir_abs = ($ENV{VFSLIBDIR} or $bindir_abs);
505
506         my @dirs = ();
507
508         my $shrdir="$prefix_abs/share";
509         push(@dirs,$shrdir);
510
511         my $libdir="$prefix_abs/lib";
512         push(@dirs,$libdir);
513
514         my $piddir="$prefix_abs/pid";
515         push(@dirs,$piddir);
516
517         my $privatedir="$prefix_abs/private";
518         push(@dirs,$privatedir);
519
520         my $lockdir="$prefix_abs/lockdir";
521         push(@dirs,$lockdir);
522
523         my $eventlogdir="$prefix_abs/lockdir/eventlog";
524         push(@dirs,$eventlogdir);
525
526         my $logdir="$prefix_abs/logs";
527         push(@dirs,$logdir);
528
529         my $driver32dir="$shrdir/W32X86";
530         push(@dirs,$driver32dir);
531
532         my $driver64dir="$shrdir/x64";
533         push(@dirs,$driver64dir);
534
535         my $driver40dir="$shrdir/WIN40";
536         push(@dirs,$driver40dir);
537
538         my $ro_shrdir="$shrdir/root-tmp";
539         push(@dirs,$ro_shrdir);
540
541         my $msdfs_shrdir="$shrdir/msdfsshare";
542         push(@dirs,$msdfs_shrdir);
543
544         my $msdfs_deeppath="$msdfs_shrdir/deeppath";
545         push(@dirs,$msdfs_deeppath);
546
547         # this gets autocreated by winbindd
548         my $wbsockdir="$prefix_abs/winbindd";
549         my $wbsockprivdir="$lockdir/winbindd_privileged";
550
551         my $nmbdsockdir="$prefix_abs/nmbd";
552         unlink($nmbdsockdir);
553
554         ## 
555         ## create the test directory layout
556         ##
557         die ("prefix_abs = ''") if $prefix_abs eq "";
558         die ("prefix_abs = '/'") if $prefix_abs eq "/";
559
560         mkdir($prefix_abs, 0777);
561         print "CREATE TEST ENVIRONMENT IN '$prefix'...";
562         system("rm -rf $prefix_abs/*");
563         mkdir($_, 0777) foreach(@dirs);
564
565         ##
566         ## create ro and msdfs share layout
567         ##
568
569         chmod 0755, $ro_shrdir;
570         my $unreadable_file = "$ro_shrdir/unreadable_file";
571         open(UNREADABLE_FILE, ">$unreadable_file") or die("Unable to open $unreadable_file");
572         close(UNREADABLE_FILE);
573         chmod 0600, $unreadable_file;
574
575         my $msdfs_target = "$ro_shrdir/msdfs-target";
576         open(MSDFS_TARGET, ">$msdfs_target") or die("Unable to open $msdfs_target");
577         close(MSDFS_TARGET);
578         chmod 0666, $msdfs_target;
579         symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/msdfs-src1";
580         symlink "msdfs:$server_ip\\ro-tmp", "$msdfs_shrdir/deeppath/msdfs-src2";
581
582         my $conffile="$libdir/server.conf";
583
584         my $nss_wrapper_pl = "$ENV{PERL} $self->{srcdir}/lib/nss_wrapper/nss_wrapper.pl";
585         my $nss_wrapper_passwd = "$privatedir/passwd";
586         my $nss_wrapper_group = "$privatedir/group";
587
588         my $mod_printer_pl = "$ENV{PERL} $self->{srcdir}/source3/script/tests/printing/modprinter.pl";
589
590         my @eventlog_list = ("dns server", "application");
591
592         ##
593         ## calculate uids and gids
594         ##
595
596         my ($max_uid, $max_gid);
597         my ($uid_nobody, $uid_root);
598         my ($gid_nobody, $gid_nogroup, $gid_root, $gid_domusers);
599
600         if ($unix_uid < 0xffff - 2) {
601                 $max_uid = 0xffff;
602         } else {
603                 $max_uid = $unix_uid;
604         }
605
606         $uid_root = $max_uid - 1;
607         $uid_nobody = $max_uid - 2;
608
609         if ($unix_gids[0] < 0xffff - 3) {
610                 $max_gid = 0xffff;
611         } else {
612                 $max_gid = $unix_gids[0];
613         }
614
615         $gid_nobody = $max_gid - 1;
616         $gid_nogroup = $max_gid - 2;
617         $gid_root = $max_gid - 3;
618         $gid_domusers = $max_gid - 4;
619
620         ##
621         ## create conffile
622         ##
623
624         open(CONF, ">$conffile") or die("Unable to open $conffile");
625         print CONF "
626 [global]
627         netbios name = $server
628         interfaces = $server_ip/8
629         bind interfaces only = yes
630         panic action = $self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
631
632         workgroup = $domain
633
634         private dir = $privatedir
635         pid directory = $piddir
636         lock directory = $lockdir
637         log file = $logdir/log.\%m
638         log level = 0
639         debug pid = yes
640         max log size = 0
641
642         name resolve order = bcast
643
644         state directory = $lockdir
645         cache directory = $lockdir
646
647         passdb backend = tdbsam
648
649         time server = yes
650
651         add user script =               $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
652         add group script =              $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action add --name %g
653         add machine script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action add --name %u --gid $gid_nogroup
654         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
655         delete user script =            $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type passwd --action delete --name %u
656         delete group script =           $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action delete --name %g
657         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
658
659         addprinter command =            $mod_printer_pl -a -s $conffile --
660         deleteprinter command =         $mod_printer_pl -d -s $conffile --
661
662         eventlog list = application \"dns server\"
663
664         kernel oplocks = no
665         kernel change notify = no
666
667         syslog = no
668         printing = bsd
669         printcap name = /dev/null
670
671         winbindd:socket dir = $wbsockdir
672         nmbd:socket dir = $nmbdsockdir
673         idmap config * : range = 100000-200000
674         winbind enum users = yes
675         winbind enum groups = yes
676
677 #       min receivefile size = 4000
678
679         max protocol = SMB2
680         read only = no
681         server signing = auto
682
683         smbd:sharedelay = 100000
684 #       smbd:writetimeupdatedelay = 500000
685         map hidden = no
686         map system = no
687         map readonly = no
688         store dos attributes = yes
689         create mask = 755
690         vfs objects = $vfs_modulesdir_abs/xattr_tdb.so $vfs_modulesdir_abs/streams_depot.so
691
692         printing = vlp
693         print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
694         lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
695         lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
696         lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
697         lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
698         queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
699         queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
700         lpq cache time = 0
701
702         ncalrpc dir = $lockdir/ncalrpc
703         rpc_server:epmapper = embedded
704
705         # Begin extra options
706         $extra_options
707         # End extra options
708
709         #Include user defined custom parameters if set
710 ";
711
712         if (defined($ENV{INCLUDE_CUSTOM_CONF})) {
713                 print CONF "\t$ENV{INCLUDE_CUSTOM_CONF}\n";
714         }
715
716         print CONF "
717 [tmp]
718         path = $shrdir
719 [tmpguest]
720         path = $shrdir
721         guest ok = yes
722 [guestonly]
723         path = $shrdir
724         guest only = yes
725         guest ok = yes
726 [forceuser]
727         path = $shrdir
728         force user = $unix_name
729         guest ok = yes
730 [forcegroup]
731         path = $shrdir
732         force group = nogroup
733         guest ok = yes
734 [ro-tmp]
735         path = $ro_shrdir
736         guest ok = yes
737 [msdfs-share]
738         path = $msdfs_shrdir
739         msdfs root = yes
740         guest ok = yes
741 [hideunread]
742         copy = tmp
743         hide unreadable = yes
744 [tmpcase]
745         copy = tmp
746         case sensitive = yes
747 [hideunwrite]
748         copy = tmp
749         hide unwriteable files = yes
750 [print1]
751         copy = tmp
752         printable = yes
753
754 [print2]
755         copy = print1
756 [print3]
757         copy = print1
758 [lp]
759         copy = print1
760 [print\$]
761         copy = tmp
762         ";
763         close(CONF);
764
765         ##
766         ## create a test account
767         ##
768
769         open(PASSWD, ">$nss_wrapper_passwd") or die("Unable to open $nss_wrapper_passwd");
770         print PASSWD "nobody:x:$uid_nobody:$gid_nobody:nobody gecos:$prefix_abs:/bin/false
771 $unix_name:x:$unix_uid:$unix_gids[0]:$unix_name gecos:$prefix_abs:/bin/false
772 ";
773         if ($unix_uid != 0) {
774                 print PASSWD "root:x:$uid_root:$gid_root:root gecos:$prefix_abs:/bin/false";
775         }
776         close(PASSWD);
777
778         open(GROUP, ">$nss_wrapper_group") or die("Unable to open $nss_wrapper_group");
779         print GROUP "nobody:x:$gid_nobody:
780 nogroup:x:$gid_nogroup:nobody
781 $unix_name-group:x:$unix_gids[0]:
782 domusers:X:$gid_domusers:
783 ";
784         if ($unix_gids[0] != 0) {
785                 print GROUP "root:x:$gid_root:";
786         }
787
788         close(GROUP);
789
790         foreach my $evlog (@eventlog_list) {
791                 my $evlogtdb = "$eventlogdir/$evlog.tdb";
792                 open(EVENTLOG, ">$evlogtdb") or die("Unable to open $evlogtdb");
793                 close(EVENTLOG);
794         }
795
796         $ENV{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
797         $ENV{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
798
799         open(PWD, "|".$self->binpath("smbpasswd")." -c $conffile -L -s -a $unix_name >/dev/null");
800         print PWD "$password\n$password\n";
801         close(PWD) or die("Unable to set password for test account");
802
803         print "DONE\n";
804
805         $ret{SERVER_IP} = $server_ip;
806         $ret{NMBD_TEST_LOG} = "$prefix/nmbd_test.log";
807         $ret{NMBD_TEST_LOG_POS} = 0;
808         $ret{WINBINDD_TEST_LOG} = "$prefix/winbindd_test.log";
809         $ret{WINBINDD_TEST_LOG_POS} = 0;
810         $ret{SMBD_TEST_LOG} = "$prefix/smbd_test.log";
811         $ret{SMBD_TEST_LOG_POS} = 0;
812         $ret{SERVERCONFFILE} = $conffile;
813         $ret{CONFIGURATION} ="-s $conffile";
814         $ret{SERVER} = $server;
815         $ret{USERNAME} = $unix_name;
816         $ret{USERID} = $unix_uid;
817         $ret{DOMAIN} = $domain;
818         $ret{NETBIOSNAME} = $server;
819         $ret{PASSWORD} = $password;
820         $ret{PIDDIR} = $piddir;
821         $ret{WINBINDD_SOCKET_DIR} = $wbsockdir;
822         $ret{WINBINDD_PRIV_PIPE_DIR} = $wbsockprivdir;
823         $ret{NMBD_SOCKET_DIR} = $nmbdsockdir;
824         $ret{SOCKET_WRAPPER_DEFAULT_IFACE} = $swiface;
825         $ret{NSS_WRAPPER_PASSWD} = $nss_wrapper_passwd;
826         $ret{NSS_WRAPPER_GROUP} = $nss_wrapper_group;
827         $ret{NSS_WRAPPER_WINBIND_SO_PATH} = $ENV{NSS_WRAPPER_WINBIND_SO_PATH};
828         $ret{LOCAL_PATH} = "$shrdir";
829
830         return \%ret;
831 }
832
833 sub wait_for_start($$)
834 {
835         my ($self, $envvars) = @_;
836
837         # give time for nbt server to register its names
838         print "delaying for nbt name registration\n";
839         sleep(10);
840         # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
841         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} __SAMBA__");
842         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} __SAMBA__");
843         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U 127.255.255.255 __SAMBA__");
844         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} -U $envvars->{SERVER_IP} $envvars->{SERVER}");
845         system($self->binpath("nmblookup") ." $envvars->{CONFIGURATION} $envvars->{SERVER}");
846         # make sure smbd is also up set
847         print "wait for smbd\n";
848         system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
849         system($self->binpath("smbclient") ." $envvars->{CONFIGURATION} -L $envvars->{SERVER_IP} -U% -p 139 | head -2");
850
851         # Ensure we have domain users mapped.
852         system($self->binpath("net") ." $envvars->{CONFIGURATION} groupmap add rid=513 unixgroup=domusers type=domain");
853
854         print $self->getlog_env($envvars);
855 }
856
857 1;