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.
6 # NOTE: Refer to the README for more details about the various testenvs,
7 # and tips about adding new testenvs.
13 use FindBin qw($RealBin);
21 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
28 server_maxtime => $server_maxtime,
29 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
35 sub scriptdir_path($$) {
36 my ($self, $path) = @_;
37 return "$self->{srcdir}/source4/scripting/$path";
40 sub openldap_start($$$) {
46 my ($self, $env_vars, $STDIN_READER) = @_;
47 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
49 my $uri = $env_vars->{LDAP_URI};
51 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
52 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
55 # running slapd in the background means it stays in the same process group, so it can be
59 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
60 open STDERR, '>&STDOUT';
61 close($env_vars->{STDIN_PIPE});
62 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
64 if ($self->{ldap} eq "fedora-ds") {
65 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
66 } elsif ($self->{ldap} eq "openldap") {
67 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
69 die("Unable to start slapd: $!");
71 $env_vars->{SLAPD_PID} = $pid;
73 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
76 $self->slapd_stop($env_vars);
86 my ($self, $envvars) = @_;
87 kill 9, $envvars->{SLAPD_PID};
91 sub check_or_start($$$)
93 my ($self, $env_vars, $process_model) = @_;
96 my $env_ok = $self->check_env($env_vars);
98 return $env_vars->{SAMBA_PID};
99 } elsif (defined($env_vars->{SAMBA_PID})) {
100 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
104 # use a pipe for stdin in the child processes. This allows
105 # those processes to monitor the pipe for EOF to ensure they
106 # exit when the test script exits
107 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
109 # Start slapd before samba, but with the fifo on stdin
110 if (defined($self->{ldap})) {
111 unless($self->slapd_start($env_vars, $STDIN_READER)) {
112 warn("couldn't start slapd (main run)");
117 print "STARTING SAMBA...\n";
120 # we want out from samba to go to the log file, but also
121 # to the users terminal when running 'make test' on the command
122 # line. This puts it on stderr on the terminal
123 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
124 open STDERR, '>&STDOUT';
126 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
128 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
129 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
130 if (defined($ENV{MITKRB5})) {
131 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
133 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
134 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
136 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
137 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
138 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
139 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
140 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
141 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
143 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
144 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
146 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
149 $ENV{UID_WRAPPER} = "1";
150 $ENV{UID_WRAPPER_ROOT} = "1";
152 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
155 if (defined($ENV{SAMBA_OPTIONS})) {
156 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
158 if(defined($ENV{SAMBA_VALGRIND})) {
159 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
162 close($env_vars->{STDIN_PIPE});
163 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
165 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: $!");
167 $env_vars->{SAMBA_PID} = $pid;
168 print "DONE ($pid)\n";
170 close($STDIN_READER);
172 if ($self->wait_for_start($env_vars) != 0) {
173 warn("Samba $pid failed to start up");
180 sub wait_for_start($$)
182 my ($self, $testenv_vars) = @_;
186 if (not $self->check_env($testenv_vars)) {
187 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
191 # This will return quickly when things are up, but be slow if we
192 # need to wait for (eg) SSL init
193 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
196 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
200 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
201 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
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->{SERVER}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
207 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
208 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
209 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
210 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
213 } while ($ret != 0 && $count < 20);
215 warn("nbt not reachable after 20 retries\n");
216 teardown_env($self, $testenv_vars);
220 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
221 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
222 print "waiting for working LDAP and a RID Set to be allocated\n";
223 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
225 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
227 my $search_dn = $base_dn;
228 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
229 # TODO currently no check for actual rIDAllocationPool
230 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
234 # Add hosts file for name lookups
235 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
236 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
237 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
239 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
242 $cmd .= "$ldbsearch ";
243 $cmd .= "$testenv_vars->{CONFIGURATION} ";
244 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
245 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
247 $cmd .= "-b '$search_dn' ";
248 while (system("$cmd >/dev/null") != 0) {
250 if ($count > $max_wait) {
251 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}");
259 my $wbinfo = Samba::bindir_path($self, "wbinfo");
263 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
264 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
265 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
266 $cmd .= "$wbinfo -P";
273 } while ($ret != 0 && $count < 20);
275 warn("winbind not reachable after 20 retries\n");
276 teardown_env($self, $testenv_vars);
280 print $self->getlog_env($testenv_vars);
285 sub write_ldb_file($$$)
287 my ($self, $file, $ldif) = @_;
289 my $ldbadd = Samba::bindir_path($self, "ldbadd");
290 open(LDIF, "|$ldbadd -H $file >/dev/null");
295 sub add_wins_config($$)
297 my ($self, $privatedir) = @_;
299 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
300 dn: name=TORTURE_11,CN=PARTNERS
301 objectClass: wreplPartner
312 my ($self, $ctx) = @_;
314 #Make the subdirectory be as fedora DS would expect
315 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
317 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
319 return ($fedora_ds_dir, $pidfile);
324 my ($self, $ctx) = @_;
326 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
327 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
329 return ($slapd_conf_d, $pidfile);
332 sub setup_namespaces($$:$$)
334 my ($self, $localenv, $upn_array, $spn_array) = @_;
336 @{$upn_array} = [] unless defined($upn_array);
338 foreach my $upn (@{$upn_array}) {
339 $upn_args .= " --add-upn-suffix=$upn";
342 @{$spn_array} = [] unless defined($spn_array);
344 foreach my $spn (@{$spn_array}) {
345 $spn_args .= " --add-spn-suffix=$spn";
348 my $samba_tool = Samba::bindir_path($self, "samba-tool");
350 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
351 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
352 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
353 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
355 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
357 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
358 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
360 my $cmd_config = " $localenv->{CONFIGURATION}";
362 my $namespaces = $cmd_env;
363 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
364 $namespaces .= $cmd_config;
365 unless (system($namespaces) == 0) {
366 warn("Failed to add namespaces \n$namespaces");
373 sub setup_trust($$$$$)
375 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
377 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
378 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
379 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
380 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
381 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
382 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
383 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
384 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
385 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
387 my $samba_tool = Samba::bindir_path($self, "samba-tool");
390 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
391 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
392 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
393 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
395 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
397 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
398 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
400 my $cmd_config = " $localenv->{CONFIGURATION}";
401 my $cmd_creds = $cmd_config;
402 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
404 my $create = $cmd_env;
405 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
406 $create .= " $extra_args";
407 $create .= $cmd_creds;
408 unless (system($create) == 0) {
409 warn("Failed to create trust \n$create");
413 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
414 my $groupadd = $cmd_env;
415 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
416 unless (system($groupadd) == 0) {
417 warn("Failed to create group \n$groupadd");
420 my $groupmem = $cmd_env;
421 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
422 unless (system($groupmem) == 0) {
423 warn("Failed to add group member \n$groupmem");
430 sub provision_raw_prepare($$$$$$$$$$$$)
432 my ($self, $prefix, $server_role, $hostname,
433 $domain, $realm, $samsid, $functional_level,
434 $password, $kdc_ipv4, $kdc_ipv6) = @_;
437 if (defined $ENV{PYTHON}) {
438 $python_cmd = $ENV{PYTHON} . " ";
440 $ctx->{python} = $python_cmd;
441 my $netbiosname = uc($hostname);
443 unless(-d $prefix or mkdir($prefix, 0777)) {
444 warn("Unable to create $prefix");
447 my $prefix_abs = abs_path($prefix);
449 die ("prefix=''") if $prefix_abs eq "";
450 die ("prefix='/'") if $prefix_abs eq "/";
452 unless (system("rm -rf $prefix_abs/*") == 0) {
453 warn("Unable to clean up");
457 my $swiface = Samba::get_interface($hostname);
459 $ctx->{prefix} = $prefix;
460 $ctx->{prefix_abs} = $prefix_abs;
462 $ctx->{server_role} = $server_role;
463 $ctx->{hostname} = $hostname;
464 $ctx->{netbiosname} = $netbiosname;
465 $ctx->{swiface} = $swiface;
466 $ctx->{password} = $password;
467 $ctx->{kdc_ipv4} = $kdc_ipv4;
468 $ctx->{kdc_ipv6} = $kdc_ipv6;
469 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
470 if ($functional_level eq "2000") {
471 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
475 # Set smbd log level here.
477 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
478 $ctx->{username} = "Administrator";
479 $ctx->{domain} = $domain;
480 $ctx->{realm} = uc($realm);
481 $ctx->{dnsname} = lc($realm);
482 $ctx->{samsid} = $samsid;
484 $ctx->{functional_level} = $functional_level;
486 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
488 $ctx->{unix_name} = $unix_name;
489 $ctx->{unix_uid} = $>;
490 my @mygid = split(" ", $();
491 $ctx->{unix_gid} = $mygid[0];
492 $ctx->{unix_gids_str} = $);
493 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
495 $ctx->{etcdir} = "$prefix_abs/etc";
496 $ctx->{piddir} = "$prefix_abs/pid";
497 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
498 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
499 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
500 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
501 $ctx->{privatedir} = "$prefix_abs/private";
502 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
503 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
504 $ctx->{lockdir} = "$prefix_abs/lockdir";
505 $ctx->{logdir} = "$prefix_abs/logs";
506 $ctx->{statedir} = "$prefix_abs/statedir";
507 $ctx->{cachedir} = "$prefix_abs/cachedir";
508 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
509 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
510 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
511 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
512 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
513 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
514 if ($ENV{SAMBA_DNS_FAKING}) {
515 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
516 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
517 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
519 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
520 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
521 $ctx->{use_resolv_wrapper} = 1;
523 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
525 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
527 $ctx->{ipv4} = "127.0.0.$swiface";
528 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
529 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
531 push(@{$ctx->{directories}}, $ctx->{privatedir});
532 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
533 push(@{$ctx->{directories}}, $ctx->{etcdir});
534 push(@{$ctx->{directories}}, $ctx->{piddir});
535 push(@{$ctx->{directories}}, $ctx->{lockdir});
536 push(@{$ctx->{directories}}, $ctx->{logdir});
537 push(@{$ctx->{directories}}, $ctx->{statedir});
538 push(@{$ctx->{directories}}, $ctx->{cachedir});
540 $ctx->{smb_conf_extra_options} = "";
542 my @provision_options = ();
543 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
544 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
545 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
546 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
547 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
548 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
549 if (defined($ctx->{use_resolv_wrapper})) {
550 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
552 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
554 if (defined($ENV{GDB_PROVISION})) {
555 push (@provision_options, "gdb --args");
556 if (!defined($ENV{PYTHON})) {
557 push (@provision_options, "env");
558 push (@provision_options, "python");
561 if (defined($ENV{VALGRIND_PROVISION})) {
562 push (@provision_options, "valgrind");
563 if (!defined($ENV{PYTHON})) {
564 push (@provision_options, "env");
565 push (@provision_options, "python");
569 my $samba_tool = Samba::bindir_path($self, "samba-tool");
571 push (@provision_options, $samba_tool);
572 push (@provision_options, "domain");
573 push (@provision_options, "provision");
574 push (@provision_options, "--configfile=$ctx->{smb_conf}");
575 push (@provision_options, "--host-name=$ctx->{hostname}");
576 push (@provision_options, "--host-ip=$ctx->{ipv4}");
577 push (@provision_options, "--quiet");
578 push (@provision_options, "--domain=$ctx->{domain}");
579 push (@provision_options, "--realm=$ctx->{realm}");
580 if (defined($ctx->{samsid})) {
581 push (@provision_options, "--domain-sid=$ctx->{samsid}");
583 push (@provision_options, "--adminpass=$ctx->{password}");
584 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
585 push (@provision_options, "--machinepass=machine$ctx->{password}");
586 push (@provision_options, "--root=$ctx->{unix_name}");
587 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
588 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
590 @{$ctx->{provision_options}} = @provision_options;
596 # Step1 creates the basic configuration
598 sub provision_raw_step1($$)
600 my ($self, $ctx) = @_;
602 mkdir($_, 0777) foreach (@{$ctx->{directories}});
605 ## lockdir and piddir must be 0755
607 chmod 0755, $ctx->{lockdir};
608 chmod 0755, $ctx->{piddir};
610 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
611 warn("can't open $ctx->{smb_conf}$?");
615 Samba::prepare_keyblobs($ctx);
616 my $crlfile = "$ctx->{tlsdir}/crl.pem";
617 $crlfile = "" unless -e ${crlfile};
621 netbios name = $ctx->{netbiosname}
622 posix:eadb = $ctx->{statedir}/eadb.tdb
623 workgroup = $ctx->{domain}
624 realm = $ctx->{realm}
625 private dir = $ctx->{privatedir}
626 binddns dir = $ctx->{binddnsdir}
627 pid directory = $ctx->{piddir}
628 ncalrpc dir = $ctx->{ncalrpcdir}
629 lock dir = $ctx->{lockdir}
630 state directory = $ctx->{statedir}
631 cache directory = $ctx->{cachedir}
632 winbindd socket directory = $ctx->{winbindd_socket_dir}
633 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
634 winbind separator = /
635 interfaces = $ctx->{interfaces}
636 tls dh params file = $ctx->{tlsdir}/dhparms.pem
637 tls crlfile = ${crlfile}
638 tls verify peer = no_check
639 panic action = $RealBin/gdb_backtrace \%d
641 server role = $ctx->{server_role}
642 server services = +echo +smb -s3fs
643 dcerpc endpoint servers = +winreg +srvsvc
644 notify:inotify = false
646 ldap server require strong auth = yes
647 #We don't want to pass our self-tests if the PAC code is wrong
648 gensec:require_pac = true
649 log file = $ctx->{logdir}/log.\%m
650 log level = $ctx->{server_loglevel}
654 dns update command = $ctx->{samba_dnsupdate}
655 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
656 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
657 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
658 dreplsrv:periodic_startup_interval = 0
659 dsdb:schema update allowed = yes
663 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
665 idmap_ldb:use rfc2307=yes
666 winbind enum users = yes
667 winbind enum groups = yes
669 rpc server port:netlogon = 1026
675 # Begin extra options
676 $ctx->{smb_conf_extra_options}
681 #Default the KDC IP to the server's IP
682 if (not defined($ctx->{kdc_ipv4})) {
683 $ctx->{kdc_ipv4} = $ctx->{ipv4};
685 if (not defined($ctx->{kdc_ipv6})) {
686 $ctx->{kdc_ipv6} = $ctx->{ipv6};
689 Samba::mk_krb5_conf($ctx);
690 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
692 open(PWD, ">$ctx->{nsswrap_passwd}");
693 if ($ctx->{unix_uid} != 0) {
694 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
696 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
697 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
698 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
699 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
700 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
701 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
704 my $uid_rfc2307test = 65533;
706 open(GRP, ">$ctx->{nsswrap_group}");
707 if ($ctx->{unix_gid} != 0) {
708 print GRP "root:x:0:\n";
710 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
711 print GRP "wheel:x:10:
714 nogroup:x:65534:nobody
717 my $gid_rfc2307test = 65532;
719 my $hostname = lc($ctx->{hostname});
720 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
721 if ($hostname eq "localdc") {
722 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
723 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
725 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
726 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
730 if (defined($ctx->{resolv_conf})) {
731 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
732 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
733 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
737 my $configuration = "--configfile=$ctx->{smb_conf}";
739 #Ensure the config file is valid before we start
740 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
741 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
742 system("$testparm -v --suppress-prompt $configuration >&2");
743 warn("Failed to create a valid smb.conf configuration $testparm!");
746 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) {
747 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
752 KRB5_CONFIG => $ctx->{krb5_conf},
753 KRB5_CCACHE => $ctx->{krb5_ccache},
754 MITKDC_CONFIG => $ctx->{mitkdc_conf},
755 PIDDIR => $ctx->{piddir},
756 SERVER => $ctx->{hostname},
757 SERVER_IP => $ctx->{ipv4},
758 SERVER_IPV6 => $ctx->{ipv6},
759 NETBIOSNAME => $ctx->{netbiosname},
760 DOMAIN => $ctx->{domain},
761 USERNAME => $ctx->{username},
762 REALM => $ctx->{realm},
763 DNSNAME => $ctx->{dnsname},
764 SAMSID => $ctx->{samsid},
765 PASSWORD => $ctx->{password},
766 LDAPDIR => $ctx->{ldapdir},
767 LDAP_INSTANCE => $ctx->{ldap_instance},
768 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
769 NCALRPCDIR => $ctx->{ncalrpcdir},
770 LOCKDIR => $ctx->{lockdir},
771 STATEDIR => $ctx->{statedir},
772 CACHEDIR => $ctx->{cachedir},
773 PRIVATEDIR => $ctx->{privatedir},
774 BINDDNSDIR => $ctx->{binddnsdir},
775 SERVERCONFFILE => $ctx->{smb_conf},
776 CONFIGURATION => $configuration,
777 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
778 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
779 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
780 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
781 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
782 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
783 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
784 SAMBA_TEST_LOG_POS => 0,
785 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
786 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
787 LOCAL_PATH => $ctx->{share},
788 UID_RFC2307TEST => $uid_rfc2307test,
789 GID_RFC2307TEST => $gid_rfc2307test,
790 SERVER_ROLE => $ctx->{server_role},
791 RESOLV_CONF => $ctx->{resolv_conf}
794 if (defined($ctx->{use_resolv_wrapper})) {
795 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
797 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
800 if ($ctx->{server_role} eq "domain controller") {
801 $ret->{DOMSID} = $ret->{SAMSID};
808 # Step2 runs the provision script
810 sub provision_raw_step2($$$)
812 my ($self, $ctx, $ret) = @_;
814 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
815 unless (system($provision_cmd) == 0) {
816 warn("Unable to provision: \n$provision_cmd\n");
820 my $testallowed_account = "testallowed";
821 my $samba_tool_cmd = "";
822 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
823 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
824 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
825 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
826 unless (system($samba_tool_cmd) == 0) {
827 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
832 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
833 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
834 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
835 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
837 if ($ctx->{server_role} ne "domain controller") {
838 $base_dn = "DC=$ctx->{netbiosname}";
841 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
842 $testallowed_account = "testallowed account";
843 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
844 print LDIF "dn: $user_dn
846 replace: samAccountName
847 samAccountName: $testallowed_account
852 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
853 print LDIF "dn: $user_dn
855 replace: userPrincipalName
856 userPrincipalName: testallowed upn\@$ctx->{realm}
857 replace: servicePrincipalName
858 servicePrincipalName: host/testallowed
863 $samba_tool_cmd = "";
864 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
865 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
866 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
867 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
868 unless (system($samba_tool_cmd) == 0) {
869 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
873 my $user_dn = "cn=testdenied,cn=users,$base_dn";
874 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
875 print LDIF "dn: $user_dn
877 replace: userPrincipalName
878 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
883 $samba_tool_cmd = "";
884 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
885 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
886 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
887 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
888 unless (system($samba_tool_cmd) == 0) {
889 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
893 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
894 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
895 print LDIF "dn: $user_dn
897 replace: userPrincipalName
898 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
899 replace: servicePrincipalName
900 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
905 $samba_tool_cmd = "";
906 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
907 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
908 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
909 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
910 unless (system($samba_tool_cmd) == 0) {
911 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
915 # Create to users alice and bob!
916 my $user_account_array = ["alice", "bob", "jane"];
918 foreach my $user_account (@{$user_account_array}) {
919 my $samba_tool_cmd = "";
921 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
922 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
923 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
924 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
925 unless (system($samba_tool_cmd) == 0) {
926 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
932 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
933 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
934 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
936 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
937 my $user_dn = "cn=jane,cn=users,$base_dn";
939 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
940 print LDIF "dn: $user_dn
942 replace: userPrincipalName
943 userPrincipalName: jane.doe\@$ctx->{realm}
951 sub provision($$$$$$$$$$)
953 my ($self, $prefix, $server_role, $hostname,
954 $domain, $realm, $functional_level,
955 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
956 $extra_provision_options) = @_;
958 my $samsid = Samba::random_domain_sid();
960 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
965 $password, $kdc_ipv4, $kdc_ipv6);
967 if (defined($extra_provision_options)) {
968 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
971 $ctx->{share} = "$ctx->{prefix_abs}/share";
972 push(@{$ctx->{directories}}, "$ctx->{share}");
973 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
974 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
976 # precreate directories for printer drivers
977 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
978 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
979 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
982 $msdfs = "yes" if ($server_role eq "domain controller");
983 $ctx->{smb_conf_extra_options} = "
986 server max protocol = SMB2
990 # fruit:copyfile is a global option
993 $extra_smbconf_options
998 posix:sharedelay = 100000
999 posix:oplocktimeout = 3
1000 posix:writetimeupdatedelay = 500000
1003 path = $ctx->{share}
1005 posix:sharedelay = 100000
1006 posix:oplocktimeout = 3
1007 posix:writetimeupdatedelay = 500000
1009 force create mode = 777
1012 path = $ctx->{share}
1015 force create mode = 0
1016 directory mask = 0777
1017 force directory mode = 0
1020 path = $ctx->{share}/test1
1022 posix:sharedelay = 100000
1023 posix:oplocktimeout = 3
1024 posix:writetimeupdatedelay = 500000
1027 path = $ctx->{share}/test2
1029 posix:sharedelay = 100000
1030 posix:oplocktimeout = 3
1031 posix:writetimeupdatedelay = 500000
1034 path = $ctx->{share}/_ignore_cifs_
1036 ntvfs handler = cifs
1037 cifs:server = $ctx->{netbiosname}
1039 cifs:use-s4u2proxy = yes
1040 # There is no username specified here, instead the client is expected
1041 # to log in with kerberos, and the serverwill use delegated credentials.
1042 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1045 path = $ctx->{share}
1047 ntvfs handler = simple
1050 path = $ctx->{statedir}/sysvol
1054 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1059 ntvfs handler = cifsposix
1062 path = $ctx->{share}
1063 vfs objects = catia fruit streams_xattr acl_xattr
1065 fruit:resource = file
1066 fruit:metadata = netatalk
1067 fruit:locking = netatalk
1068 fruit:encoding = native
1070 $extra_smbconf_shares
1073 if (defined($self->{ldap})) {
1074 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1075 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1077 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1078 $ldap_uri =~ s|/|%2F|g;
1079 $ldap_uri = "ldapi://$ldap_uri";
1080 $ctx->{ldap_uri} = $ldap_uri;
1082 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1085 my $ret = $self->provision_raw_step1($ctx);
1086 unless (defined $ret) {
1090 if (defined($self->{ldap})) {
1091 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1092 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1093 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1094 if ($self->{ldap} eq "openldap") {
1095 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1096 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1098 } elsif ($self->{ldap} eq "fedora-ds") {
1099 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1100 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1101 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1106 return $self->provision_raw_step2($ctx, $ret);
1109 sub provision_s4member($$$$$)
1111 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1112 print "PROVISIONING MEMBER...\n";
1113 my $extra_smb_conf = "
1114 passdb backend = samba_dsdb
1115 winbindd:use external pipes = true
1117 # the source4 smb server doesn't allow signing by default
1118 server signing = enabled
1119 raw NTLMv2 auth = yes
1121 rpc_server:default = external
1122 rpc_server:svcctl = embedded
1123 rpc_server:srvsvc = embedded
1124 rpc_server:eventlog = embedded
1125 rpc_server:ntsvcs = embedded
1126 rpc_server:winreg = embedded
1127 rpc_server:spoolss = embedded
1128 rpc_daemon:spoolssd = embedded
1129 rpc_server:tcpip = no
1132 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1134 my $extra_provision_options = ["--use-ntvfs"];
1135 my $ret = $self->provision($prefix,
1142 $dcvars->{SERVER_IP},
1143 $dcvars->{SERVER_IPV6},
1144 $extra_smb_conf, "",
1145 $extra_provision_options);
1150 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1151 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1152 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1153 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1154 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1156 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1158 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1159 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1160 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1161 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1162 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1164 unless (system($cmd) == 0) {
1165 warn("Join failed\n$cmd");
1169 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1170 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1171 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1172 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1173 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1174 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1176 $ret->{DOMSID} = $dcvars->{DOMSID};
1177 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1178 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1179 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1180 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1181 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1182 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1187 sub provision_rpc_proxy($$$)
1189 my ($self, $prefix, $dcvars) = @_;
1190 print "PROVISIONING RPC PROXY...\n";
1192 my $extra_smbconf_options = "
1193 passdb backend = samba_dsdb
1196 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1197 dcerpc endpoint servers = epmapper, remote
1198 dcerpc_remote:interfaces = rpcecho
1201 path = /tmp/_ignore_cifs_to_dc_/_none_
1203 ntvfs handler = cifs
1204 cifs:server = $dcvars->{SERVER}
1206 cifs:use-s4u2proxy = yes
1207 # There is no username specified here, instead the client is expected
1208 # to log in with kerberos, and the serverwill use delegated credentials.
1209 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1213 my $extra_provision_options = ["--use-ntvfs"];
1214 my $ret = $self->provision($prefix,
1221 $dcvars->{SERVER_IP},
1222 $dcvars->{SERVER_IPV6},
1223 $extra_smbconf_options, "",
1224 $extra_provision_options);
1229 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1231 # The joind runs in the context of the rpc_proxy/member for now
1232 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1233 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1234 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1235 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1237 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1239 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1240 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1241 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1242 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1243 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1245 unless (system($cmd) == 0) {
1246 warn("Join failed\n$cmd");
1250 # Setting up delegation runs in the context of the DC for now
1252 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1253 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1254 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1255 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1256 $cmd .= " $dcvars->{CONFIGURATION}";
1259 unless (system($cmd) == 0) {
1260 warn("Delegation failed\n$cmd");
1264 # Setting up delegation runs in the context of the DC for now
1266 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1267 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1268 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1269 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1270 $cmd .= " $dcvars->{CONFIGURATION}";
1272 unless (system($cmd) == 0) {
1273 warn("Delegation failed\n$cmd");
1277 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1278 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1279 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1280 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1281 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1282 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1284 $ret->{DOMSID} = $dcvars->{DOMSID};
1285 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1286 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1287 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1288 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1289 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1290 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1295 sub provision_promoted_dc($$$)
1297 my ($self, $prefix, $dcvars) = @_;
1298 print "PROVISIONING PROMOTED DC...\n";
1300 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1301 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1307 $dcvars->{PASSWORD},
1308 $dcvars->{SERVER_IP},
1309 $dcvars->{SERVER_IPV6});
1311 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1313 $ctx->{smb_conf_extra_options} = "
1315 server max protocol = SMB2
1317 ntlm auth = ntlmv2-only
1320 path = $ctx->{statedir}/sysvol
1324 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1329 my $ret = $self->provision_raw_step1($ctx);
1334 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1335 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1336 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1337 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1338 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1340 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1342 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1343 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1344 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1345 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1346 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1348 unless (system($cmd) == 0) {
1349 warn("Join failed\n$cmd");
1353 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1354 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1355 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1356 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1357 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1359 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1361 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1362 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1363 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1364 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1365 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1367 unless (system($cmd) == 0) {
1368 warn("Join failed\n$cmd");
1372 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1373 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1374 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1375 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1377 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1378 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1379 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1380 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1381 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1382 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1387 sub provision_vampire_dc($$$)
1389 my ($self, $prefix, $dcvars, $fl) = @_;
1390 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1391 my $name = "localvampiredc";
1392 my $extra_conf = "";
1394 if ($fl == "2000") {
1395 $name = "vampire2000dc";
1397 $extra_conf = "drs: immediate link sync = yes
1398 drs: max link sync = 250";
1401 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1402 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1408 $dcvars->{PASSWORD},
1409 $dcvars->{SERVER_IP},
1410 $dcvars->{SERVER_IPV6});
1412 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1414 $ctx->{smb_conf_extra_options} = "
1416 server max protocol = SMB2
1418 ntlm auth = mschapv2-and-ntlmv2-only
1422 path = $ctx->{statedir}/sysvol
1426 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1431 my $ret = $self->provision_raw_step1($ctx);
1436 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1437 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1438 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1439 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1440 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1442 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1444 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1445 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1446 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1447 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1448 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1449 $cmd .= " --backend-store=mdb";
1451 unless (system($cmd) == 0) {
1452 warn("Join failed\n$cmd");
1456 if ($fl == "2000") {
1457 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1458 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1459 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1460 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1462 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1463 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1464 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1465 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1467 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1468 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1469 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1470 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1471 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1472 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1473 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1478 sub provision_subdom_dc($$$)
1480 my ($self, $prefix, $dcvars) = @_;
1481 print "PROVISIONING SUBDOMAIN DC...\n";
1483 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1484 my $samsid = undef; # TODO pass the domain sid all the way down
1485 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1488 "sub.samba.example.com",
1491 $dcvars->{PASSWORD},
1494 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1496 $ctx->{smb_conf_extra_options} = "
1498 server max protocol = SMB2
1501 path = $ctx->{statedir}/sysvol
1505 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1510 my $ret = $self->provision_raw_step1($ctx);
1515 Samba::mk_krb5_conf($ctx);
1516 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1518 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1519 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1520 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1521 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1522 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1524 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1526 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1527 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1528 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1529 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1530 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1531 $cmd .= " --adminpass=$ret->{PASSWORD}";
1533 unless (system($cmd) == 0) {
1534 warn("Join failed\n$cmd");
1538 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1539 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1540 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1541 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1543 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1544 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1545 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1546 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1547 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1548 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1553 sub provision_ad_dc_ntvfs($$)
1555 my ($self, $prefix) = @_;
1557 # We keep the old 'winbind' name here in server services to
1558 # ensure upgrades which used that name still work with the now
1561 print "PROVISIONING AD DC (NTVFS)...\n";
1562 my $extra_conf_options = "netbios aliases = localDC1-a
1563 server services = +winbind -winbindd
1564 ldap server require strong auth = allow_sasl_over_tls
1565 allow nt4 crypto = yes
1566 raw NTLMv2 auth = yes
1567 lsa over netlogon = yes
1568 rpc server port = 1027
1569 auth event notification = true
1570 dsdb event notification = true
1571 dsdb password event notification = true
1572 dsdb group change notification = true
1573 server schannel = auto
1575 my $extra_provision_options = ["--use-ntvfs"];
1576 my $ret = $self->provision($prefix,
1577 "domain controller",
1580 "samba.example.com",
1585 $extra_conf_options,
1587 $extra_provision_options);
1592 unless($self->add_wins_config("$prefix/private")) {
1593 warn("Unable to add wins configuration");
1596 $ret->{NETBIOSALIAS} = "localdc1-a";
1597 $ret->{DC_SERVER} = $ret->{SERVER};
1598 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1599 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1600 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1601 $ret->{DC_USERNAME} = $ret->{USERNAME};
1602 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1603 $ret->{DC_REALM} = $ret->{REALM};
1608 sub provision_fl2000dc($$)
1610 my ($self, $prefix) = @_;
1612 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1613 my $extra_conf_options = "
1614 spnego:simulate_w2k=yes
1615 ntlmssp_server:force_old_spnego=yes
1617 my $extra_provision_options = ["--use-ntvfs"];
1618 # This environment uses plain text secrets
1619 # i.e. secret attributes are not encrypted on disk.
1620 # This allows testing of the --plaintext-secrets option for
1622 push (@{$extra_provision_options}, "--plaintext-secrets");
1623 my $ret = $self->provision($prefix,
1624 "domain controller",
1627 "samba2000.example.com",
1632 $extra_conf_options,
1634 $extra_provision_options);
1639 unless($self->add_wins_config("$prefix/private")) {
1640 warn("Unable to add wins configuration");
1643 $ret->{DC_SERVER} = $ret->{SERVER};
1644 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1645 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1646 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1647 $ret->{DC_USERNAME} = $ret->{USERNAME};
1648 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1649 $ret->{DC_REALM} = $ret->{REALM};
1654 sub provision_fl2003dc($$$)
1656 my ($self, $prefix, $dcvars) = @_;
1657 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1658 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1660 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1661 my $extra_conf_options = "allow dns updates = nonsecure and secure
1662 dcesrv:header signing = no
1663 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1664 my $extra_provision_options = ["--use-ntvfs"];
1665 my $ret = $self->provision($prefix,
1666 "domain controller",
1669 "samba2003.example.com",
1674 $extra_conf_options,
1676 $extra_provision_options);
1677 unless (defined $ret) {
1681 $ret->{DC_SERVER} = $ret->{SERVER};
1682 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1683 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1684 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1685 $ret->{DC_USERNAME} = $ret->{USERNAME};
1686 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1687 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1688 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1690 my @samba_tool_options;
1691 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1692 push (@samba_tool_options, "domain");
1693 push (@samba_tool_options, "passwordsettings");
1694 push (@samba_tool_options, "set");
1695 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1696 push (@samba_tool_options, "--min-pwd-age=0");
1697 push (@samba_tool_options, "--history-length=1");
1699 my $samba_tool_cmd = join(" ", @samba_tool_options);
1701 unless (system($samba_tool_cmd) == 0) {
1702 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1706 unless($self->add_wins_config("$prefix/private")) {
1707 warn("Unable to add wins configuration");
1714 sub provision_fl2008r2dc($$$)
1716 my ($self, $prefix, $dcvars) = @_;
1718 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1719 my $extra_conf_options = "ldap server require strong auth = no";
1720 my $extra_provision_options = ["--use-ntvfs"];
1721 my $ret = $self->provision($prefix,
1722 "domain controller",
1725 "samba2008R2.example.com",
1730 $extra_conf_options,
1732 $extra_provision_options);
1733 unless (defined $ret) {
1737 unless ($self->add_wins_config("$prefix/private")) {
1738 warn("Unable to add wins configuration");
1741 $ret->{DC_SERVER} = $ret->{SERVER};
1742 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1743 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1744 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1745 $ret->{DC_USERNAME} = $ret->{USERNAME};
1746 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1747 $ret->{DC_REALM} = $ret->{REALM};
1753 sub provision_rodc($$$)
1755 my ($self, $prefix, $dcvars) = @_;
1756 print "PROVISIONING RODC...\n";
1758 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1759 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1765 $dcvars->{PASSWORD},
1766 $dcvars->{SERVER_IP},
1767 $dcvars->{SERVER_IPV6});
1772 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1774 $ctx->{share} = "$ctx->{prefix_abs}/share";
1775 push(@{$ctx->{directories}}, "$ctx->{share}");
1777 $ctx->{smb_conf_extra_options} = "
1779 server max protocol = SMB2
1780 password server = $dcvars->{DC_SERVER}
1783 path = $ctx->{statedir}/sysvol
1787 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1791 path = $ctx->{share}
1793 posix:sharedelay = 10000
1794 posix:oplocktimeout = 3
1795 posix:writetimeupdatedelay = 50000
1799 my $ret = $self->provision_raw_step1($ctx);
1804 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1805 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1806 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1807 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1808 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1810 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1812 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1813 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1814 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1815 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1816 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1818 unless (system($cmd) == 0) {
1819 warn("RODC join failed\n$cmd");
1823 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1824 # user password verified on the RODC
1825 my $testallowed_account = "testallowed account";
1826 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1827 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1828 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1829 $cmd .= " --server=$dcvars->{DC_SERVER}";
1831 unless (system($cmd) == 0) {
1832 warn("RODC join failed\n$cmd");
1836 # we overwrite the kdc after the RODC join
1837 # so that use the RODC as kdc and test
1839 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1840 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1841 Samba::mk_krb5_conf($ctx);
1842 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1844 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1845 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1846 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1847 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1849 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1850 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1851 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1852 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1853 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1854 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1859 sub read_config_h($)
1863 open(LF, "<$name") or die("unable to read $name: $!");
1866 next if not (/^#define /);
1867 if (/^#define (.*?)[ \t]+(.*?)$/) {
1871 if (/^#define (.*?)[ \t]+$/) {
1880 sub provision_ad_dc($$$$$$)
1882 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1883 $extra_provision_options) = @_;
1885 my $prefix_abs = abs_path($prefix);
1887 my $bindir_abs = abs_path($self->{bindir});
1888 my $lockdir="$prefix_abs/lockdir";
1889 my $conffile="$prefix_abs/etc/smb.conf";
1891 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1892 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1896 if (defined($ENV{CONFIG_H})) {
1897 $config_h = read_config_h($ENV{CONFIG_H});
1900 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1901 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1903 my $extra_smbconf_options = "
1904 server services = -smb +s3fs
1905 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1907 dbwrap_tdb_mutexes:* = yes
1910 ${password_hash_gpg_key_ids}
1913 kernel change notify = no
1918 printcap name = /dev/null
1923 smbd:sharedelay = 100000
1924 smbd:writetimeupdatedelay = 500000
1927 check parent directory delete on close = yes
1929 dcerpc endpoint servers = -winreg -srvsvc
1931 printcap name = /dev/null
1933 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1934 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1937 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1938 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1939 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1940 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1941 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1942 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1943 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1945 print notify backchannel = yes
1947 server schannel = auto
1948 auth event notification = true
1949 dsdb event notification = true
1950 dsdb password event notification = true
1951 dsdb group change notification = true
1955 my $extra_smbconf_shares = "
1959 smb encrypt = required
1963 case sensitive = yes
1971 hide unreadable = yes
1975 kernel share modes = no
1994 push (@{$extra_provision_options}, "--backend-store=mdb");
1995 print "PROVISIONING AD DC...\n";
1996 my $ret = $self->provision($prefix,
1997 "domain controller",
2005 $extra_smbconf_options,
2006 $extra_smbconf_shares,
2007 $extra_provision_options);
2008 unless (defined $ret) {
2012 unless($self->add_wins_config("$prefix/private")) {
2013 warn("Unable to add wins configuration");
2017 $ret->{DC_SERVER} = $ret->{SERVER};
2018 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2019 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2020 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2021 $ret->{DC_USERNAME} = $ret->{USERNAME};
2022 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2027 sub provision_chgdcpass($$)
2029 my ($self, $prefix) = @_;
2031 print "PROVISIONING CHGDCPASS...\n";
2032 my $extra_provision_options = undef;
2033 # This environment disallows the use of this password
2034 # (and also removes the default AD complexity checks)
2035 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2036 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2037 my $ret = $self->provision($prefix,
2038 "domain controller",
2041 "chgdcpassword.samba.example.com",
2046 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
2048 $extra_provision_options);
2049 unless (defined $ret) {
2053 unless($self->add_wins_config("$prefix/private")) {
2054 warn("Unable to add wins configuration");
2058 # Remove secrets.tdb from this environment to test that we
2059 # still start up on systems without the new matching
2060 # secrets.tdb records.
2061 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2062 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2066 $ret->{DC_SERVER} = $ret->{SERVER};
2067 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2068 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2069 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2070 $ret->{DC_USERNAME} = $ret->{USERNAME};
2071 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2072 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2077 sub teardown_env_terminate($$)
2079 my ($self, $envvars) = @_;
2082 # This should cause samba to terminate gracefully
2083 close($envvars->{STDIN_PIPE});
2085 $pid = $envvars->{SAMBA_PID};
2089 # This should give it time to write out the gcov data
2090 until ($count > 15) {
2091 if (Samba::cleanup_child($pid, "samba") != 0) {
2098 # After 15 Seconds, work out why this thing is still alive
2099 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2100 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2102 until ($count > 30) {
2103 if (Samba::cleanup_child($pid, "samba") != 0) {
2110 if (kill(0, $pid)) {
2111 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2115 until ($count > 40) {
2116 if (Samba::cleanup_child($pid, "samba") != 0) {
2122 # If it is still around, kill it
2123 if (kill(0, $pid)) {
2124 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2130 sub teardown_env($$)
2132 my ($self, $envvars) = @_;
2133 teardown_env_terminate($self, $envvars);
2135 $self->slapd_stop($envvars) if ($self->{ldap});
2137 print $self->getlog_env($envvars);
2144 my ($self, $envvars) = @_;
2145 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2148 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2150 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2154 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2157 return "" if $out eq $title;
2164 my ($self, $envvars) = @_;
2165 my $samba_pid = $envvars->{SAMBA_PID};
2167 if (not defined($samba_pid)) {
2169 } elsif ($samba_pid > 0) {
2170 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2172 if ($childpid == 0) {
2181 # Declare the environments Samba4 makes available.
2182 # To be set up, they will be called as
2183 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2184 %Samba4::ENV_DEPS = (
2185 # name => [dep_1, dep_2, ...],
2189 ad_dc_no_ntlm => [],
2193 preforkrestartdc => [],
2195 fl2008r2dc => ["ad_dc"],
2196 fl2003dc => ["ad_dc"],
2199 vampire_2000_dc => ["fl2000dc"],
2200 vampire_dc => ["ad_dc_ntvfs"],
2201 promoted_dc => ["ad_dc_ntvfs"],
2202 subdom_dc => ["ad_dc_ntvfs"],
2204 rodc => ["ad_dc_ntvfs"],
2205 rpc_proxy => ["ad_dc_ntvfs"],
2208 s4member_dflt_domain => ["ad_dc_ntvfs"],
2209 s4member => ["ad_dc_ntvfs"],
2211 restoredc => ["backupfromdc"],
2212 renamedc => ["backupfromdc"],
2213 offlinebackupdc => ["backupfromdc"],
2214 labdc => ["backupfromdc"],
2221 my ($self, $path, $dc_vars) = @_;
2223 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2226 if (not defined($self->check_or_start($env, "standard"))) {
2234 sub setup_s4member_dflt_domain
2236 my ($self, $path, $dc_vars) = @_;
2238 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2239 "winbind use default domain = yes");
2242 if (not defined($self->check_or_start($env, "standard"))) {
2252 my ($self, $path, $dc_vars) = @_;
2254 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2257 if (not defined($self->check_or_start($env, "standard"))) {
2264 sub setup_ad_dc_ntvfs
2266 my ($self, $path) = @_;
2268 my $env = $self->provision_ad_dc_ntvfs($path);
2270 if (not defined($self->check_or_start($env, "standard"))) {
2271 warn("Failed to start ad_dc_ntvfs");
2280 my ($self, $path) = @_;
2282 my $env = $self->provision_chgdcpass($path);
2284 if (not defined($self->check_or_start($env, "standard"))) {
2293 my ($self, $path) = @_;
2295 my $env = $self->provision_fl2000dc($path);
2297 if (not defined($self->check_or_start($env, "standard"))) {
2307 my ($self, $path, $dc_vars) = @_;
2309 my $env = $self->provision_fl2003dc($path);
2312 if (not defined($self->check_or_start($env, "standard"))) {
2316 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2321 sub setup_fl2008r2dc
2323 my ($self, $path, $dc_vars) = @_;
2325 my $env = $self->provision_fl2008r2dc($path);
2328 if (not defined($self->check_or_start($env, "standard"))) {
2332 my $upn_array = ["$env->{REALM}.upn"];
2333 my $spn_array = ["$env->{REALM}.spn"];
2335 $self->setup_namespaces($env, $upn_array, $spn_array);
2337 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2343 sub setup_vampire_dc
2345 return setup_generic_vampire_dc(@_, "2008");
2348 sub setup_vampire_2000_dc
2350 return setup_generic_vampire_dc(@_, "2000");
2353 sub setup_generic_vampire_dc
2355 my ($self, $path, $dc_vars, $fl) = @_;
2357 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2360 if (not defined($self->check_or_start($env, "single"))) {
2364 # force replicated DC to update repsTo/repsFrom
2365 # for vampired partitions
2366 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2368 # as 'vampired' dc may add data in its local replica
2369 # we need to synchronize data between DCs
2370 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2371 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2372 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2373 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2374 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2376 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2378 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2379 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2380 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2381 $cmd .= " $dc_vars->{CONFIGURATION}";
2382 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2383 # replicate Configuration NC
2384 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2385 unless(system($cmd_repl) == 0) {
2386 warn("Failed to replicate\n$cmd_repl");
2389 # replicate Default NC
2390 $cmd_repl = "$cmd \"$base_dn\"";
2391 unless(system($cmd_repl) == 0) {
2392 warn("Failed to replicate\n$cmd_repl");
2396 # Pull in a full set of changes from the main DC
2397 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2398 $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2399 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2400 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2401 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2403 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2405 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2406 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2407 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2408 $cmd .= " $dc_vars->{CONFIGURATION}";
2409 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2410 # replicate Configuration NC
2411 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2412 unless(system($cmd_repl) == 0) {
2413 warn("Failed to replicate\n$cmd_repl");
2416 # replicate Default NC
2417 $cmd_repl = "$cmd \"$base_dn\"";
2418 unless(system($cmd_repl) == 0) {
2419 warn("Failed to replicate\n$cmd_repl");
2427 sub setup_promoted_dc
2429 my ($self, $path, $dc_vars) = @_;
2431 my $env = $self->provision_promoted_dc($path, $dc_vars);
2434 if (not defined($self->check_or_start($env, "single"))) {
2438 # force source and replicated DC to update repsTo/repsFrom
2439 # for vampired partitions
2440 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2441 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2442 # as 'vampired' dc may add data in its local replica
2443 # we need to synchronize data between DCs
2444 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2445 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2446 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2447 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2448 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2449 $cmd .= " $dc_vars->{CONFIGURATION}";
2450 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2451 # replicate Configuration NC
2452 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2453 unless(system($cmd_repl) == 0) {
2454 warn("Failed to replicate\n$cmd_repl");
2457 # replicate Default NC
2458 $cmd_repl = "$cmd \"$base_dn\"";
2459 unless(system($cmd_repl) == 0) {
2460 warn("Failed to replicate\n$cmd_repl");
2470 my ($self, $path, $dc_vars) = @_;
2472 my $env = $self->provision_subdom_dc($path, $dc_vars);
2475 if (not defined($self->check_or_start($env, "single"))) {
2479 # force replicated DC to update repsTo/repsFrom
2480 # for primary domain partitions
2481 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2482 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2483 # as 'subdomain' dc may add data in its local replica
2484 # we need to synchronize data between DCs
2485 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2486 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2487 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2488 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2489 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2490 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2491 $cmd .= " $dc_vars->{CONFIGURATION}";
2492 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2493 # replicate Configuration NC
2494 my $cmd_repl = "$cmd \"$config_dn\"";
2495 unless(system($cmd_repl) == 0) {
2496 warn("Failed to replicate\n$cmd_repl");
2499 # replicate Default NC
2500 $cmd_repl = "$cmd \"$base_dn\"";
2501 unless(system($cmd_repl) == 0) {
2502 warn("Failed to replicate\n$cmd_repl");
2512 my ($self, $path, $dc_vars) = @_;
2514 my $env = $self->provision_rodc($path, $dc_vars);
2520 if (not defined($self->check_or_start($env, "standard"))) {
2524 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2527 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2528 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2529 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2530 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2531 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2532 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2533 $cmd .= " $dc_vars->{CONFIGURATION}";
2534 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2535 # replicate Configuration NC
2536 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2537 unless(system($cmd_repl) == 0) {
2538 warn("Failed to replicate\n$cmd_repl");
2541 # replicate Default NC
2542 $cmd_repl = "$cmd \"$base_dn\"";
2543 unless(system($cmd_repl) == 0) {
2544 warn("Failed to replicate\n$cmd_repl");
2553 my ($self, $path) = @_;
2555 # If we didn't build with ADS, pretend this env was never available
2556 if (not $self->{target3}->have_ads()) {
2560 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2561 "addom.samba.example.com", "", undef);
2566 if (not defined($self->check_or_start($env, "prefork"))) {
2570 my $upn_array = ["$env->{REALM}.upn"];
2571 my $spn_array = ["$env->{REALM}.spn"];
2573 $self->setup_namespaces($env, $upn_array, $spn_array);
2578 sub setup_ad_dc_no_nss
2580 my ($self, $path) = @_;
2582 # If we didn't build with ADS, pretend this env was never available
2583 if (not $self->{target3}->have_ads()) {
2587 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2588 "adnonssdom.samba.example.com", "", undef);
2593 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2594 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2596 if (not defined($self->check_or_start($env, "single"))) {
2600 my $upn_array = ["$env->{REALM}.upn"];
2601 my $spn_array = ["$env->{REALM}.spn"];
2603 $self->setup_namespaces($env, $upn_array, $spn_array);
2608 sub setup_ad_dc_no_ntlm
2610 my ($self, $path) = @_;
2612 # If we didn't build with ADS, pretend this env was never available
2613 if (not $self->{target3}->have_ads()) {
2617 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2618 "adnontlmdom.samba.example.com",
2619 "ntlm auth = disabled", undef);
2624 if (not defined($self->check_or_start($env, "prefork"))) {
2628 my $upn_array = ["$env->{REALM}.upn"];
2629 my $spn_array = ["$env->{REALM}.spn"];
2631 $self->setup_namespaces($env, $upn_array, $spn_array);
2637 # AD DC test environment used solely to test pre-fork process restarts.
2638 # As processes get killed off and restarted it should not be used for other
2639 sub setup_preforkrestartdc
2641 my ($self, $path) = @_;
2643 # If we didn't build with ADS, pretend this env was never available
2644 if (not $self->{target3}->have_ads()) {
2648 # note DC name must be <= 15 chars so we use 'prockill' instead of
2650 my $env = $self->provision_ad_dc(
2654 "prockilldom.samba.example.com",
2655 "prefork backoff increment = 5\nprefork maximum backoff=10");
2660 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2661 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2663 if (not defined($self->check_or_start($env, "prefork"))) {
2667 my $upn_array = ["$env->{REALM}.upn"];
2668 my $spn_array = ["$env->{REALM}.spn"];
2670 $self->setup_namespaces($env, $upn_array, $spn_array);
2675 # Sets up a DC that's solely used to do a domain backup from. We then use the
2676 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2677 # process will create a Samba DC that will actually start up.
2678 # We don't use the backup-DC for anything else because its domain will conflict
2679 # with the restore DC.
2680 sub setup_backupfromdc
2682 my ($self, $path) = @_;
2684 # If we didn't build with ADS, pretend this env was never available
2685 if (not $self->{target3}->have_ads()) {
2689 my $provision_args = ["--site=Backup-Site"];
2691 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2692 "backupdom.samba.example.com", "",
2698 if (not defined($self->check_or_start($env, "standard"))) {
2702 my $upn_array = ["$env->{REALM}.upn"];
2703 my $spn_array = ["$env->{REALM}.spn"];
2705 $self->setup_namespaces($env, $upn_array, $spn_array);
2710 # returns the server/user-auth params needed to run an online backup cmd
2711 sub get_backup_server_args
2713 # dcvars contains the env info for the backup DC testenv
2714 my ($self, $dcvars) = @_;
2715 my $server = $dcvars->{DC_SERVER_IP};
2716 my $server_args = "--server=$server ";
2717 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2718 $server_args .= " $dcvars->{CONFIGURATION}";
2720 return $server_args;
2723 # Creates a backup of a running testenv DC
2726 # note: dcvars contains the env info for the backup DC testenv
2727 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2729 # get all the env variables we pass in with the samba-tool command
2730 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2731 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2732 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2733 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2735 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2737 # Note: use the backupfrom-DC's krb5.conf to do the backup
2738 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2739 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2741 # use samba-tool to create a backup from the 'backupfromdc' DC
2743 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2745 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2746 $cmd .= " --targetdir=$backupdir";
2748 print "Executing: $cmd\n";
2749 unless(system($cmd) == 0) {
2750 warn("Failed to create backup using: \n$cmd");
2754 # get the name of the backup file created
2755 opendir(DIR, $backupdir);
2756 my @files = grep(/\.tar/, readdir(DIR));
2759 if(scalar @files != 1) {
2760 warn("Backup file not found in directory $backupdir\n");
2763 my $backup_file = "$backupdir/$files[0]";
2764 print "Using backup file $backup_file...\n";
2766 return $backup_file;
2769 # Restores a backup-file to populate a testenv for a new DC
2770 sub restore_backup_file
2772 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2774 # pass the restore command the testenv's smb.conf that we've already
2775 # generated. But move it to a temp-dir first, so that the restore doesn't
2777 my $tmpdir = File::Temp->newdir();
2778 my $tmpconf = "$tmpdir/smb.conf";
2779 my $cmd = "cp $smbconf $tmpconf";
2780 unless(system($cmd) == 0) {
2781 warn("Failed to backup smb.conf using: \n$cmd");
2785 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2786 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2787 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2789 print "Executing: $cmd\n";
2790 unless(system($cmd) == 0) {
2791 warn("Failed to restore backup using: \n$cmd");
2795 print "Restore complete\n";
2799 # sets up the initial directory and returns the new testenv's env info
2800 # (without actually doing a 'domain join')
2801 sub prepare_dc_testenv
2803 my ($self, $prefix, $dcname, $domain, $realm, $password) = @_;
2805 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2815 # the restore uses a slightly different state-dir location to other testenvs
2816 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2817 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2819 # add support for sysvol/netlogon/tmp shares
2820 $ctx->{share} = "$ctx->{prefix_abs}/share";
2821 push(@{$ctx->{directories}}, "$ctx->{share}");
2823 $ctx->{smb_conf_extra_options} = "
2825 server max protocol = SMB2
2828 path = $ctx->{statedir}/sysvol
2832 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2836 path = $ctx->{share}
2838 posix:sharedelay = 10000
2839 posix:oplocktimeout = 3
2840 posix:writetimeupdatedelay = 50000
2844 my $env = $self->provision_raw_step1($ctx);
2846 $env->{DC_SERVER} = $env->{SERVER};
2847 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
2848 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
2849 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
2850 $env->{DC_USERNAME} = $env->{USERNAME};
2851 $env->{DC_PASSWORD} = $env->{PASSWORD};
2853 return ($env, $ctx);
2857 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2858 # commands. This proves that we can backup an online DC ('backupfromdc') and
2859 # use the backup file to create a valid, working samba DC.
2862 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2863 my ($self, $prefix, $dcvars) = @_;
2864 print "Preparing RESTORE DC...\n";
2866 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2869 $dcvars->{PASSWORD});
2871 # create a backup of the 'backupfromdc'
2872 my $backupdir = File::Temp->newdir();
2873 my $server_args = $self->get_backup_server_args($dcvars);
2874 my $backup_args = "online $server_args";
2875 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2877 unless($backup_file) {
2881 # restore the backup file to populate the restore-DC testenv
2882 my $restore_dir = abs_path($prefix);
2883 my $ret = $self->restore_backup_file($backup_file,
2884 "--newservername=$env->{SERVER}",
2885 $restore_dir, $env->{SERVERCONFFILE});
2886 unless ($ret == 0) {
2890 # start samba for the restored DC
2891 if (not defined($self->check_or_start($env, "standard"))) {
2898 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2899 # restore commands. This proves that we can backup and rename an online DC
2900 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2903 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2904 my ($self, $prefix, $dcvars) = @_;
2905 print "Preparing RENAME DC...\n";
2907 my $realm = "renamedom.samba.example.com";
2908 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
2909 "RENAMEDOMAIN", $realm,
2910 $dcvars->{PASSWORD});
2912 # create a backup of the 'backupfromdc' which renames the domain
2913 my $backupdir = File::Temp->newdir();
2914 my $server_args = $self->get_backup_server_args($dcvars);
2915 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2916 $backup_args .= " --backend-store=tdb";
2917 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2919 unless($backup_file) {
2923 # restore the backup file to populate the rename-DC testenv
2924 my $restore_dir = abs_path($prefix);
2925 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2926 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2927 $restore_dir, $env->{SERVERCONFFILE});
2928 unless ($ret == 0) {
2932 # start samba for the restored DC
2933 if (not defined($self->check_or_start($env, "standard"))) {
2937 my $upn_array = ["$env->{REALM}.upn"];
2938 my $spn_array = ["$env->{REALM}.spn"];
2940 $self->setup_namespaces($env, $upn_array, $spn_array);
2945 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
2946 # restore commands. This proves that we do an offline backup of a local DC
2947 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2948 sub setup_offlinebackupdc
2950 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2951 my ($self, $prefix, $dcvars) = @_;
2952 print "Preparing OFFLINE BACKUP DC...\n";
2954 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
2957 $dcvars->{PASSWORD});
2959 # create an offline backup of the 'backupfromdc' target
2960 my $backupdir = File::Temp->newdir();
2961 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
2962 my $backup_file = $self->create_backup($env, $dcvars,
2965 unless($backup_file) {
2969 # restore the backup file to populate the rename-DC testenv
2970 my $restore_dir = abs_path($prefix);
2971 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2972 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2973 $restore_dir, $env->{SERVERCONFFILE});
2974 unless ($ret == 0) {
2978 # re-create the testenv's krb5.conf (the restore may have overwritten it)
2979 Samba::mk_krb5_conf($ctx);
2981 # start samba for the restored DC
2982 if (not defined($self->check_or_start($env, "standard"))) {
2989 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
2990 # restore commands, using the --no-secrets option. This proves that we can
2991 # create a realistic lab environment from an online DC ('backupfromdc').
2994 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2995 my ($self, $prefix, $dcvars) = @_;
2996 print "Preparing LAB-DOMAIN DC...\n";
2998 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3000 "labdom.samba.example.com",
3001 $dcvars->{PASSWORD});
3003 # create a backup of the 'backupfromdc' which renames the domain and uses
3004 # the --no-secrets option to scrub any sensitive info
3005 my $backupdir = File::Temp->newdir();
3006 my $server_args = $self->get_backup_server_args($dcvars);
3007 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3008 $backup_args .= " --no-secrets --backend-store=mdb";
3009 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3011 unless($backup_file) {
3015 # restore the backup file to populate the lab-DC testenv
3016 my $restore_dir = abs_path($prefix);
3017 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3018 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3019 $restore_dir, $env->{SERVERCONFFILE});
3020 unless ($ret == 0) {
3024 # because we don't include any secrets in the backup, we need to reset the
3025 # admin user's password back to what the testenv expects
3026 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3027 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3028 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3029 $cmd .= " $env->{CONFIGURATION}";
3031 unless(system($cmd) == 0) {
3032 warn("Failed to reset admin's password: \n$cmd");
3036 # start samba for the restored DC
3037 if (not defined($self->check_or_start($env, "standard"))) {
3041 my $upn_array = ["$env->{REALM}.upn"];
3042 my $spn_array = ["$env->{REALM}.spn"];
3044 $self->setup_namespaces($env, $upn_array, $spn_array);
3049 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3050 sub get_backup_domain_realm
3052 my ($self, $backup_file) = @_;
3054 print "Determining REALM/DOMAIN values in backup...\n";
3056 # The backup will have the correct domain/realm values in the smb.conf.
3057 # So we can work out the env variables the testenv should use based on
3058 # that. Let's start by extracting the smb.conf
3059 my $tar = Archive::Tar->new($backup_file);
3060 my $tmpdir = File::Temp->newdir();
3061 my $smbconf = "$tmpdir/smb.conf";
3063 # note that the filepaths within the tar-file differ slightly for online
3064 # and offline backups
3065 if ($tar->contains_file("etc/smb.conf")) {
3066 $tar->extract_file("etc/smb.conf", $smbconf);
3067 } elsif ($tar->contains_file("./etc/smb.conf")) {
3068 $tar->extract_file("./etc/smb.conf", $smbconf);
3070 warn("Could not find smb.conf in $backup_file");
3071 return undef, undef;
3074 # now use testparm to read the values we're interested in
3075 my $testparm = Samba::bindir_path($self, "testparm");
3076 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3077 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3080 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3082 return ($domain, $realm);
3085 # This spins up a custom testenv that can be based on any backup-file you want.
3086 # This is just intended for manual testing (rather than automated test-cases)
3089 my ($self, $prefix) = @_;
3090 print "Preparing CUSTOM RESTORE DC...\n";
3091 my $dc_name = "customdc";
3092 my $password = "locDCpass1";
3093 my $backup_file = $ENV{'BACKUP_FILE'};
3095 # user must specify a backup file to restore via an ENV variable, i.e.
3096 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3097 if (not defined($backup_file)) {
3098 warn("Please specify BACKUP_FILE");
3102 # work out the correct domain/realm env values from the backup-file
3103 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3105 # create a placeholder directory and smb.conf, as well as the env vars.
3106 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3107 $domain, $realm, $password);
3109 # restore the specified backup file to populate the testenv
3110 my $restore_dir = abs_path($prefix);
3111 my $ret = $self->restore_backup_file($backup_file,
3112 "--newservername=$env->{SERVER}",
3113 $restore_dir, $env->{SERVERCONFFILE});
3114 unless ($ret == 0) {
3118 # Change the admin password to the testenv default, just in case it's
3119 # different, or in case this was a --no-secrets backup
3120 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3121 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3122 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3123 $cmd .= " $env->{CONFIGURATION}";
3125 unless(system($cmd) == 0) {
3126 warn("Failed to reset admin's password: \n$cmd");
3130 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3131 # if the backup-file was an offline backup)
3132 Samba::mk_krb5_conf($ctx);
3134 # start samba for the restored DC
3135 if (not defined($self->check_or_start($env, "standard"))) {
3139 # if this was a backup-rename, then we may need to setup namespaces
3140 my $upn_array = ["$env->{REALM}.upn"];
3141 my $spn_array = ["$env->{REALM}.spn"];
3143 $self->setup_namespaces($env, $upn_array, $spn_array);
3150 my ($self, $path) = @_;
3153 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",