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;
597 my ($self, $keyword, @options_list) = @_;
599 # convert the options-list to a hash-map for easy keyword lookup
600 my %options_dict = map { $_ => 1 } @options_list;
602 return exists $options_dict{$keyword};
606 # Step1 creates the basic configuration
608 sub provision_raw_step1($$)
610 my ($self, $ctx) = @_;
612 mkdir($_, 0777) foreach (@{$ctx->{directories}});
615 ## lockdir and piddir must be 0755
617 chmod 0755, $ctx->{lockdir};
618 chmod 0755, $ctx->{piddir};
620 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
621 warn("can't open $ctx->{smb_conf}$?");
625 Samba::prepare_keyblobs($ctx);
626 my $crlfile = "$ctx->{tlsdir}/crl.pem";
627 $crlfile = "" unless -e ${crlfile};
629 # work out which file server to use. Default to source3 smbd (s3fs),
630 # unless the source4 NTVFS (smb) file server has been specified
631 my $services = "-smb +s3fs";
632 if ($self->has_option("--use-ntvfs", @{$ctx->{provision_options}})) {
633 $services = "+smb -s3fs";
638 netbios name = $ctx->{netbiosname}
639 posix:eadb = $ctx->{statedir}/eadb.tdb
640 workgroup = $ctx->{domain}
641 realm = $ctx->{realm}
642 private dir = $ctx->{privatedir}
643 binddns dir = $ctx->{binddnsdir}
644 pid directory = $ctx->{piddir}
645 ncalrpc dir = $ctx->{ncalrpcdir}
646 lock dir = $ctx->{lockdir}
647 state directory = $ctx->{statedir}
648 cache directory = $ctx->{cachedir}
649 winbindd socket directory = $ctx->{winbindd_socket_dir}
650 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
651 winbind separator = /
652 interfaces = $ctx->{interfaces}
653 tls dh params file = $ctx->{tlsdir}/dhparms.pem
654 tls crlfile = ${crlfile}
655 tls verify peer = no_check
656 panic action = $RealBin/gdb_backtrace \%d
658 server role = $ctx->{server_role}
659 server services = +echo $services
660 dcerpc endpoint servers = +winreg +srvsvc
661 notify:inotify = false
663 ldap server require strong auth = yes
664 #We don't want to pass our self-tests if the PAC code is wrong
665 gensec:require_pac = true
666 log file = $ctx->{logdir}/log.\%m
667 log level = $ctx->{server_loglevel}
671 dns update command = $ctx->{samba_dnsupdate}
672 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
673 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
674 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
675 dreplsrv:periodic_startup_interval = 0
676 dsdb:schema update allowed = yes
680 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
682 idmap_ldb:use rfc2307=yes
683 winbind enum users = yes
684 winbind enum groups = yes
686 rpc server port:netlogon = 1026
692 # Begin extra options
693 $ctx->{smb_conf_extra_options}
698 #Default the KDC IP to the server's IP
699 if (not defined($ctx->{kdc_ipv4})) {
700 $ctx->{kdc_ipv4} = $ctx->{ipv4};
702 if (not defined($ctx->{kdc_ipv6})) {
703 $ctx->{kdc_ipv6} = $ctx->{ipv6};
706 Samba::mk_krb5_conf($ctx);
707 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
709 open(PWD, ">$ctx->{nsswrap_passwd}");
710 if ($ctx->{unix_uid} != 0) {
711 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
713 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
714 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
715 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
716 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
717 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
718 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
721 my $uid_rfc2307test = 65533;
723 open(GRP, ">$ctx->{nsswrap_group}");
724 if ($ctx->{unix_gid} != 0) {
725 print GRP "root:x:0:\n";
727 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
728 print GRP "wheel:x:10:
731 nogroup:x:65534:nobody
734 my $gid_rfc2307test = 65532;
736 my $hostname = lc($ctx->{hostname});
737 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
738 if ($hostname eq "localdc") {
739 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
740 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
742 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
743 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
747 if (defined($ctx->{resolv_conf})) {
748 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
749 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
750 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
754 my $configuration = "--configfile=$ctx->{smb_conf}";
756 #Ensure the config file is valid before we start
757 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
758 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
759 system("$testparm -v --suppress-prompt $configuration >&2");
760 warn("Failed to create a valid smb.conf configuration $testparm!");
763 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) {
764 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
769 KRB5_CONFIG => $ctx->{krb5_conf},
770 KRB5_CCACHE => $ctx->{krb5_ccache},
771 MITKDC_CONFIG => $ctx->{mitkdc_conf},
772 PIDDIR => $ctx->{piddir},
773 SERVER => $ctx->{hostname},
774 SERVER_IP => $ctx->{ipv4},
775 SERVER_IPV6 => $ctx->{ipv6},
776 NETBIOSNAME => $ctx->{netbiosname},
777 DOMAIN => $ctx->{domain},
778 USERNAME => $ctx->{username},
779 REALM => $ctx->{realm},
780 DNSNAME => $ctx->{dnsname},
781 SAMSID => $ctx->{samsid},
782 PASSWORD => $ctx->{password},
783 LDAPDIR => $ctx->{ldapdir},
784 LDAP_INSTANCE => $ctx->{ldap_instance},
785 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
786 NCALRPCDIR => $ctx->{ncalrpcdir},
787 LOCKDIR => $ctx->{lockdir},
788 STATEDIR => $ctx->{statedir},
789 CACHEDIR => $ctx->{cachedir},
790 PRIVATEDIR => $ctx->{privatedir},
791 BINDDNSDIR => $ctx->{binddnsdir},
792 SERVERCONFFILE => $ctx->{smb_conf},
793 CONFIGURATION => $configuration,
794 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
795 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
796 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
797 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
798 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
799 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
800 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
801 SAMBA_TEST_LOG_POS => 0,
802 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
803 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
804 LOCAL_PATH => $ctx->{share},
805 UID_RFC2307TEST => $uid_rfc2307test,
806 GID_RFC2307TEST => $gid_rfc2307test,
807 SERVER_ROLE => $ctx->{server_role},
808 RESOLV_CONF => $ctx->{resolv_conf}
811 if (defined($ctx->{use_resolv_wrapper})) {
812 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
814 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
817 if ($ctx->{server_role} eq "domain controller") {
818 $ret->{DOMSID} = $ret->{SAMSID};
825 # Step2 runs the provision script
827 sub provision_raw_step2($$$)
829 my ($self, $ctx, $ret) = @_;
831 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
832 unless (system($provision_cmd) == 0) {
833 warn("Unable to provision: \n$provision_cmd\n");
837 my $testallowed_account = "testallowed";
838 my $samba_tool_cmd = "";
839 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
840 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
841 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
842 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
843 unless (system($samba_tool_cmd) == 0) {
844 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
849 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
850 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
851 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
852 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
854 if ($ctx->{server_role} ne "domain controller") {
855 $base_dn = "DC=$ctx->{netbiosname}";
858 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
859 $testallowed_account = "testallowed account";
860 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
861 print LDIF "dn: $user_dn
863 replace: samAccountName
864 samAccountName: $testallowed_account
869 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
870 print LDIF "dn: $user_dn
872 replace: userPrincipalName
873 userPrincipalName: testallowed upn\@$ctx->{realm}
874 replace: servicePrincipalName
875 servicePrincipalName: host/testallowed
880 $samba_tool_cmd = "";
881 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
882 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
883 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
884 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
885 unless (system($samba_tool_cmd) == 0) {
886 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
890 my $user_dn = "cn=testdenied,cn=users,$base_dn";
891 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
892 print LDIF "dn: $user_dn
894 replace: userPrincipalName
895 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
900 $samba_tool_cmd = "";
901 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
902 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
903 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
904 . " user create --configfile=$ctx->{smb_conf} testupnspn $ctx->{password}";
905 unless (system($samba_tool_cmd) == 0) {
906 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
910 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
911 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
912 print LDIF "dn: $user_dn
914 replace: userPrincipalName
915 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
916 replace: servicePrincipalName
917 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
922 $samba_tool_cmd = "";
923 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
924 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
925 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
926 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
927 unless (system($samba_tool_cmd) == 0) {
928 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
932 # Create to users alice and bob!
933 my $user_account_array = ["alice", "bob", "jane"];
935 foreach my $user_account (@{$user_account_array}) {
936 my $samba_tool_cmd = "";
938 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
939 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
940 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
941 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
942 unless (system($samba_tool_cmd) == 0) {
943 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
949 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
950 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
951 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
953 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
954 my $user_dn = "cn=jane,cn=users,$base_dn";
956 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
957 print LDIF "dn: $user_dn
959 replace: userPrincipalName
960 userPrincipalName: jane.doe\@$ctx->{realm}
968 sub provision($$$$$$$$$$)
970 my ($self, $prefix, $server_role, $hostname,
971 $domain, $realm, $functional_level,
972 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
973 $extra_provision_options) = @_;
975 my $samsid = Samba::random_domain_sid();
977 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
982 $password, $kdc_ipv4, $kdc_ipv6);
984 if (defined($extra_provision_options)) {
985 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
988 $ctx->{share} = "$ctx->{prefix_abs}/share";
989 push(@{$ctx->{directories}}, "$ctx->{share}");
990 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
991 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
993 # precreate directories for printer drivers
994 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
995 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
996 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
999 $msdfs = "yes" if ($server_role eq "domain controller");
1000 $ctx->{smb_conf_extra_options} = "
1003 server max protocol = SMB2
1007 # fruit:copyfile is a global option
1008 fruit:copyfile = yes
1010 $extra_smbconf_options
1013 path = $ctx->{share}
1015 posix:sharedelay = 100000
1016 posix:oplocktimeout = 3
1017 posix:writetimeupdatedelay = 500000
1020 path = $ctx->{share}
1022 posix:sharedelay = 100000
1023 posix:oplocktimeout = 3
1024 posix:writetimeupdatedelay = 500000
1026 force create mode = 777
1029 path = $ctx->{share}
1032 force create mode = 0
1033 directory mask = 0777
1034 force directory mode = 0
1037 path = $ctx->{share}/test1
1039 posix:sharedelay = 100000
1040 posix:oplocktimeout = 3
1041 posix:writetimeupdatedelay = 500000
1044 path = $ctx->{share}/test2
1046 posix:sharedelay = 100000
1047 posix:oplocktimeout = 3
1048 posix:writetimeupdatedelay = 500000
1051 path = $ctx->{share}/_ignore_cifs_
1053 ntvfs handler = cifs
1054 cifs:server = $ctx->{netbiosname}
1056 cifs:use-s4u2proxy = yes
1057 # There is no username specified here, instead the client is expected
1058 # to log in with kerberos, and the serverwill use delegated credentials.
1059 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1062 path = $ctx->{share}
1064 ntvfs handler = simple
1067 path = $ctx->{statedir}/sysvol
1071 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1076 ntvfs handler = cifsposix
1079 path = $ctx->{share}
1080 vfs objects = catia fruit streams_xattr acl_xattr
1082 fruit:resource = file
1083 fruit:metadata = netatalk
1084 fruit:locking = netatalk
1085 fruit:encoding = native
1087 $extra_smbconf_shares
1090 if (defined($self->{ldap})) {
1091 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1092 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1094 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1095 $ldap_uri =~ s|/|%2F|g;
1096 $ldap_uri = "ldapi://$ldap_uri";
1097 $ctx->{ldap_uri} = $ldap_uri;
1099 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1102 my $ret = $self->provision_raw_step1($ctx);
1103 unless (defined $ret) {
1107 if (defined($self->{ldap})) {
1108 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1109 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1110 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1111 if ($self->{ldap} eq "openldap") {
1112 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1113 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1115 } elsif ($self->{ldap} eq "fedora-ds") {
1116 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1117 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1118 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1123 return $self->provision_raw_step2($ctx, $ret);
1126 sub provision_s4member($$$$$)
1128 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1129 print "PROVISIONING MEMBER...\n";
1130 my $extra_smb_conf = "
1131 passdb backend = samba_dsdb
1132 winbindd:use external pipes = true
1134 # the source4 smb server doesn't allow signing by default
1135 server signing = enabled
1136 raw NTLMv2 auth = yes
1138 rpc_server:default = external
1139 rpc_server:svcctl = embedded
1140 rpc_server:srvsvc = embedded
1141 rpc_server:eventlog = embedded
1142 rpc_server:ntsvcs = embedded
1143 rpc_server:winreg = embedded
1144 rpc_server:spoolss = embedded
1145 rpc_daemon:spoolssd = embedded
1146 rpc_server:tcpip = no
1149 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1151 my $extra_provision_options = ["--use-ntvfs"];
1152 my $ret = $self->provision($prefix,
1159 $dcvars->{SERVER_IP},
1160 $dcvars->{SERVER_IPV6},
1161 $extra_smb_conf, "",
1162 $extra_provision_options);
1167 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1168 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1169 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1170 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1171 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1173 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1175 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1176 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1177 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1178 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1179 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1181 unless (system($cmd) == 0) {
1182 warn("Join failed\n$cmd");
1186 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1187 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1188 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1189 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1190 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1191 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1193 $ret->{DOMSID} = $dcvars->{DOMSID};
1194 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1195 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1196 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1197 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1198 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1199 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1204 sub provision_rpc_proxy($$$)
1206 my ($self, $prefix, $dcvars) = @_;
1207 print "PROVISIONING RPC PROXY...\n";
1209 my $extra_smbconf_options = "
1210 passdb backend = samba_dsdb
1213 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1214 dcerpc endpoint servers = epmapper, remote
1215 dcerpc_remote:interfaces = rpcecho
1218 path = /tmp/_ignore_cifs_to_dc_/_none_
1220 ntvfs handler = cifs
1221 cifs:server = $dcvars->{SERVER}
1223 cifs:use-s4u2proxy = yes
1224 # There is no username specified here, instead the client is expected
1225 # to log in with kerberos, and the serverwill use delegated credentials.
1226 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1230 my $extra_provision_options = ["--use-ntvfs"];
1231 my $ret = $self->provision($prefix,
1238 $dcvars->{SERVER_IP},
1239 $dcvars->{SERVER_IPV6},
1240 $extra_smbconf_options, "",
1241 $extra_provision_options);
1246 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1248 # The joind runs in the context of the rpc_proxy/member for now
1249 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1250 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1251 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1252 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1254 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1256 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1257 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1258 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1259 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1260 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1262 unless (system($cmd) == 0) {
1263 warn("Join failed\n$cmd");
1267 # Setting up delegation runs in the context of the DC for now
1269 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1270 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1271 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1272 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1273 $cmd .= " $dcvars->{CONFIGURATION}";
1276 unless (system($cmd) == 0) {
1277 warn("Delegation failed\n$cmd");
1281 # Setting up delegation runs in the context of the DC for now
1283 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1284 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1285 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1286 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1287 $cmd .= " $dcvars->{CONFIGURATION}";
1289 unless (system($cmd) == 0) {
1290 warn("Delegation failed\n$cmd");
1294 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1295 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1296 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1297 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1298 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1299 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1301 $ret->{DOMSID} = $dcvars->{DOMSID};
1302 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1303 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1304 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1305 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1306 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1307 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1312 sub provision_promoted_dc($$$)
1314 my ($self, $prefix, $dcvars) = @_;
1315 print "PROVISIONING PROMOTED DC...\n";
1317 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1318 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1324 $dcvars->{PASSWORD},
1325 $dcvars->{SERVER_IP},
1326 $dcvars->{SERVER_IPV6});
1328 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1330 $ctx->{smb_conf_extra_options} = "
1332 server max protocol = SMB2
1334 ntlm auth = ntlmv2-only
1337 path = $ctx->{statedir}/sysvol
1341 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1346 my $ret = $self->provision_raw_step1($ctx);
1351 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1352 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1353 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1354 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1355 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1357 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1359 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1360 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1361 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1362 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1363 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1365 unless (system($cmd) == 0) {
1366 warn("Join failed\n$cmd");
1370 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1371 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1372 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1373 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1374 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1376 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1378 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1379 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1380 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1381 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1382 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1384 unless (system($cmd) == 0) {
1385 warn("Join failed\n$cmd");
1389 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1390 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1391 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1392 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1394 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1395 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1396 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1397 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1398 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1399 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1404 sub provision_vampire_dc($$$)
1406 my ($self, $prefix, $dcvars, $fl) = @_;
1407 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1408 my $name = "localvampiredc";
1409 my $extra_conf = "";
1411 if ($fl == "2000") {
1412 $name = "vampire2000dc";
1414 $extra_conf = "drs: immediate link sync = yes
1415 drs: max link sync = 250";
1418 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1419 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1425 $dcvars->{PASSWORD},
1426 $dcvars->{SERVER_IP},
1427 $dcvars->{SERVER_IPV6});
1429 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1431 $ctx->{smb_conf_extra_options} = "
1433 server max protocol = SMB2
1435 ntlm auth = mschapv2-and-ntlmv2-only
1439 path = $ctx->{statedir}/sysvol
1443 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1448 my $ret = $self->provision_raw_step1($ctx);
1453 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1454 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1455 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1456 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1457 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1459 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1461 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1462 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1463 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1464 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1465 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1466 $cmd .= " --backend-store=mdb";
1468 unless (system($cmd) == 0) {
1469 warn("Join failed\n$cmd");
1473 if ($fl == "2000") {
1474 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1475 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1476 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1477 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1479 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1480 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1481 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1482 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1484 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1485 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1486 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1487 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1488 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1489 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1490 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1495 sub provision_subdom_dc($$$)
1497 my ($self, $prefix, $dcvars) = @_;
1498 print "PROVISIONING SUBDOMAIN DC...\n";
1500 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1501 my $samsid = undef; # TODO pass the domain sid all the way down
1502 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1505 "sub.samba.example.com",
1508 $dcvars->{PASSWORD},
1511 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1513 $ctx->{smb_conf_extra_options} = "
1515 server max protocol = SMB2
1518 path = $ctx->{statedir}/sysvol
1522 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1527 my $ret = $self->provision_raw_step1($ctx);
1532 Samba::mk_krb5_conf($ctx);
1533 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1535 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1536 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1537 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1538 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1539 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1541 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1543 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1544 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1545 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1546 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1547 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1548 $cmd .= " --adminpass=$ret->{PASSWORD}";
1550 unless (system($cmd) == 0) {
1551 warn("Join failed\n$cmd");
1555 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1556 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1557 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1558 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1560 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1561 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1562 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1563 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1564 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1565 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1570 sub provision_ad_dc_ntvfs($$)
1572 my ($self, $prefix) = @_;
1574 # We keep the old 'winbind' name here in server services to
1575 # ensure upgrades which used that name still work with the now
1578 print "PROVISIONING AD DC (NTVFS)...\n";
1579 my $extra_conf_options = "netbios aliases = localDC1-a
1580 server services = +winbind -winbindd
1581 ldap server require strong auth = allow_sasl_over_tls
1582 allow nt4 crypto = yes
1583 raw NTLMv2 auth = yes
1584 lsa over netlogon = yes
1585 rpc server port = 1027
1586 auth event notification = true
1587 dsdb event notification = true
1588 dsdb password event notification = true
1589 dsdb group change notification = true
1590 server schannel = auto
1592 my $extra_provision_options = ["--use-ntvfs"];
1593 my $ret = $self->provision($prefix,
1594 "domain controller",
1597 "samba.example.com",
1602 $extra_conf_options,
1604 $extra_provision_options);
1609 unless($self->add_wins_config("$prefix/private")) {
1610 warn("Unable to add wins configuration");
1613 $ret->{NETBIOSALIAS} = "localdc1-a";
1614 $ret->{DC_SERVER} = $ret->{SERVER};
1615 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1616 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1617 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1618 $ret->{DC_USERNAME} = $ret->{USERNAME};
1619 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1620 $ret->{DC_REALM} = $ret->{REALM};
1625 sub provision_fl2000dc($$)
1627 my ($self, $prefix) = @_;
1629 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1630 my $extra_conf_options = "
1631 spnego:simulate_w2k=yes
1632 ntlmssp_server:force_old_spnego=yes
1634 my $extra_provision_options = ["--use-ntvfs"];
1635 # This environment uses plain text secrets
1636 # i.e. secret attributes are not encrypted on disk.
1637 # This allows testing of the --plaintext-secrets option for
1639 push (@{$extra_provision_options}, "--plaintext-secrets");
1640 my $ret = $self->provision($prefix,
1641 "domain controller",
1644 "samba2000.example.com",
1649 $extra_conf_options,
1651 $extra_provision_options);
1656 unless($self->add_wins_config("$prefix/private")) {
1657 warn("Unable to add wins configuration");
1660 $ret->{DC_SERVER} = $ret->{SERVER};
1661 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1662 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1663 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1664 $ret->{DC_USERNAME} = $ret->{USERNAME};
1665 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1666 $ret->{DC_REALM} = $ret->{REALM};
1671 sub provision_fl2003dc($$$)
1673 my ($self, $prefix, $dcvars) = @_;
1674 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1675 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1677 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1678 my $extra_conf_options = "allow dns updates = nonsecure and secure
1679 dcesrv:header signing = no
1680 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1681 my $extra_provision_options = ["--use-ntvfs"];
1682 my $ret = $self->provision($prefix,
1683 "domain controller",
1686 "samba2003.example.com",
1691 $extra_conf_options,
1693 $extra_provision_options);
1694 unless (defined $ret) {
1698 $ret->{DC_SERVER} = $ret->{SERVER};
1699 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1700 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1701 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1702 $ret->{DC_USERNAME} = $ret->{USERNAME};
1703 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1704 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1705 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1707 my @samba_tool_options;
1708 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1709 push (@samba_tool_options, "domain");
1710 push (@samba_tool_options, "passwordsettings");
1711 push (@samba_tool_options, "set");
1712 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1713 push (@samba_tool_options, "--min-pwd-age=0");
1714 push (@samba_tool_options, "--history-length=1");
1716 my $samba_tool_cmd = join(" ", @samba_tool_options);
1718 unless (system($samba_tool_cmd) == 0) {
1719 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1723 unless($self->add_wins_config("$prefix/private")) {
1724 warn("Unable to add wins configuration");
1731 sub provision_fl2008r2dc($$$)
1733 my ($self, $prefix, $dcvars) = @_;
1735 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1736 my $extra_conf_options = "ldap server require strong auth = no";
1737 my $extra_provision_options = ["--use-ntvfs"];
1738 my $ret = $self->provision($prefix,
1739 "domain controller",
1742 "samba2008R2.example.com",
1747 $extra_conf_options,
1749 $extra_provision_options);
1750 unless (defined $ret) {
1754 unless ($self->add_wins_config("$prefix/private")) {
1755 warn("Unable to add wins configuration");
1758 $ret->{DC_SERVER} = $ret->{SERVER};
1759 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1760 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1761 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1762 $ret->{DC_USERNAME} = $ret->{USERNAME};
1763 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1764 $ret->{DC_REALM} = $ret->{REALM};
1770 sub provision_rodc($$$)
1772 my ($self, $prefix, $dcvars) = @_;
1773 print "PROVISIONING RODC...\n";
1775 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1776 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1782 $dcvars->{PASSWORD},
1783 $dcvars->{SERVER_IP},
1784 $dcvars->{SERVER_IPV6});
1789 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1791 $ctx->{share} = "$ctx->{prefix_abs}/share";
1792 push(@{$ctx->{directories}}, "$ctx->{share}");
1794 $ctx->{smb_conf_extra_options} = "
1796 server max protocol = SMB2
1797 password server = $dcvars->{DC_SERVER}
1800 path = $ctx->{statedir}/sysvol
1804 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1808 path = $ctx->{share}
1810 posix:sharedelay = 10000
1811 posix:oplocktimeout = 3
1812 posix:writetimeupdatedelay = 50000
1816 my $ret = $self->provision_raw_step1($ctx);
1821 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1822 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1823 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1824 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1825 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1827 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1829 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1830 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1831 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1832 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1833 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1835 unless (system($cmd) == 0) {
1836 warn("RODC join failed\n$cmd");
1840 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1841 # user password verified on the RODC
1842 my $testallowed_account = "testallowed account";
1843 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1844 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1845 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1846 $cmd .= " --server=$dcvars->{DC_SERVER}";
1848 unless (system($cmd) == 0) {
1849 warn("RODC join failed\n$cmd");
1853 # we overwrite the kdc after the RODC join
1854 # so that use the RODC as kdc and test
1856 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1857 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1858 Samba::mk_krb5_conf($ctx);
1859 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1861 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1862 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1863 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1864 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1866 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1867 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1868 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1869 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1870 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1871 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1876 sub read_config_h($)
1880 open(LF, "<$name") or die("unable to read $name: $!");
1883 next if not (/^#define /);
1884 if (/^#define (.*?)[ \t]+(.*?)$/) {
1888 if (/^#define (.*?)[ \t]+$/) {
1897 sub provision_ad_dc($$$$$$)
1899 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1900 $extra_provision_options) = @_;
1902 my $prefix_abs = abs_path($prefix);
1904 my $bindir_abs = abs_path($self->{bindir});
1905 my $lockdir="$prefix_abs/lockdir";
1906 my $conffile="$prefix_abs/etc/smb.conf";
1908 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1909 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1913 if (defined($ENV{CONFIG_H})) {
1914 $config_h = read_config_h($ENV{CONFIG_H});
1917 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1918 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1920 my $extra_smbconf_options = "
1921 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1923 dbwrap_tdb_mutexes:* = yes
1926 ${password_hash_gpg_key_ids}
1929 kernel change notify = no
1934 printcap name = /dev/null
1939 smbd:sharedelay = 100000
1940 smbd:writetimeupdatedelay = 500000
1943 check parent directory delete on close = yes
1945 dcerpc endpoint servers = -winreg -srvsvc
1947 printcap name = /dev/null
1949 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1950 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1953 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1954 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1955 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1956 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1957 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1958 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1959 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1961 print notify backchannel = yes
1963 server schannel = auto
1964 auth event notification = true
1965 dsdb event notification = true
1966 dsdb password event notification = true
1967 dsdb group change notification = true
1971 my $extra_smbconf_shares = "
1975 smb encrypt = required
1979 case sensitive = yes
1987 hide unreadable = yes
1991 kernel share modes = no
2010 push (@{$extra_provision_options}, "--backend-store=mdb");
2011 print "PROVISIONING AD DC...\n";
2012 my $ret = $self->provision($prefix,
2013 "domain controller",
2021 $extra_smbconf_options,
2022 $extra_smbconf_shares,
2023 $extra_provision_options);
2024 unless (defined $ret) {
2028 unless($self->add_wins_config("$prefix/private")) {
2029 warn("Unable to add wins configuration");
2033 $ret->{DC_SERVER} = $ret->{SERVER};
2034 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2035 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2036 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2037 $ret->{DC_USERNAME} = $ret->{USERNAME};
2038 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2043 sub provision_chgdcpass($$)
2045 my ($self, $prefix) = @_;
2047 print "PROVISIONING CHGDCPASS...\n";
2048 my $extra_provision_options = ["--use-ntvfs"];
2049 # This environment disallows the use of this password
2050 # (and also removes the default AD complexity checks)
2051 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2052 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2053 my $ret = $self->provision($prefix,
2054 "domain controller",
2057 "chgdcpassword.samba.example.com",
2062 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
2064 $extra_provision_options);
2065 unless (defined $ret) {
2069 unless($self->add_wins_config("$prefix/private")) {
2070 warn("Unable to add wins configuration");
2074 # Remove secrets.tdb from this environment to test that we
2075 # still start up on systems without the new matching
2076 # secrets.tdb records.
2077 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2078 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2082 $ret->{DC_SERVER} = $ret->{SERVER};
2083 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2084 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2085 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2086 $ret->{DC_USERNAME} = $ret->{USERNAME};
2087 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2088 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2093 sub teardown_env_terminate($$)
2095 my ($self, $envvars) = @_;
2098 # This should cause samba to terminate gracefully
2099 close($envvars->{STDIN_PIPE});
2101 $pid = $envvars->{SAMBA_PID};
2105 # This should give it time to write out the gcov data
2106 until ($count > 15) {
2107 if (Samba::cleanup_child($pid, "samba") != 0) {
2114 # After 15 Seconds, work out why this thing is still alive
2115 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2116 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2118 until ($count > 30) {
2119 if (Samba::cleanup_child($pid, "samba") != 0) {
2126 if (kill(0, $pid)) {
2127 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2131 until ($count > 40) {
2132 if (Samba::cleanup_child($pid, "samba") != 0) {
2138 # If it is still around, kill it
2139 if (kill(0, $pid)) {
2140 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2146 sub teardown_env($$)
2148 my ($self, $envvars) = @_;
2149 teardown_env_terminate($self, $envvars);
2151 $self->slapd_stop($envvars) if ($self->{ldap});
2153 print $self->getlog_env($envvars);
2160 my ($self, $envvars) = @_;
2161 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2164 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2166 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2170 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2173 return "" if $out eq $title;
2180 my ($self, $envvars) = @_;
2181 my $samba_pid = $envvars->{SAMBA_PID};
2183 if (not defined($samba_pid)) {
2185 } elsif ($samba_pid > 0) {
2186 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2188 if ($childpid == 0) {
2197 # Declare the environments Samba4 makes available.
2198 # To be set up, they will be called as
2199 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2200 %Samba4::ENV_DEPS = (
2201 # name => [dep_1, dep_2, ...],
2205 ad_dc_no_ntlm => [],
2209 preforkrestartdc => [],
2211 fl2008r2dc => ["ad_dc"],
2212 fl2003dc => ["ad_dc"],
2215 vampire_2000_dc => ["fl2000dc"],
2216 vampire_dc => ["ad_dc_ntvfs"],
2217 promoted_dc => ["ad_dc_ntvfs"],
2218 subdom_dc => ["ad_dc_ntvfs"],
2220 rodc => ["ad_dc_ntvfs"],
2221 rpc_proxy => ["ad_dc_ntvfs"],
2224 s4member_dflt_domain => ["ad_dc_ntvfs"],
2225 s4member => ["ad_dc_ntvfs"],
2227 restoredc => ["backupfromdc"],
2228 renamedc => ["backupfromdc"],
2229 offlinebackupdc => ["backupfromdc"],
2230 labdc => ["backupfromdc"],
2237 my ($self, $path, $dc_vars) = @_;
2239 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2242 if (not defined($self->check_or_start($env, "standard"))) {
2250 sub setup_s4member_dflt_domain
2252 my ($self, $path, $dc_vars) = @_;
2254 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2255 "winbind use default domain = yes");
2258 if (not defined($self->check_or_start($env, "standard"))) {
2268 my ($self, $path, $dc_vars) = @_;
2270 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2273 if (not defined($self->check_or_start($env, "standard"))) {
2280 sub setup_ad_dc_ntvfs
2282 my ($self, $path) = @_;
2284 my $env = $self->provision_ad_dc_ntvfs($path);
2286 if (not defined($self->check_or_start($env, "standard"))) {
2287 warn("Failed to start ad_dc_ntvfs");
2296 my ($self, $path) = @_;
2298 my $env = $self->provision_chgdcpass($path);
2300 if (not defined($self->check_or_start($env, "standard"))) {
2309 my ($self, $path) = @_;
2311 my $env = $self->provision_fl2000dc($path);
2313 if (not defined($self->check_or_start($env, "standard"))) {
2323 my ($self, $path, $dc_vars) = @_;
2325 my $env = $self->provision_fl2003dc($path);
2328 if (not defined($self->check_or_start($env, "standard"))) {
2332 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2337 sub setup_fl2008r2dc
2339 my ($self, $path, $dc_vars) = @_;
2341 my $env = $self->provision_fl2008r2dc($path);
2344 if (not defined($self->check_or_start($env, "standard"))) {
2348 my $upn_array = ["$env->{REALM}.upn"];
2349 my $spn_array = ["$env->{REALM}.spn"];
2351 $self->setup_namespaces($env, $upn_array, $spn_array);
2353 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2359 sub setup_vampire_dc
2361 return setup_generic_vampire_dc(@_, "2008");
2364 sub setup_vampire_2000_dc
2366 return setup_generic_vampire_dc(@_, "2000");
2369 sub setup_generic_vampire_dc
2371 my ($self, $path, $dc_vars, $fl) = @_;
2373 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2376 if (not defined($self->check_or_start($env, "single"))) {
2380 # force replicated DC to update repsTo/repsFrom
2381 # for vampired partitions
2382 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2384 # as 'vampired' dc may add data in its local replica
2385 # we need to synchronize data between DCs
2386 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2387 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2388 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2389 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2390 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2392 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2394 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2395 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2396 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2397 $cmd .= " $dc_vars->{CONFIGURATION}";
2398 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2399 # replicate Configuration NC
2400 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2401 unless(system($cmd_repl) == 0) {
2402 warn("Failed to replicate\n$cmd_repl");
2405 # replicate Default NC
2406 $cmd_repl = "$cmd \"$base_dn\"";
2407 unless(system($cmd_repl) == 0) {
2408 warn("Failed to replicate\n$cmd_repl");
2412 # Pull in a full set of changes from the main DC
2413 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2414 $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2415 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2416 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2417 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2419 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2421 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2422 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2423 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2424 $cmd .= " $dc_vars->{CONFIGURATION}";
2425 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2426 # replicate Configuration NC
2427 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2428 unless(system($cmd_repl) == 0) {
2429 warn("Failed to replicate\n$cmd_repl");
2432 # replicate Default NC
2433 $cmd_repl = "$cmd \"$base_dn\"";
2434 unless(system($cmd_repl) == 0) {
2435 warn("Failed to replicate\n$cmd_repl");
2443 sub setup_promoted_dc
2445 my ($self, $path, $dc_vars) = @_;
2447 my $env = $self->provision_promoted_dc($path, $dc_vars);
2450 if (not defined($self->check_or_start($env, "single"))) {
2454 # force source and replicated DC to update repsTo/repsFrom
2455 # for vampired partitions
2456 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2457 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2458 # as 'vampired' dc may add data in its local replica
2459 # we need to synchronize data between DCs
2460 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2461 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2462 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2463 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2464 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2465 $cmd .= " $dc_vars->{CONFIGURATION}";
2466 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2467 # replicate Configuration NC
2468 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2469 unless(system($cmd_repl) == 0) {
2470 warn("Failed to replicate\n$cmd_repl");
2473 # replicate Default NC
2474 $cmd_repl = "$cmd \"$base_dn\"";
2475 unless(system($cmd_repl) == 0) {
2476 warn("Failed to replicate\n$cmd_repl");
2486 my ($self, $path, $dc_vars) = @_;
2488 my $env = $self->provision_subdom_dc($path, $dc_vars);
2491 if (not defined($self->check_or_start($env, "single"))) {
2495 # force replicated DC to update repsTo/repsFrom
2496 # for primary domain partitions
2497 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2498 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2499 # as 'subdomain' dc may add data in its local replica
2500 # we need to synchronize data between DCs
2501 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2502 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2503 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2504 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2505 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2506 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2507 $cmd .= " $dc_vars->{CONFIGURATION}";
2508 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2509 # replicate Configuration NC
2510 my $cmd_repl = "$cmd \"$config_dn\"";
2511 unless(system($cmd_repl) == 0) {
2512 warn("Failed to replicate\n$cmd_repl");
2515 # replicate Default NC
2516 $cmd_repl = "$cmd \"$base_dn\"";
2517 unless(system($cmd_repl) == 0) {
2518 warn("Failed to replicate\n$cmd_repl");
2528 my ($self, $path, $dc_vars) = @_;
2530 my $env = $self->provision_rodc($path, $dc_vars);
2536 if (not defined($self->check_or_start($env, "standard"))) {
2540 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2543 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2544 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2545 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2546 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2547 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2548 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2549 $cmd .= " $dc_vars->{CONFIGURATION}";
2550 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2551 # replicate Configuration NC
2552 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2553 unless(system($cmd_repl) == 0) {
2554 warn("Failed to replicate\n$cmd_repl");
2557 # replicate Default NC
2558 $cmd_repl = "$cmd \"$base_dn\"";
2559 unless(system($cmd_repl) == 0) {
2560 warn("Failed to replicate\n$cmd_repl");
2569 my ($self, $path) = @_;
2571 # If we didn't build with ADS, pretend this env was never available
2572 if (not $self->{target3}->have_ads()) {
2576 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2577 "addom.samba.example.com", "", undef);
2582 if (not defined($self->check_or_start($env, "prefork"))) {
2586 my $upn_array = ["$env->{REALM}.upn"];
2587 my $spn_array = ["$env->{REALM}.spn"];
2589 $self->setup_namespaces($env, $upn_array, $spn_array);
2594 sub setup_ad_dc_no_nss
2596 my ($self, $path) = @_;
2598 # If we didn't build with ADS, pretend this env was never available
2599 if (not $self->{target3}->have_ads()) {
2603 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2604 "adnonssdom.samba.example.com", "", undef);
2609 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2610 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2612 if (not defined($self->check_or_start($env, "single"))) {
2616 my $upn_array = ["$env->{REALM}.upn"];
2617 my $spn_array = ["$env->{REALM}.spn"];
2619 $self->setup_namespaces($env, $upn_array, $spn_array);
2624 sub setup_ad_dc_no_ntlm
2626 my ($self, $path) = @_;
2628 # If we didn't build with ADS, pretend this env was never available
2629 if (not $self->{target3}->have_ads()) {
2633 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2634 "adnontlmdom.samba.example.com",
2635 "ntlm auth = disabled", undef);
2640 if (not defined($self->check_or_start($env, "prefork"))) {
2644 my $upn_array = ["$env->{REALM}.upn"];
2645 my $spn_array = ["$env->{REALM}.spn"];
2647 $self->setup_namespaces($env, $upn_array, $spn_array);
2653 # AD DC test environment used solely to test pre-fork process restarts.
2654 # As processes get killed off and restarted it should not be used for other
2655 sub setup_preforkrestartdc
2657 my ($self, $path) = @_;
2659 # If we didn't build with ADS, pretend this env was never available
2660 if (not $self->{target3}->have_ads()) {
2664 # note DC name must be <= 15 chars so we use 'prockill' instead of
2666 my $env = $self->provision_ad_dc(
2670 "prockilldom.samba.example.com",
2671 "prefork backoff increment = 5\nprefork maximum backoff=10");
2676 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2677 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2679 if (not defined($self->check_or_start($env, "prefork"))) {
2683 my $upn_array = ["$env->{REALM}.upn"];
2684 my $spn_array = ["$env->{REALM}.spn"];
2686 $self->setup_namespaces($env, $upn_array, $spn_array);
2691 # Sets up a DC that's solely used to do a domain backup from. We then use the
2692 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2693 # process will create a Samba DC that will actually start up.
2694 # We don't use the backup-DC for anything else because its domain will conflict
2695 # with the restore DC.
2696 sub setup_backupfromdc
2698 my ($self, $path) = @_;
2700 # If we didn't build with ADS, pretend this env was never available
2701 if (not $self->{target3}->have_ads()) {
2705 my $provision_args = ["--site=Backup-Site"];
2707 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2708 "backupdom.samba.example.com", "",
2714 if (not defined($self->check_or_start($env, "standard"))) {
2718 my $upn_array = ["$env->{REALM}.upn"];
2719 my $spn_array = ["$env->{REALM}.spn"];
2721 $self->setup_namespaces($env, $upn_array, $spn_array);
2726 # returns the server/user-auth params needed to run an online backup cmd
2727 sub get_backup_server_args
2729 # dcvars contains the env info for the backup DC testenv
2730 my ($self, $dcvars) = @_;
2731 my $server = $dcvars->{DC_SERVER_IP};
2732 my $server_args = "--server=$server ";
2733 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2734 $server_args .= " $dcvars->{CONFIGURATION}";
2736 return $server_args;
2739 # Creates a backup of a running testenv DC
2742 # note: dcvars contains the env info for the backup DC testenv
2743 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2745 # get all the env variables we pass in with the samba-tool command
2746 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2747 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2748 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2749 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2751 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2753 # Note: use the backupfrom-DC's krb5.conf to do the backup
2754 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2755 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2757 # use samba-tool to create a backup from the 'backupfromdc' DC
2759 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2761 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2762 $cmd .= " --targetdir=$backupdir";
2764 print "Executing: $cmd\n";
2765 unless(system($cmd) == 0) {
2766 warn("Failed to create backup using: \n$cmd");
2770 # get the name of the backup file created
2771 opendir(DIR, $backupdir);
2772 my @files = grep(/\.tar/, readdir(DIR));
2775 if(scalar @files != 1) {
2776 warn("Backup file not found in directory $backupdir\n");
2779 my $backup_file = "$backupdir/$files[0]";
2780 print "Using backup file $backup_file...\n";
2782 return $backup_file;
2785 # Restores a backup-file to populate a testenv for a new DC
2786 sub restore_backup_file
2788 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2790 # pass the restore command the testenv's smb.conf that we've already
2791 # generated. But move it to a temp-dir first, so that the restore doesn't
2793 my $tmpdir = File::Temp->newdir();
2794 my $tmpconf = "$tmpdir/smb.conf";
2795 my $cmd = "cp $smbconf $tmpconf";
2796 unless(system($cmd) == 0) {
2797 warn("Failed to backup smb.conf using: \n$cmd");
2801 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2802 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2803 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2805 print "Executing: $cmd\n";
2806 unless(system($cmd) == 0) {
2807 warn("Failed to restore backup using: \n$cmd");
2811 print "Restore complete\n";
2815 # sets up the initial directory and returns the new testenv's env info
2816 # (without actually doing a 'domain join')
2817 sub prepare_dc_testenv
2819 my ($self, $prefix, $dcname, $domain, $realm, $password) = @_;
2821 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2831 # the restore uses a slightly different state-dir location to other testenvs
2832 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2833 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2835 # add support for sysvol/netlogon/tmp shares
2836 $ctx->{share} = "$ctx->{prefix_abs}/share";
2837 push(@{$ctx->{directories}}, "$ctx->{share}");
2839 $ctx->{smb_conf_extra_options} = "
2841 server max protocol = SMB2
2844 path = $ctx->{statedir}/sysvol
2848 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2852 path = $ctx->{share}
2854 posix:sharedelay = 10000
2855 posix:oplocktimeout = 3
2856 posix:writetimeupdatedelay = 50000
2860 my $env = $self->provision_raw_step1($ctx);
2862 $env->{DC_SERVER} = $env->{SERVER};
2863 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
2864 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
2865 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
2866 $env->{DC_USERNAME} = $env->{USERNAME};
2867 $env->{DC_PASSWORD} = $env->{PASSWORD};
2869 return ($env, $ctx);
2873 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2874 # commands. This proves that we can backup an online DC ('backupfromdc') and
2875 # use the backup file to create a valid, working samba DC.
2878 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2879 my ($self, $prefix, $dcvars) = @_;
2880 print "Preparing RESTORE DC...\n";
2882 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2885 $dcvars->{PASSWORD});
2887 # create a backup of the 'backupfromdc'
2888 my $backupdir = File::Temp->newdir();
2889 my $server_args = $self->get_backup_server_args($dcvars);
2890 my $backup_args = "online $server_args";
2891 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2893 unless($backup_file) {
2897 # restore the backup file to populate the restore-DC testenv
2898 my $restore_dir = abs_path($prefix);
2899 my $ret = $self->restore_backup_file($backup_file,
2900 "--newservername=$env->{SERVER}",
2901 $restore_dir, $env->{SERVERCONFFILE});
2902 unless ($ret == 0) {
2906 # start samba for the restored DC
2907 if (not defined($self->check_or_start($env, "standard"))) {
2914 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2915 # restore commands. This proves that we can backup and rename an online DC
2916 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2919 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2920 my ($self, $prefix, $dcvars) = @_;
2921 print "Preparing RENAME DC...\n";
2923 my $realm = "renamedom.samba.example.com";
2924 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
2925 "RENAMEDOMAIN", $realm,
2926 $dcvars->{PASSWORD});
2928 # create a backup of the 'backupfromdc' which renames the domain
2929 my $backupdir = File::Temp->newdir();
2930 my $server_args = $self->get_backup_server_args($dcvars);
2931 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2932 $backup_args .= " --backend-store=tdb";
2933 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2935 unless($backup_file) {
2939 # restore the backup file to populate the rename-DC testenv
2940 my $restore_dir = abs_path($prefix);
2941 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2942 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2943 $restore_dir, $env->{SERVERCONFFILE});
2944 unless ($ret == 0) {
2948 # start samba for the restored DC
2949 if (not defined($self->check_or_start($env, "standard"))) {
2953 my $upn_array = ["$env->{REALM}.upn"];
2954 my $spn_array = ["$env->{REALM}.spn"];
2956 $self->setup_namespaces($env, $upn_array, $spn_array);
2961 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
2962 # restore commands. This proves that we do an offline backup of a local DC
2963 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2964 sub setup_offlinebackupdc
2966 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2967 my ($self, $prefix, $dcvars) = @_;
2968 print "Preparing OFFLINE BACKUP DC...\n";
2970 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
2973 $dcvars->{PASSWORD});
2975 # create an offline backup of the 'backupfromdc' target
2976 my $backupdir = File::Temp->newdir();
2977 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
2978 my $backup_file = $self->create_backup($env, $dcvars,
2981 unless($backup_file) {
2985 # restore the backup file to populate the rename-DC testenv
2986 my $restore_dir = abs_path($prefix);
2987 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2988 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2989 $restore_dir, $env->{SERVERCONFFILE});
2990 unless ($ret == 0) {
2994 # re-create the testenv's krb5.conf (the restore may have overwritten it)
2995 Samba::mk_krb5_conf($ctx);
2997 # start samba for the restored DC
2998 if (not defined($self->check_or_start($env, "standard"))) {
3005 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
3006 # restore commands, using the --no-secrets option. This proves that we can
3007 # create a realistic lab environment from an online DC ('backupfromdc').
3010 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
3011 my ($self, $prefix, $dcvars) = @_;
3012 print "Preparing LAB-DOMAIN DC...\n";
3014 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
3016 "labdom.samba.example.com",
3017 $dcvars->{PASSWORD});
3019 # create a backup of the 'backupfromdc' which renames the domain and uses
3020 # the --no-secrets option to scrub any sensitive info
3021 my $backupdir = File::Temp->newdir();
3022 my $server_args = $self->get_backup_server_args($dcvars);
3023 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
3024 $backup_args .= " --no-secrets --backend-store=mdb";
3025 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
3027 unless($backup_file) {
3031 # restore the backup file to populate the lab-DC testenv
3032 my $restore_dir = abs_path($prefix);
3033 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
3034 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
3035 $restore_dir, $env->{SERVERCONFFILE});
3036 unless ($ret == 0) {
3040 # because we don't include any secrets in the backup, we need to reset the
3041 # admin user's password back to what the testenv expects
3042 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3043 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3044 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
3045 $cmd .= " $env->{CONFIGURATION}";
3047 unless(system($cmd) == 0) {
3048 warn("Failed to reset admin's password: \n$cmd");
3052 # start samba for the restored DC
3053 if (not defined($self->check_or_start($env, "standard"))) {
3057 my $upn_array = ["$env->{REALM}.upn"];
3058 my $spn_array = ["$env->{REALM}.spn"];
3060 $self->setup_namespaces($env, $upn_array, $spn_array);
3065 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3066 sub get_backup_domain_realm
3068 my ($self, $backup_file) = @_;
3070 print "Determining REALM/DOMAIN values in backup...\n";
3072 # The backup will have the correct domain/realm values in the smb.conf.
3073 # So we can work out the env variables the testenv should use based on
3074 # that. Let's start by extracting the smb.conf
3075 my $tar = Archive::Tar->new($backup_file);
3076 my $tmpdir = File::Temp->newdir();
3077 my $smbconf = "$tmpdir/smb.conf";
3079 # note that the filepaths within the tar-file differ slightly for online
3080 # and offline backups
3081 if ($tar->contains_file("etc/smb.conf")) {
3082 $tar->extract_file("etc/smb.conf", $smbconf);
3083 } elsif ($tar->contains_file("./etc/smb.conf")) {
3084 $tar->extract_file("./etc/smb.conf", $smbconf);
3086 warn("Could not find smb.conf in $backup_file");
3087 return undef, undef;
3090 # now use testparm to read the values we're interested in
3091 my $testparm = Samba::bindir_path($self, "testparm");
3092 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3093 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3096 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3098 return ($domain, $realm);
3101 # This spins up a custom testenv that can be based on any backup-file you want.
3102 # This is just intended for manual testing (rather than automated test-cases)
3105 my ($self, $prefix) = @_;
3106 print "Preparing CUSTOM RESTORE DC...\n";
3107 my $dc_name = "customdc";
3108 my $password = "locDCpass1";
3109 my $backup_file = $ENV{'BACKUP_FILE'};
3111 # user must specify a backup file to restore via an ENV variable, i.e.
3112 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3113 if (not defined($backup_file)) {
3114 warn("Please specify BACKUP_FILE");
3118 # work out the correct domain/realm env values from the backup-file
3119 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3121 # create a placeholder directory and smb.conf, as well as the env vars.
3122 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3123 $domain, $realm, $password);
3125 # restore the specified backup file to populate the testenv
3126 my $restore_dir = abs_path($prefix);
3127 my $ret = $self->restore_backup_file($backup_file,
3128 "--newservername=$env->{SERVER}",
3129 $restore_dir, $env->{SERVERCONFFILE});
3130 unless ($ret == 0) {
3134 # Change the admin password to the testenv default, just in case it's
3135 # different, or in case this was a --no-secrets backup
3136 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3137 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3138 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3139 $cmd .= " $env->{CONFIGURATION}";
3141 unless(system($cmd) == 0) {
3142 warn("Failed to reset admin's password: \n$cmd");
3146 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3147 # if the backup-file was an offline backup)
3148 Samba::mk_krb5_conf($ctx);
3150 # start samba for the restored DC
3151 if (not defined($self->check_or_start($env, "standard"))) {
3155 # if this was a backup-rename, then we may need to setup namespaces
3156 my $upn_array = ["$env->{REALM}.upn"];
3157 my $spn_array = ["$env->{REALM}.spn"];
3159 $self->setup_namespaces($env, $upn_array, $spn_array);
3166 my ($self, $path) = @_;
3169 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",