2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
10 use FindBin qw($RealBin);
17 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
24 server_maxtime => $server_maxtime,
25 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
31 sub scriptdir_path($$) {
32 my ($self, $path) = @_;
33 return "$self->{srcdir}/source4/scripting/$path";
36 sub openldap_start($$$) {
42 my ($self, $env_vars, $STDIN_READER) = @_;
43 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
45 my $uri = $env_vars->{LDAP_URI};
47 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
48 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
51 # running slapd in the background means it stays in the same process group, so it can be
55 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
56 open STDERR, '>&STDOUT';
57 close($env_vars->{STDIN_PIPE});
58 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
60 if ($self->{ldap} eq "fedora-ds") {
61 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
62 } elsif ($self->{ldap} eq "openldap") {
63 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
65 die("Unable to start slapd: $!");
67 $env_vars->{SLAPD_PID} = $pid;
69 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
72 $self->slapd_stop($env_vars);
82 my ($self, $envvars) = @_;
83 kill 9, $envvars->{SLAPD_PID};
87 sub check_or_start($$$)
89 my ($self, $env_vars, $process_model) = @_;
92 my $env_ok = $self->check_env($env_vars);
94 return $env_vars->{SAMBA_PID};
95 } elsif (defined($env_vars->{SAMBA_PID})) {
96 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
100 # use a pipe for stdin in the child processes. This allows
101 # those processes to monitor the pipe for EOF to ensure they
102 # exit when the test script exits
103 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
105 # Start slapd before samba, but with the fifo on stdin
106 if (defined($self->{ldap})) {
107 unless($self->slapd_start($env_vars, $STDIN_READER)) {
108 warn("couldn't start slapd (main run)");
113 print "STARTING SAMBA...\n";
116 # we want out from samba to go to the log file, but also
117 # to the users terminal when running 'make test' on the command
118 # line. This puts it on stderr on the terminal
119 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
120 open STDERR, '>&STDOUT';
122 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
124 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
125 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
126 if (defined($ENV{MITKRB5})) {
127 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
129 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
130 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
132 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
133 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
134 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
135 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
136 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
137 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
139 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
140 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
142 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
145 $ENV{UID_WRAPPER} = "1";
146 $ENV{UID_WRAPPER_ROOT} = "1";
148 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
151 if (defined($ENV{SAMBA_OPTIONS})) {
152 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
154 if(defined($ENV{SAMBA_VALGRIND})) {
155 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
158 close($env_vars->{STDIN_PIPE});
159 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
161 exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--no-process-group", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
163 $env_vars->{SAMBA_PID} = $pid;
164 print "DONE ($pid)\n";
166 close($STDIN_READER);
168 if ($self->wait_for_start($env_vars) != 0) {
169 warn("Samba $pid failed to start up");
176 sub wait_for_start($$)
178 my ($self, $testenv_vars) = @_;
182 if (not $self->check_env($testenv_vars)) {
183 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
187 # This will return quickly when things are up, but be slow if we
188 # need to wait for (eg) SSL init
189 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
192 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
199 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
200 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
201 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
204 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
209 } while ($ret != 0 && $count < 20);
211 warn("nbt not reachable after 20 retries\n");
212 teardown_env($self, $testenv_vars);
216 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
217 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
218 # Add hosts file for name lookups
219 $ENV{NSS_WRAPPER_HOSTS} = $testenv_vars->{NSS_WRAPPER_HOSTS};
220 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
221 $ENV{RESOLV_WRAPPER_CONF} = $testenv_vars->{RESOLV_WRAPPER_CONF};
223 $ENV{RESOLV_WRAPPER_HOSTS} = $testenv_vars->{RESOLV_WRAPPER_HOSTS};
226 print "waiting for working LDAP and a RID Set to be allocated\n";
227 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
229 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
231 my $search_dn = $base_dn;
232 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
233 # TODO currently no check for actual rIDAllocationPool
234 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
237 my $cmd = "$ldbsearch $testenv_vars->{CONFIGURATION} -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$search_dn\"";
238 while (system("$cmd >/dev/null") != 0) {
240 if ($count > $max_wait) {
241 warn("Timed out ($max_wait sec) waiting for working LDAP and a RID Set to be allocated by $testenv_vars->{NETBIOSNAME} PID $testenv_vars->{SAMBA_PID}");
249 my $wbinfo = Samba::bindir_path($self, "wbinfo");
253 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
254 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
255 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
256 $cmd .= "$wbinfo -p";
263 } while ($ret != 0 && $count < 20);
265 warn("winbind not reachable after 20 retries\n");
266 teardown_env($self, $testenv_vars);
270 print $self->getlog_env($testenv_vars);
275 sub write_ldb_file($$$)
277 my ($self, $file, $ldif) = @_;
279 my $ldbadd = Samba::bindir_path($self, "ldbadd");
280 open(LDIF, "|$ldbadd -H $file >/dev/null");
285 sub add_wins_config($$)
287 my ($self, $privatedir) = @_;
289 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
290 dn: name=TORTURE_11,CN=PARTNERS
291 objectClass: wreplPartner
302 my ($self, $ctx) = @_;
304 #Make the subdirectory be as fedora DS would expect
305 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
307 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
309 return ($fedora_ds_dir, $pidfile);
314 my ($self, $ctx) = @_;
316 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
317 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
319 return ($slapd_conf_d, $pidfile);
322 sub setup_namespaces($$:$$)
324 my ($self, $localenv, $upn_array, $spn_array) = @_;
326 @{$upn_array} = [] unless defined($upn_array);
328 foreach my $upn (@{$upn_array}) {
329 $upn_args .= " --add-upn-suffix=$upn";
332 @{$spn_array} = [] unless defined($spn_array);
334 foreach my $spn (@{$spn_array}) {
335 $spn_args .= " --add-spn-suffix=$spn";
338 my $samba_tool = Samba::bindir_path($self, "samba-tool");
341 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
342 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
343 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
345 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
347 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
348 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
350 my $cmd_config = " $localenv->{CONFIGURATION}";
352 my $namespaces = $cmd_env;
353 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
354 $namespaces .= $cmd_config;
355 unless (system($namespaces) == 0) {
356 warn("Failed to add namespaces \n$namespaces");
363 sub setup_trust($$$$$)
365 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
367 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
368 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
369 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
370 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
371 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
372 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
373 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
374 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
375 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
377 my $samba_tool = Samba::bindir_path($self, "samba-tool");
380 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
381 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
382 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
384 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
386 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
387 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
389 my $cmd_config = " $localenv->{CONFIGURATION}";
390 my $cmd_creds = $cmd_config;
391 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
393 my $create = $cmd_env;
394 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
395 $create .= " $extra_args";
396 $create .= $cmd_creds;
397 unless (system($create) == 0) {
398 warn("Failed to create trust \n$create");
405 sub provision_raw_prepare($$$$$$$$$$$$)
407 my ($self, $prefix, $server_role, $hostname,
408 $domain, $realm, $samsid, $functional_level,
409 $password, $kdc_ipv4, $kdc_ipv6) = @_;
411 my $netbiosname = uc($hostname);
413 unless(-d $prefix or mkdir($prefix, 0777)) {
414 warn("Unable to create $prefix");
417 my $prefix_abs = abs_path($prefix);
419 die ("prefix=''") if $prefix_abs eq "";
420 die ("prefix='/'") if $prefix_abs eq "/";
422 unless (system("rm -rf $prefix_abs/*") == 0) {
423 warn("Unable to clean up");
427 my $swiface = Samba::get_interface($hostname);
429 $ctx->{prefix} = $prefix;
430 $ctx->{prefix_abs} = $prefix_abs;
432 $ctx->{server_role} = $server_role;
433 $ctx->{hostname} = $hostname;
434 $ctx->{netbiosname} = $netbiosname;
435 $ctx->{swiface} = $swiface;
436 $ctx->{password} = $password;
437 $ctx->{kdc_ipv4} = $kdc_ipv4;
438 $ctx->{kdc_ipv6} = $kdc_ipv6;
439 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
440 if ($functional_level eq "2000") {
441 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
445 # Set smbd log level here.
447 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
448 $ctx->{username} = "Administrator";
449 $ctx->{domain} = $domain;
450 $ctx->{realm} = uc($realm);
451 $ctx->{dnsname} = lc($realm);
452 $ctx->{samsid} = $samsid;
454 $ctx->{functional_level} = $functional_level;
456 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
458 $ctx->{unix_name} = $unix_name;
459 $ctx->{unix_uid} = $>;
460 my @mygid = split(" ", $();
461 $ctx->{unix_gid} = $mygid[0];
462 $ctx->{unix_gids_str} = $);
463 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
465 $ctx->{etcdir} = "$prefix_abs/etc";
466 $ctx->{piddir} = "$prefix_abs/pid";
467 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
468 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
469 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
470 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
471 $ctx->{privatedir} = "$prefix_abs/private";
472 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
473 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
474 $ctx->{lockdir} = "$prefix_abs/lockdir";
475 $ctx->{logdir} = "$prefix_abs/logs";
476 $ctx->{statedir} = "$prefix_abs/statedir";
477 $ctx->{cachedir} = "$prefix_abs/cachedir";
478 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
479 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
480 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
481 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
482 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
483 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
484 if ($ENV{SAMBA_DNS_FAKING}) {
485 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
486 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
488 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
489 $ctx->{use_resolv_wrapper} = 1;
491 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
493 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
495 $ctx->{ipv4} = "127.0.0.$swiface";
496 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
497 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
499 push(@{$ctx->{directories}}, $ctx->{privatedir});
500 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
501 push(@{$ctx->{directories}}, $ctx->{etcdir});
502 push(@{$ctx->{directories}}, $ctx->{piddir});
503 push(@{$ctx->{directories}}, $ctx->{lockdir});
504 push(@{$ctx->{directories}}, $ctx->{logdir});
505 push(@{$ctx->{directories}}, $ctx->{statedir});
506 push(@{$ctx->{directories}}, $ctx->{cachedir});
508 $ctx->{smb_conf_extra_options} = "";
510 my @provision_options = ();
511 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
512 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
513 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
514 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
515 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
516 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
517 if (defined($ctx->{use_resolv_wrapper})) {
518 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
520 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
522 if (defined($ENV{GDB_PROVISION})) {
523 push (@provision_options, "gdb --args");
524 if (!defined($ENV{PYTHON})) {
525 push (@provision_options, "env");
526 push (@provision_options, "python");
529 if (defined($ENV{VALGRIND_PROVISION})) {
530 push (@provision_options, "valgrind");
531 if (!defined($ENV{PYTHON})) {
532 push (@provision_options, "env");
533 push (@provision_options, "python");
536 if (defined($ENV{PYTHON})) {
537 push (@provision_options, $ENV{PYTHON});
539 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
540 push (@provision_options, "domain");
541 push (@provision_options, "provision");
542 push (@provision_options, "--configfile=$ctx->{smb_conf}");
543 push (@provision_options, "--host-name=$ctx->{hostname}");
544 push (@provision_options, "--host-ip=$ctx->{ipv4}");
545 push (@provision_options, "--quiet");
546 push (@provision_options, "--domain=$ctx->{domain}");
547 push (@provision_options, "--realm=$ctx->{realm}");
548 if (defined($ctx->{samsid})) {
549 push (@provision_options, "--domain-sid=$ctx->{samsid}");
551 push (@provision_options, "--adminpass=$ctx->{password}");
552 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
553 push (@provision_options, "--machinepass=machine$ctx->{password}");
554 push (@provision_options, "--root=$ctx->{unix_name}");
555 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
556 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
558 @{$ctx->{provision_options}} = @provision_options;
564 # Step1 creates the basic configuration
566 sub provision_raw_step1($$)
568 my ($self, $ctx) = @_;
570 mkdir($_, 0777) foreach (@{$ctx->{directories}});
573 ## lockdir and piddir must be 0755
575 chmod 0755, $ctx->{lockdir};
576 chmod 0755, $ctx->{piddir};
578 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
579 warn("can't open $ctx->{smb_conf}$?");
583 Samba::prepare_keyblobs($ctx);
584 my $crlfile = "$ctx->{tlsdir}/crl.pem";
585 $crlfile = "" unless -e ${crlfile};
589 netbios name = $ctx->{netbiosname}
590 posix:eadb = $ctx->{statedir}/eadb.tdb
591 workgroup = $ctx->{domain}
592 realm = $ctx->{realm}
593 private dir = $ctx->{privatedir}
594 binddns dir = $ctx->{binddnsdir}
595 pid directory = $ctx->{piddir}
596 ncalrpc dir = $ctx->{ncalrpcdir}
597 lock dir = $ctx->{lockdir}
598 state directory = $ctx->{statedir}
599 cache directory = $ctx->{cachedir}
600 winbindd socket directory = $ctx->{winbindd_socket_dir}
601 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
602 winbind separator = /
603 interfaces = $ctx->{interfaces}
604 tls dh params file = $ctx->{tlsdir}/dhparms.pem
605 tls crlfile = ${crlfile}
606 tls verify peer = no_check
607 panic action = $RealBin/gdb_backtrace \%d
609 server role = $ctx->{server_role}
610 server services = +echo +smb -s3fs
611 dcerpc endpoint servers = +winreg +srvsvc
612 notify:inotify = false
614 ldap server require strong auth = yes
615 #We don't want to pass our self-tests if the PAC code is wrong
616 gensec:require_pac = true
617 log file = $ctx->{logdir}/log.\%m
618 log level = $ctx->{server_loglevel}
622 dns update command = $ctx->{samba_dnsupdate}
623 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
624 gpo update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_gpoupdate -s $ctx->{smb_conf} -H $ctx->{privatedir}/sam.ldb --machine
625 dreplsrv:periodic_startup_interval = 0
626 dsdb:schema update allowed = yes
630 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
632 idmap_ldb:use rfc2307=yes
633 winbind enum users = yes
634 winbind enum groups = yes
636 rpc server port:netlogon = 1026
642 # Begin extra options
643 $ctx->{smb_conf_extra_options}
648 #Default the KDC IP to the server's IP
649 if (not defined($ctx->{kdc_ipv4})) {
650 $ctx->{kdc_ipv4} = $ctx->{ipv4};
652 if (not defined($ctx->{kdc_ipv6})) {
653 $ctx->{kdc_ipv6} = $ctx->{ipv6};
656 Samba::mk_krb5_conf($ctx);
657 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
659 open(PWD, ">$ctx->{nsswrap_passwd}");
660 if ($ctx->{unix_uid} != 0) {
661 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
663 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
664 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
665 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
666 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
667 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
668 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
671 my $uid_rfc2307test = 65533;
673 open(GRP, ">$ctx->{nsswrap_group}");
674 if ($ctx->{unix_gid} != 0) {
675 print GRP "root:x:0:\n";
677 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
678 print GRP "wheel:x:10:
681 nogroup:x:65534:nobody
684 my $gid_rfc2307test = 65532;
686 my $hostname = lc($ctx->{hostname});
687 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
688 if ($hostname eq "localdc") {
689 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
690 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
692 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
693 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
697 if (defined($ctx->{resolv_conf})) {
698 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
699 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
700 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
704 my $configuration = "--configfile=$ctx->{smb_conf}";
706 #Ensure the config file is valid before we start
707 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
708 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
709 system("$testparm -v --suppress-prompt $configuration >&2");
710 warn("Failed to create a valid smb.conf configuration $testparm!");
713 unless (system("($testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$ctx->{netbiosname}\" ) >/dev/null 2>&1") == 0) {
714 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
719 KRB5_CONFIG => $ctx->{krb5_conf},
720 KRB5_CCACHE => $ctx->{krb5_ccache},
721 MITKDC_CONFIG => $ctx->{mitkdc_conf},
722 PIDDIR => $ctx->{piddir},
723 SERVER => $ctx->{hostname},
724 SERVER_IP => $ctx->{ipv4},
725 SERVER_IPV6 => $ctx->{ipv6},
726 NETBIOSNAME => $ctx->{netbiosname},
727 DOMAIN => $ctx->{domain},
728 USERNAME => $ctx->{username},
729 REALM => $ctx->{realm},
730 SAMSID => $ctx->{samsid},
731 PASSWORD => $ctx->{password},
732 LDAPDIR => $ctx->{ldapdir},
733 LDAP_INSTANCE => $ctx->{ldap_instance},
734 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
735 NCALRPCDIR => $ctx->{ncalrpcdir},
736 LOCKDIR => $ctx->{lockdir},
737 STATEDIR => $ctx->{statedir},
738 CACHEDIR => $ctx->{cachedir},
739 PRIVATEDIR => $ctx->{privatedir},
740 BINDDNSDIR => $ctx->{binddnsdir},
741 SERVERCONFFILE => $ctx->{smb_conf},
742 CONFIGURATION => $configuration,
743 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
744 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
745 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
746 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
747 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
748 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
749 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
750 SAMBA_TEST_LOG_POS => 0,
751 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
752 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
753 LOCAL_PATH => $ctx->{share},
754 UID_RFC2307TEST => $uid_rfc2307test,
755 GID_RFC2307TEST => $gid_rfc2307test,
756 SERVER_ROLE => $ctx->{server_role},
757 RESOLV_CONF => $ctx->{resolv_conf}
760 if (defined($ctx->{use_resolv_wrapper})) {
761 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
763 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
766 if ($ctx->{server_role} eq "domain controller") {
767 $ret->{DOMSID} = $ret->{SAMSID};
774 # Step2 runs the provision script
776 sub provision_raw_step2($$$)
778 my ($self, $ctx, $ret) = @_;
780 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
781 unless (system($provision_cmd) == 0) {
782 warn("Unable to provision: \n$provision_cmd\n");
786 my $testallowed_account = "testallowed";
787 my $samba_tool_cmd = "";
788 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
789 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
790 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
791 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
792 unless (system($samba_tool_cmd) == 0) {
793 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
798 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
799 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
800 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
801 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
803 if ($ctx->{server_role} ne "domain controller") {
804 $base_dn = "DC=$ctx->{netbiosname}";
807 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
808 $testallowed_account = "testallowed account";
809 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
810 print LDIF "dn: $user_dn
812 replace: samAccountName
813 samAccountName: $testallowed_account
818 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
819 print LDIF "dn: $user_dn
821 replace: userPrincipalName
822 userPrincipalName: testallowed upn\@$ctx->{realm}
823 replace: servicePrincipalName
824 servicePrincipalName: host/testallowed
829 $samba_tool_cmd = "";
830 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
831 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
832 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
833 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
834 unless (system($samba_tool_cmd) == 0) {
835 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
839 my $user_dn = "cn=testdenied,cn=users,$base_dn";
840 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
841 print LDIF "dn: $user_dn
843 replace: userPrincipalName
844 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
849 $samba_tool_cmd = "";
850 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
851 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
852 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
853 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
854 unless (system($samba_tool_cmd) == 0) {
855 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
859 # Create to users alice and bob!
860 my $user_account_array = ["alice", "bob"];
862 foreach my $user_account (@{$user_account_array}) {
863 my $samba_tool_cmd = "";
865 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
866 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
867 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
868 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
869 unless (system($samba_tool_cmd) == 0) {
870 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
878 sub provision($$$$$$$$$$)
880 my ($self, $prefix, $server_role, $hostname,
881 $domain, $realm, $functional_level,
882 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
883 $extra_provision_options) = @_;
885 my $samsid = Samba::random_domain_sid();
887 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
892 $password, $kdc_ipv4, $kdc_ipv6);
894 if (defined($extra_provision_options)) {
895 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
897 push (@{$ctx->{provision_options}}, "--use-ntvfs");
900 $ctx->{share} = "$ctx->{prefix_abs}/share";
901 push(@{$ctx->{directories}}, "$ctx->{share}");
902 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
903 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
905 # precreate directories for printer drivers
906 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
907 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
908 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
911 $msdfs = "yes" if ($server_role eq "domain controller");
912 $ctx->{smb_conf_extra_options} = "
915 server max protocol = SMB2
919 # fruit:copyfile is a global option
922 $extra_smbconf_options
927 posix:sharedelay = 100000
928 posix:oplocktimeout = 3
929 posix:writetimeupdatedelay = 500000
934 posix:sharedelay = 100000
935 posix:oplocktimeout = 3
936 posix:writetimeupdatedelay = 500000
938 force create mode = 777
944 force create mode = 0
945 directory mask = 0777
946 force directory mode = 0
949 path = $ctx->{share}/test1
951 posix:sharedelay = 100000
952 posix:oplocktimeout = 3
953 posix:writetimeupdatedelay = 500000
956 path = $ctx->{share}/test2
958 posix:sharedelay = 100000
959 posix:oplocktimeout = 3
960 posix:writetimeupdatedelay = 500000
963 path = $ctx->{share}/_ignore_cifs_
966 cifs:server = $ctx->{netbiosname}
968 cifs:use-s4u2proxy = yes
969 # There is no username specified here, instead the client is expected
970 # to log in with kerberos, and the serverwill use delegated credentials.
971 # Or the server tries s4u2self/s4u2proxy to impersonate the client
976 ntvfs handler = simple
979 path = $ctx->{statedir}/sysvol
983 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
988 ntvfs handler = cifsposix
992 vfs objects = catia fruit streams_xattr acl_xattr
994 fruit:resource = file
995 fruit:metadata = netatalk
996 fruit:locking = netatalk
997 fruit:encoding = native
999 $extra_smbconf_shares
1002 if (defined($self->{ldap})) {
1003 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1004 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1006 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1007 $ldap_uri =~ s|/|%2F|g;
1008 $ldap_uri = "ldapi://$ldap_uri";
1009 $ctx->{ldap_uri} = $ldap_uri;
1011 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1014 my $ret = $self->provision_raw_step1($ctx);
1015 unless (defined $ret) {
1019 if (defined($self->{ldap})) {
1020 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1021 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1022 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1023 if ($self->{ldap} eq "openldap") {
1024 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1025 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1027 } elsif ($self->{ldap} eq "fedora-ds") {
1028 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1029 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1030 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1035 return $self->provision_raw_step2($ctx, $ret);
1038 sub provision_s4member($$$$$)
1040 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1041 print "PROVISIONING MEMBER...\n";
1042 my $extra_smb_conf = "
1043 passdb backend = samba_dsdb
1044 winbindd:use external pipes = true
1046 # the source4 smb server doesn't allow signing by default
1047 server signing = enabled
1048 raw NTLMv2 auth = yes
1050 rpc_server:default = external
1051 rpc_server:svcctl = embedded
1052 rpc_server:srvsvc = embedded
1053 rpc_server:eventlog = embedded
1054 rpc_server:ntsvcs = embedded
1055 rpc_server:winreg = embedded
1056 rpc_server:spoolss = embedded
1057 rpc_daemon:spoolssd = embedded
1058 rpc_server:tcpip = no
1061 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1063 my $ret = $self->provision($prefix,
1070 $dcvars->{SERVER_IP},
1071 $dcvars->{SERVER_IPV6},
1072 $extra_smb_conf, "", undef);
1077 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1079 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1080 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1081 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1083 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1085 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1086 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1087 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1088 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1089 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1091 unless (system($cmd) == 0) {
1092 warn("Join failed\n$cmd");
1096 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1097 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1098 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1099 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1100 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1101 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1103 $ret->{DOMSID} = $dcvars->{DOMSID};
1104 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1105 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1106 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1107 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1108 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1109 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1114 sub provision_rpc_proxy($$$)
1116 my ($self, $prefix, $dcvars) = @_;
1117 print "PROVISIONING RPC PROXY...\n";
1119 my $extra_smbconf_options = "
1120 passdb backend = samba_dsdb
1123 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1124 dcerpc endpoint servers = epmapper, remote
1125 dcerpc_remote:interfaces = rpcecho
1128 path = /tmp/_ignore_cifs_to_dc_/_none_
1130 ntvfs handler = cifs
1131 cifs:server = $dcvars->{SERVER}
1133 cifs:use-s4u2proxy = yes
1134 # There is no username specified here, instead the client is expected
1135 # to log in with kerberos, and the serverwill use delegated credentials.
1136 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1140 my $ret = $self->provision($prefix,
1147 $dcvars->{SERVER_IP},
1148 $dcvars->{SERVER_IPV6},
1149 $extra_smbconf_options, "", undef);
1154 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1156 # The joind runs in the context of the rpc_proxy/member for now
1158 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1159 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1160 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1162 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1164 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1165 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1166 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1167 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1168 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1170 unless (system($cmd) == 0) {
1171 warn("Join failed\n$cmd");
1175 # Setting up delegation runs in the context of the DC for now
1177 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1178 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1179 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1180 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1181 $cmd .= " $dcvars->{CONFIGURATION}";
1184 unless (system($cmd) == 0) {
1185 warn("Delegation failed\n$cmd");
1189 # Setting up delegation runs in the context of the DC for now
1191 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1192 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1193 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1194 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1195 $cmd .= " $dcvars->{CONFIGURATION}";
1197 unless (system($cmd) == 0) {
1198 warn("Delegation failed\n$cmd");
1202 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1203 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1204 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1205 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1206 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1207 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1209 $ret->{DOMSID} = $dcvars->{DOMSID};
1210 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1211 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1212 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1213 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1214 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1215 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1220 sub provision_promoted_dc($$$)
1222 my ($self, $prefix, $dcvars) = @_;
1223 print "PROVISIONING PROMOTED DC...\n";
1225 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1226 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1232 $dcvars->{PASSWORD},
1233 $dcvars->{SERVER_IP},
1234 $dcvars->{SERVER_IPV6});
1236 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1238 $ctx->{smb_conf_extra_options} = "
1240 server max protocol = SMB2
1242 ntlm auth = ntlmv2-only
1245 path = $ctx->{statedir}/sysvol
1249 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1254 my $ret = $self->provision_raw_step1($ctx);
1259 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1261 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1262 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1263 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1265 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1267 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1268 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1269 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1270 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1271 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1273 unless (system($cmd) == 0) {
1274 warn("Join failed\n$cmd");
1278 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1280 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1281 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1282 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1283 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1284 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1285 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1287 unless (system($cmd) == 0) {
1288 warn("Join failed\n$cmd");
1292 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1293 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1294 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1295 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1297 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1298 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1299 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1300 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1301 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1302 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1307 sub provision_vampire_dc($$$)
1309 my ($self, $prefix, $dcvars, $fl) = @_;
1310 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1311 my $name = "localvampiredc";
1312 my $extra_conf = "";
1314 if ($fl == "2000") {
1315 $name = "vampire2000dc";
1317 $extra_conf = "drs: immediate link sync = yes
1318 drs: max link sync = 250";
1321 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1322 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1328 $dcvars->{PASSWORD},
1329 $dcvars->{SERVER_IP},
1330 $dcvars->{SERVER_IPV6});
1332 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1334 $ctx->{smb_conf_extra_options} = "
1336 server max protocol = SMB2
1338 ntlm auth = mschapv2-and-ntlmv2-only
1342 path = $ctx->{statedir}/sysvol
1346 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1351 my $ret = $self->provision_raw_step1($ctx);
1356 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1358 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1359 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1360 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1362 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1364 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1365 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1366 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1367 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1368 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1370 unless (system($cmd) == 0) {
1371 warn("Join failed\n$cmd");
1375 if ($fl == "2000") {
1376 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1377 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1378 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1379 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1381 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1382 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1383 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1384 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1386 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1387 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1388 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1389 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1390 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1391 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1392 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1397 sub provision_subdom_dc($$$)
1399 my ($self, $prefix, $dcvars) = @_;
1400 print "PROVISIONING SUBDOMAIN DC...\n";
1402 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1403 my $samsid = undef; # TODO pass the domain sid all the way down
1404 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1407 "sub.samba.example.com",
1410 $dcvars->{PASSWORD},
1413 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1415 $ctx->{smb_conf_extra_options} = "
1417 server max protocol = SMB2
1420 path = $ctx->{statedir}/sysvol
1424 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1429 my $ret = $self->provision_raw_step1($ctx);
1434 Samba::mk_krb5_conf($ctx);
1435 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1437 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1439 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1440 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1441 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1443 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1445 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1446 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1447 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1448 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1449 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1450 $cmd .= " --adminpass=$ret->{PASSWORD}";
1452 unless (system($cmd) == 0) {
1453 warn("Join failed\n$cmd");
1457 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1458 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1459 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1460 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1462 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1463 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1464 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1465 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1466 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1467 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1472 sub provision_ad_dc_ntvfs($$)
1474 my ($self, $prefix) = @_;
1476 # We keep the old 'winbind' name here in server services to
1477 # ensure upgrades which used that name still work with the now
1480 print "PROVISIONING AD DC (NTVFS)...\n";
1481 my $extra_conf_options = "netbios aliases = localDC1-a
1482 server services = +winbind -winbindd
1483 ldap server require strong auth = allow_sasl_over_tls
1484 allow nt4 crypto = yes
1485 raw NTLMv2 auth = yes
1486 lsa over netlogon = yes
1487 rpc server port = 1027
1488 auth event notification = true
1489 server schannel = auto
1491 my $ret = $self->provision($prefix,
1492 "domain controller",
1495 "samba.example.com",
1500 $extra_conf_options,
1507 unless($self->add_wins_config("$prefix/private")) {
1508 warn("Unable to add wins configuration");
1511 $ret->{NETBIOSALIAS} = "localdc1-a";
1512 $ret->{DC_SERVER} = $ret->{SERVER};
1513 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1514 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1515 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1516 $ret->{DC_USERNAME} = $ret->{USERNAME};
1517 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1518 $ret->{DC_REALM} = $ret->{REALM};
1523 sub provision_fl2000dc($$)
1525 my ($self, $prefix) = @_;
1527 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1528 my $extra_conf_options = "
1529 spnego:simulate_w2k=yes
1530 ntlmssp_server:force_old_spnego=yes
1532 my $extra_provision_options = undef;
1533 # This environment uses plain text secrets
1534 # i.e. secret attributes are not encrypted on disk.
1535 # This allows testing of the --plaintext-secrets option for
1537 push (@{$extra_provision_options}, "--plaintext-secrets");
1538 my $ret = $self->provision($prefix,
1539 "domain controller",
1542 "samba2000.example.com",
1547 $extra_conf_options,
1549 $extra_provision_options);
1554 unless($self->add_wins_config("$prefix/private")) {
1555 warn("Unable to add wins configuration");
1558 $ret->{DC_SERVER} = $ret->{SERVER};
1559 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1560 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1561 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1562 $ret->{DC_USERNAME} = $ret->{USERNAME};
1563 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1564 $ret->{DC_REALM} = $ret->{REALM};
1569 sub provision_fl2003dc($$$)
1571 my ($self, $prefix, $dcvars) = @_;
1572 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1573 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1575 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1576 my $extra_conf_options = "allow dns updates = nonsecure and secure
1577 dcesrv:header signing = no
1578 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1579 my $ret = $self->provision($prefix,
1580 "domain controller",
1583 "samba2003.example.com",
1588 $extra_conf_options,
1591 unless (defined $ret) {
1595 $ret->{DC_SERVER} = $ret->{SERVER};
1596 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1597 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1598 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1599 $ret->{DC_USERNAME} = $ret->{USERNAME};
1600 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1601 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1602 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1604 my @samba_tool_options;
1605 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1606 push (@samba_tool_options, "domain");
1607 push (@samba_tool_options, "passwordsettings");
1608 push (@samba_tool_options, "set");
1609 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1610 push (@samba_tool_options, "--min-pwd-age=0");
1611 push (@samba_tool_options, "--history-length=1");
1613 my $samba_tool_cmd = join(" ", @samba_tool_options);
1615 unless (system($samba_tool_cmd) == 0) {
1616 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1620 unless($self->add_wins_config("$prefix/private")) {
1621 warn("Unable to add wins configuration");
1628 sub provision_fl2008r2dc($$$)
1630 my ($self, $prefix, $dcvars) = @_;
1632 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1633 my $extra_conf_options = "ldap server require strong auth = no";
1634 my $ret = $self->provision($prefix,
1635 "domain controller",
1638 "samba2008R2.example.com",
1643 $extra_conf_options,
1646 unless (defined $ret) {
1650 unless ($self->add_wins_config("$prefix/private")) {
1651 warn("Unable to add wins configuration");
1654 $ret->{DC_SERVER} = $ret->{SERVER};
1655 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1656 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1657 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1658 $ret->{DC_USERNAME} = $ret->{USERNAME};
1659 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1660 $ret->{DC_REALM} = $ret->{REALM};
1666 sub provision_rodc($$$)
1668 my ($self, $prefix, $dcvars) = @_;
1669 print "PROVISIONING RODC...\n";
1671 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1672 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1678 $dcvars->{PASSWORD},
1679 $dcvars->{SERVER_IP},
1680 $dcvars->{SERVER_IPV6});
1685 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1687 $ctx->{share} = "$ctx->{prefix_abs}/share";
1688 push(@{$ctx->{directories}}, "$ctx->{share}");
1690 $ctx->{smb_conf_extra_options} = "
1692 server max protocol = SMB2
1693 password server = $dcvars->{DC_SERVER}
1696 path = $ctx->{statedir}/sysvol
1700 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1704 path = $ctx->{share}
1706 posix:sharedelay = 10000
1707 posix:oplocktimeout = 3
1708 posix:writetimeupdatedelay = 50000
1712 my $ret = $self->provision_raw_step1($ctx);
1717 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1719 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1720 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1721 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1723 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1725 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1726 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1727 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1728 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1729 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1731 unless (system($cmd) == 0) {
1732 warn("RODC join failed\n$cmd");
1736 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1737 # user password verified on the RODC
1738 my $testallowed_account = "testallowed account";
1739 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1740 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1741 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1742 $cmd .= " --server=$dcvars->{DC_SERVER}";
1744 unless (system($cmd) == 0) {
1745 warn("RODC join failed\n$cmd");
1749 # we overwrite the kdc after the RODC join
1750 # so that use the RODC as kdc and test
1752 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1753 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1754 Samba::mk_krb5_conf($ctx);
1755 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1757 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1758 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1759 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1760 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1762 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1763 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1764 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1765 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1766 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1767 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1772 sub read_config_h($)
1776 open(LF, "<$name") or die("unable to read $name: $!");
1779 next if not (/^#define /);
1780 if (/^#define (.*?)[ \t]+(.*?)$/) {
1784 if (/^#define (.*?)[ \t]+$/) {
1793 sub provision_ad_dc($$$$$$)
1795 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args) = @_;
1797 my $prefix_abs = abs_path($prefix);
1799 my $bindir_abs = abs_path($self->{bindir});
1800 my $lockdir="$prefix_abs/lockdir";
1801 my $conffile="$prefix_abs/etc/smb.conf";
1803 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1804 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1808 if (defined($ENV{CONFIG_H})) {
1809 $config_h = read_config_h($ENV{CONFIG_H});
1812 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1813 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1815 my $extra_smbconf_options = "
1816 server services = -smb +s3fs
1817 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1819 dbwrap_tdb_mutexes:* = yes
1822 ${password_hash_gpg_key_ids}
1825 kernel change notify = no
1830 printcap name = /dev/null
1835 smbd:sharedelay = 100000
1836 smbd:writetimeupdatedelay = 500000
1839 check parent directory delete on close = yes
1841 dcerpc endpoint servers = -winreg -srvsvc
1843 printcap name = /dev/null
1845 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1846 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1849 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1850 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1851 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1852 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1853 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1854 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1855 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1857 print notify backchannel = yes
1859 server schannel = auto
1860 auth event notification = true
1864 my $extra_smbconf_shares = "
1868 smb encrypt = required
1872 case sensitive = yes
1880 hide unreadable = yes
1884 kernel share modes = no
1903 print "PROVISIONING AD DC...\n";
1904 my $ret = $self->provision($prefix,
1905 "domain controller",
1913 $extra_smbconf_options,
1914 $extra_smbconf_shares,
1916 unless (defined $ret) {
1920 unless($self->add_wins_config("$prefix/private")) {
1921 warn("Unable to add wins configuration");
1925 $ret->{DC_SERVER} = $ret->{SERVER};
1926 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1927 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1928 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1929 $ret->{DC_USERNAME} = $ret->{USERNAME};
1930 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1935 sub provision_chgdcpass($$)
1937 my ($self, $prefix) = @_;
1939 print "PROVISIONING CHGDCPASS...\n";
1940 my $extra_provision_options = undef;
1941 # This environment disallows the use of this password
1942 # (and also removes the default AD complexity checks)
1943 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1944 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1945 my $ret = $self->provision($prefix,
1946 "domain controller",
1949 "chgdcpassword.samba.example.com",
1954 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
1956 $extra_provision_options);
1957 unless (defined $ret) {
1961 unless($self->add_wins_config("$prefix/private")) {
1962 warn("Unable to add wins configuration");
1966 # Remove secrets.tdb from this environment to test that we
1967 # still start up on systems without the new matching
1968 # secrets.tdb records.
1969 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1970 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1974 $ret->{DC_SERVER} = $ret->{SERVER};
1975 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1976 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1977 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1978 $ret->{DC_USERNAME} = $ret->{USERNAME};
1979 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1980 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1985 sub teardown_env_terminate($$)
1987 my ($self, $envvars) = @_;
1990 # This should cause samba to terminate gracefully
1991 close($envvars->{STDIN_PIPE});
1993 $pid = $envvars->{SAMBA_PID};
1997 # This should give it time to write out the gcov data
1998 until ($count > 15) {
1999 if (Samba::cleanup_child($pid, "samba") != 0) {
2006 # After 15 Seconds, work out why this thing is still alive
2007 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2008 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2010 until ($count > 30) {
2011 if (Samba::cleanup_child($pid, "samba") != 0) {
2018 if (kill(0, $pid)) {
2019 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2023 until ($count > 40) {
2024 if (Samba::cleanup_child($pid, "samba") != 0) {
2030 # If it is still around, kill it
2031 if (kill(0, $pid)) {
2032 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2038 sub teardown_env($$)
2040 my ($self, $envvars) = @_;
2041 teardown_env_terminate($self, $envvars);
2043 $self->slapd_stop($envvars) if ($self->{ldap});
2045 print $self->getlog_env($envvars);
2052 my ($self, $envvars) = @_;
2053 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2056 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2058 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2062 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2065 return "" if $out eq $title;
2072 my ($self, $envvars) = @_;
2073 my $samba_pid = $envvars->{SAMBA_PID};
2075 if (not defined($samba_pid)) {
2077 } elsif ($samba_pid > 0) {
2078 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2080 if ($childpid == 0) {
2089 # Declare the environments Samba4 makes available.
2090 # To be set up, they will be called as
2091 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2092 %Samba4::ENV_DEPS = (
2093 # name => [dep_1, dep_2, ...],
2097 ad_dc_no_ntlm => [],
2100 fl2008r2dc => ["ad_dc"],
2101 fl2003dc => ["ad_dc"],
2104 vampire_2000_dc => ["fl2000dc"],
2105 vampire_dc => ["ad_dc_ntvfs"],
2106 promoted_dc => ["ad_dc_ntvfs"],
2107 subdom_dc => ["ad_dc_ntvfs"],
2109 rodc => ["ad_dc_ntvfs"],
2110 rpc_proxy => ["ad_dc_ntvfs"],
2113 s4member_dflt_domain => ["ad_dc_ntvfs"],
2114 s4member => ["ad_dc_ntvfs"],
2121 my ($self, $path, $dc_vars) = @_;
2123 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2126 if (not defined($self->check_or_start($env, "standard"))) {
2134 sub setup_s4member_dflt_domain
2136 my ($self, $path, $dc_vars) = @_;
2138 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2139 "winbind use default domain = yes");
2142 if (not defined($self->check_or_start($env, "standard"))) {
2152 my ($self, $path, $dc_vars) = @_;
2154 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2157 if (not defined($self->check_or_start($env, "standard"))) {
2164 sub setup_ad_dc_ntvfs
2166 my ($self, $path) = @_;
2168 my $env = $self->provision_ad_dc_ntvfs($path);
2170 if (not defined($self->check_or_start($env, "standard"))) {
2171 warn("Failed to start ad_dc_ntvfs");
2180 my ($self, $path) = @_;
2182 my $env = $self->provision_chgdcpass($path);
2184 if (not defined($self->check_or_start($env, "standard"))) {
2193 my ($self, $path) = @_;
2195 my $env = $self->provision_fl2000dc($path);
2197 if (not defined($self->check_or_start($env, "standard"))) {
2207 my ($self, $path, $dc_vars) = @_;
2209 my $env = $self->provision_fl2003dc($path);
2212 if (not defined($self->check_or_start($env, "standard"))) {
2216 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2221 sub setup_fl2008r2dc
2223 my ($self, $path, $dc_vars) = @_;
2225 my $env = $self->provision_fl2008r2dc($path);
2228 if (not defined($self->check_or_start($env, "standard"))) {
2232 my $upn_array = ["$env->{REALM}.upn"];
2233 my $spn_array = ["$env->{REALM}.spn"];
2235 $self->setup_namespaces($env, $upn_array, $spn_array);
2237 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2243 sub setup_vampire_dc
2245 return setup_generic_vampire_dc(@_, "2008");
2248 sub setup_vampire_2000_dc
2250 return setup_generic_vampire_dc(@_, "2000");
2253 sub setup_generic_vampire_dc
2255 my ($self, $path, $dc_vars, $fl) = @_;
2257 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2260 if (not defined($self->check_or_start($env, "single"))) {
2264 # force replicated DC to update repsTo/repsFrom
2265 # for vampired partitions
2266 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2268 # as 'vampired' dc may add data in its local replica
2269 # we need to synchronize data between DCs
2270 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2272 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2273 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2274 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2276 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2278 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2279 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2280 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2281 $cmd .= " $dc_vars->{CONFIGURATION}";
2282 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2283 # replicate Configuration NC
2284 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2285 unless(system($cmd_repl) == 0) {
2286 warn("Failed to replicate\n$cmd_repl");
2289 # replicate Default NC
2290 $cmd_repl = "$cmd \"$base_dn\"";
2291 unless(system($cmd_repl) == 0) {
2292 warn("Failed to replicate\n$cmd_repl");
2296 # Pull in a full set of changes from the main DC
2297 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2299 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2300 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2301 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2303 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2305 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2306 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2307 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2308 $cmd .= " $dc_vars->{CONFIGURATION}";
2309 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2310 # replicate Configuration NC
2311 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2312 unless(system($cmd_repl) == 0) {
2313 warn("Failed to replicate\n$cmd_repl");
2316 # replicate Default NC
2317 $cmd_repl = "$cmd \"$base_dn\"";
2318 unless(system($cmd_repl) == 0) {
2319 warn("Failed to replicate\n$cmd_repl");
2327 sub setup_promoted_dc
2329 my ($self, $path, $dc_vars) = @_;
2331 my $env = $self->provision_promoted_dc($path, $dc_vars);
2334 if (not defined($self->check_or_start($env, "single"))) {
2338 # force source and replicated DC to update repsTo/repsFrom
2339 # for vampired partitions
2340 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2342 # as 'vampired' dc may add data in its local replica
2343 # we need to synchronize data between DCs
2344 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2345 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2346 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2347 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2348 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2349 $cmd .= " $dc_vars->{CONFIGURATION}";
2350 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2351 # replicate Configuration NC
2352 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2353 unless(system($cmd_repl) == 0) {
2354 warn("Failed to replicate\n$cmd_repl");
2357 # replicate Default NC
2358 $cmd_repl = "$cmd \"$base_dn\"";
2359 unless(system($cmd_repl) == 0) {
2360 warn("Failed to replicate\n$cmd_repl");
2370 my ($self, $path, $dc_vars) = @_;
2372 my $env = $self->provision_subdom_dc($path, $dc_vars);
2375 if (not defined($self->check_or_start($env, "single"))) {
2379 # force replicated DC to update repsTo/repsFrom
2380 # for primary domain partitions
2381 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2383 # as 'subdomain' dc may add data in its local replica
2384 # we need to synchronize data between DCs
2385 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2386 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2387 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2388 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2389 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2390 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2391 $cmd .= " $dc_vars->{CONFIGURATION}";
2392 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2393 # replicate Configuration NC
2394 my $cmd_repl = "$cmd \"$config_dn\"";
2395 unless(system($cmd_repl) == 0) {
2396 warn("Failed to replicate\n$cmd_repl");
2399 # replicate Default NC
2400 $cmd_repl = "$cmd \"$base_dn\"";
2401 unless(system($cmd_repl) == 0) {
2402 warn("Failed to replicate\n$cmd_repl");
2412 my ($self, $path, $dc_vars) = @_;
2414 my $env = $self->provision_rodc($path, $dc_vars);
2420 if (not defined($self->check_or_start($env, "standard"))) {
2424 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2427 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2428 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2429 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2430 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2431 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2432 $cmd .= " $dc_vars->{CONFIGURATION}";
2433 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2434 # replicate Configuration NC
2435 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2436 unless(system($cmd_repl) == 0) {
2437 warn("Failed to replicate\n$cmd_repl");
2440 # replicate Default NC
2441 $cmd_repl = "$cmd \"$base_dn\"";
2442 unless(system($cmd_repl) == 0) {
2443 warn("Failed to replicate\n$cmd_repl");
2452 my ($self, $path) = @_;
2454 # If we didn't build with ADS, pretend this env was never available
2455 if (not $self->{target3}->have_ads()) {
2459 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2460 "addom.samba.example.com", "");
2465 if (not defined($self->check_or_start($env, "single"))) {
2469 my $upn_array = ["$env->{REALM}.upn"];
2470 my $spn_array = ["$env->{REALM}.spn"];
2472 $self->setup_namespaces($env, $upn_array, $spn_array);
2477 sub setup_ad_dc_no_nss
2479 my ($self, $path) = @_;
2481 # If we didn't build with ADS, pretend this env was never available
2482 if (not $self->{target3}->have_ads()) {
2486 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2487 "adnonssdom.samba.example.com", "");
2492 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2493 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2495 if (not defined($self->check_or_start($env, "single"))) {
2499 my $upn_array = ["$env->{REALM}.upn"];
2500 my $spn_array = ["$env->{REALM}.spn"];
2502 $self->setup_namespaces($env, $upn_array, $spn_array);
2507 sub setup_ad_dc_no_ntlm
2509 my ($self, $path) = @_;
2511 # If we didn't build with ADS, pretend this env was never available
2512 if (not $self->{target3}->have_ads()) {
2516 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2517 "adnontlmdom.samba.example.com",
2518 "ntlm auth = disabled");
2523 if (not defined($self->check_or_start($env, "prefork"))) {
2527 my $upn_array = ["$env->{REALM}.upn"];
2528 my $spn_array = ["$env->{REALM}.spn"];
2530 $self->setup_namespaces($env, $upn_array, $spn_array);
2537 my ($self, $path) = @_;
2540 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",