2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
10 use FindBin qw($RealBin);
18 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
25 server_maxtime => $server_maxtime,
26 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
32 sub scriptdir_path($$) {
33 my ($self, $path) = @_;
34 return "$self->{srcdir}/source4/scripting/$path";
37 sub openldap_start($$$) {
43 my ($self, $env_vars, $STDIN_READER) = @_;
44 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
46 my $uri = $env_vars->{LDAP_URI};
48 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
49 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
52 # running slapd in the background means it stays in the same process group, so it can be
56 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
57 open STDERR, '>&STDOUT';
58 close($env_vars->{STDIN_PIPE});
59 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
61 if ($self->{ldap} eq "fedora-ds") {
62 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
63 } elsif ($self->{ldap} eq "openldap") {
64 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
66 die("Unable to start slapd: $!");
68 $env_vars->{SLAPD_PID} = $pid;
70 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
73 $self->slapd_stop($env_vars);
83 my ($self, $envvars) = @_;
84 kill 9, $envvars->{SLAPD_PID};
88 sub check_or_start($$$)
90 my ($self, $env_vars, $process_model) = @_;
93 my $env_ok = $self->check_env($env_vars);
95 return $env_vars->{SAMBA_PID};
96 } elsif (defined($env_vars->{SAMBA_PID})) {
97 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
101 # use a pipe for stdin in the child processes. This allows
102 # those processes to monitor the pipe for EOF to ensure they
103 # exit when the test script exits
104 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
106 # Start slapd before samba, but with the fifo on stdin
107 if (defined($self->{ldap})) {
108 unless($self->slapd_start($env_vars, $STDIN_READER)) {
109 warn("couldn't start slapd (main run)");
114 print "STARTING SAMBA...\n";
117 # we want out from samba to go to the log file, but also
118 # to the users terminal when running 'make test' on the command
119 # line. This puts it on stderr on the terminal
120 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
121 open STDERR, '>&STDOUT';
123 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
125 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
126 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
127 if (defined($ENV{MITKRB5})) {
128 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
130 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
131 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
133 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
134 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
135 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
136 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
137 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
138 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
140 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
141 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
143 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
146 $ENV{UID_WRAPPER} = "1";
147 $ENV{UID_WRAPPER_ROOT} = "1";
149 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
152 if (defined($ENV{SAMBA_OPTIONS})) {
153 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
155 if(defined($ENV{SAMBA_VALGRIND})) {
156 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
159 close($env_vars->{STDIN_PIPE});
160 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
162 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: $!");
164 $env_vars->{SAMBA_PID} = $pid;
165 print "DONE ($pid)\n";
167 close($STDIN_READER);
169 if ($self->wait_for_start($env_vars) != 0) {
170 warn("Samba $pid failed to start up");
177 sub wait_for_start($$)
179 my ($self, $testenv_vars) = @_;
183 if (not $self->check_env($testenv_vars)) {
184 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
188 # This will return quickly when things are up, but be slow if we
189 # need to wait for (eg) SSL init
190 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
193 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
199 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
200 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
201 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
204 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
207 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
210 } while ($ret != 0 && $count < 20);
212 warn("nbt not reachable after 20 retries\n");
213 teardown_env($self, $testenv_vars);
217 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
218 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
219 print "waiting for working LDAP and a RID Set to be allocated\n";
220 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
222 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
224 my $search_dn = $base_dn;
225 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
226 # TODO currently no check for actual rIDAllocationPool
227 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
231 # Add hosts file for name lookups
232 my $cmd = "NSS_WRAPPER_HOSTS='$testenv_vars->{NSS_WRAPPER_HOSTS}' ";
233 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
234 $cmd .= "RESOLV_WRAPPER_CONF='$testenv_vars->{RESOLV_WRAPPER_CONF}' ";
236 $cmd .= "RESOLV_WRAPPER_HOSTS='$testenv_vars->{RESOLV_WRAPPER_HOSTS}' ";
239 $cmd .= "$ldbsearch ";
240 $cmd .= "$testenv_vars->{CONFIGURATION} ";
241 $cmd .= "-H ldap://$testenv_vars->{SERVER} ";
242 $cmd .= "-U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} ";
244 $cmd .= "-b '$search_dn' ";
245 while (system("$cmd >/dev/null") != 0) {
247 if ($count > $max_wait) {
248 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}");
256 my $wbinfo = Samba::bindir_path($self, "wbinfo");
260 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
261 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
262 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
263 $cmd .= "$wbinfo -P";
270 } while ($ret != 0 && $count < 20);
272 warn("winbind not reachable after 20 retries\n");
273 teardown_env($self, $testenv_vars);
277 print $self->getlog_env($testenv_vars);
282 sub write_ldb_file($$$)
284 my ($self, $file, $ldif) = @_;
286 my $ldbadd = Samba::bindir_path($self, "ldbadd");
287 open(LDIF, "|$ldbadd -H $file >/dev/null");
292 sub add_wins_config($$)
294 my ($self, $privatedir) = @_;
296 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
297 dn: name=TORTURE_11,CN=PARTNERS
298 objectClass: wreplPartner
309 my ($self, $ctx) = @_;
311 #Make the subdirectory be as fedora DS would expect
312 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
314 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
316 return ($fedora_ds_dir, $pidfile);
321 my ($self, $ctx) = @_;
323 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
324 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
326 return ($slapd_conf_d, $pidfile);
329 sub setup_namespaces($$:$$)
331 my ($self, $localenv, $upn_array, $spn_array) = @_;
333 @{$upn_array} = [] unless defined($upn_array);
335 foreach my $upn (@{$upn_array}) {
336 $upn_args .= " --add-upn-suffix=$upn";
339 @{$spn_array} = [] unless defined($spn_array);
341 foreach my $spn (@{$spn_array}) {
342 $spn_args .= " --add-spn-suffix=$spn";
345 my $samba_tool = Samba::bindir_path($self, "samba-tool");
347 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
348 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
349 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
350 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
352 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
354 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
355 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
357 my $cmd_config = " $localenv->{CONFIGURATION}";
359 my $namespaces = $cmd_env;
360 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
361 $namespaces .= $cmd_config;
362 unless (system($namespaces) == 0) {
363 warn("Failed to add namespaces \n$namespaces");
370 sub setup_trust($$$$$)
372 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
374 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
375 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
376 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
377 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
378 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
379 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
380 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
381 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
382 $localenv->{TRUST_DOMSID} = $remoteenv->{DOMSID};
384 my $samba_tool = Samba::bindir_path($self, "samba-tool");
387 my $cmd_env = "NSS_WRAPPER_HOSTS='$localenv->{NSS_WRAPPER_HOSTS}' ";
388 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
389 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
390 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
392 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
394 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
395 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
397 my $cmd_config = " $localenv->{CONFIGURATION}";
398 my $cmd_creds = $cmd_config;
399 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
401 my $create = $cmd_env;
402 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
403 $create .= " $extra_args";
404 $create .= $cmd_creds;
405 unless (system($create) == 0) {
406 warn("Failed to create trust \n$create");
410 my $groupname = "g_$localenv->{TRUST_DOMAIN}";
411 my $groupadd = $cmd_env;
412 $groupadd .= " $samba_tool group add '$groupname' --group-scope=Domain $cmd_config";
413 unless (system($groupadd) == 0) {
414 warn("Failed to create group \n$groupadd");
417 my $groupmem = $cmd_env;
418 $groupmem .= " $samba_tool group addmembers '$groupname' '$localenv->{TRUST_DOMSID}-513' $cmd_config";
419 unless (system($groupmem) == 0) {
420 warn("Failed to add group member \n$groupmem");
427 sub provision_raw_prepare($$$$$$$$$$$$)
429 my ($self, $prefix, $server_role, $hostname,
430 $domain, $realm, $samsid, $functional_level,
431 $password, $kdc_ipv4, $kdc_ipv6) = @_;
434 if (defined $ENV{PYTHON}) {
435 $python_cmd = $ENV{PYTHON} . " ";
437 $ctx->{python} = $python_cmd;
438 my $netbiosname = uc($hostname);
440 unless(-d $prefix or mkdir($prefix, 0777)) {
441 warn("Unable to create $prefix");
444 my $prefix_abs = abs_path($prefix);
446 die ("prefix=''") if $prefix_abs eq "";
447 die ("prefix='/'") if $prefix_abs eq "/";
449 unless (system("rm -rf $prefix_abs/*") == 0) {
450 warn("Unable to clean up");
454 my $swiface = Samba::get_interface($hostname);
456 $ctx->{prefix} = $prefix;
457 $ctx->{prefix_abs} = $prefix_abs;
459 $ctx->{server_role} = $server_role;
460 $ctx->{hostname} = $hostname;
461 $ctx->{netbiosname} = $netbiosname;
462 $ctx->{swiface} = $swiface;
463 $ctx->{password} = $password;
464 $ctx->{kdc_ipv4} = $kdc_ipv4;
465 $ctx->{kdc_ipv6} = $kdc_ipv6;
466 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
467 if ($functional_level eq "2000") {
468 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
472 # Set smbd log level here.
474 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
475 $ctx->{username} = "Administrator";
476 $ctx->{domain} = $domain;
477 $ctx->{realm} = uc($realm);
478 $ctx->{dnsname} = lc($realm);
479 $ctx->{samsid} = $samsid;
481 $ctx->{functional_level} = $functional_level;
483 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
485 $ctx->{unix_name} = $unix_name;
486 $ctx->{unix_uid} = $>;
487 my @mygid = split(" ", $();
488 $ctx->{unix_gid} = $mygid[0];
489 $ctx->{unix_gids_str} = $);
490 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
492 $ctx->{etcdir} = "$prefix_abs/etc";
493 $ctx->{piddir} = "$prefix_abs/pid";
494 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
495 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
496 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
497 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
498 $ctx->{privatedir} = "$prefix_abs/private";
499 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
500 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
501 $ctx->{lockdir} = "$prefix_abs/lockdir";
502 $ctx->{logdir} = "$prefix_abs/logs";
503 $ctx->{statedir} = "$prefix_abs/statedir";
504 $ctx->{cachedir} = "$prefix_abs/cachedir";
505 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
506 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
507 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
508 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
509 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
510 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
511 if ($ENV{SAMBA_DNS_FAKING}) {
512 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
513 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
514 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
516 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
517 $ctx->{samba_dnsupdate} = $python_cmd . $ctx->{samba_dnsupdate};
518 $ctx->{use_resolv_wrapper} = 1;
520 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
522 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
524 $ctx->{ipv4} = "127.0.0.$swiface";
525 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
526 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
528 push(@{$ctx->{directories}}, $ctx->{privatedir});
529 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
530 push(@{$ctx->{directories}}, $ctx->{etcdir});
531 push(@{$ctx->{directories}}, $ctx->{piddir});
532 push(@{$ctx->{directories}}, $ctx->{lockdir});
533 push(@{$ctx->{directories}}, $ctx->{logdir});
534 push(@{$ctx->{directories}}, $ctx->{statedir});
535 push(@{$ctx->{directories}}, $ctx->{cachedir});
537 $ctx->{smb_conf_extra_options} = "";
539 my @provision_options = ();
540 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
541 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
542 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
543 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
544 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
545 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
546 if (defined($ctx->{use_resolv_wrapper})) {
547 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
549 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
551 if (defined($ENV{GDB_PROVISION})) {
552 push (@provision_options, "gdb --args");
553 if (!defined($ENV{PYTHON})) {
554 push (@provision_options, "env");
555 push (@provision_options, "python");
558 if (defined($ENV{VALGRIND_PROVISION})) {
559 push (@provision_options, "valgrind");
560 if (!defined($ENV{PYTHON})) {
561 push (@provision_options, "env");
562 push (@provision_options, "python");
566 my $samba_tool = Samba::bindir_path($self, "samba-tool");
568 push (@provision_options, $samba_tool);
569 push (@provision_options, "domain");
570 push (@provision_options, "provision");
571 push (@provision_options, "--configfile=$ctx->{smb_conf}");
572 push (@provision_options, "--host-name=$ctx->{hostname}");
573 push (@provision_options, "--host-ip=$ctx->{ipv4}");
574 push (@provision_options, "--quiet");
575 push (@provision_options, "--domain=$ctx->{domain}");
576 push (@provision_options, "--realm=$ctx->{realm}");
577 if (defined($ctx->{samsid})) {
578 push (@provision_options, "--domain-sid=$ctx->{samsid}");
580 push (@provision_options, "--adminpass=$ctx->{password}");
581 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
582 push (@provision_options, "--machinepass=machine$ctx->{password}");
583 push (@provision_options, "--root=$ctx->{unix_name}");
584 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
585 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
587 @{$ctx->{provision_options}} = @provision_options;
593 # Step1 creates the basic configuration
595 sub provision_raw_step1($$)
597 my ($self, $ctx) = @_;
599 mkdir($_, 0777) foreach (@{$ctx->{directories}});
602 ## lockdir and piddir must be 0755
604 chmod 0755, $ctx->{lockdir};
605 chmod 0755, $ctx->{piddir};
607 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
608 warn("can't open $ctx->{smb_conf}$?");
612 Samba::prepare_keyblobs($ctx);
613 my $crlfile = "$ctx->{tlsdir}/crl.pem";
614 $crlfile = "" unless -e ${crlfile};
618 netbios name = $ctx->{netbiosname}
619 posix:eadb = $ctx->{statedir}/eadb.tdb
620 workgroup = $ctx->{domain}
621 realm = $ctx->{realm}
622 private dir = $ctx->{privatedir}
623 binddns dir = $ctx->{binddnsdir}
624 pid directory = $ctx->{piddir}
625 ncalrpc dir = $ctx->{ncalrpcdir}
626 lock dir = $ctx->{lockdir}
627 state directory = $ctx->{statedir}
628 cache directory = $ctx->{cachedir}
629 winbindd socket directory = $ctx->{winbindd_socket_dir}
630 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
631 winbind separator = /
632 interfaces = $ctx->{interfaces}
633 tls dh params file = $ctx->{tlsdir}/dhparms.pem
634 tls crlfile = ${crlfile}
635 tls verify peer = no_check
636 panic action = $RealBin/gdb_backtrace \%d
638 server role = $ctx->{server_role}
639 server services = +echo +smb -s3fs
640 dcerpc endpoint servers = +winreg +srvsvc
641 notify:inotify = false
643 ldap server require strong auth = yes
644 #We don't want to pass our self-tests if the PAC code is wrong
645 gensec:require_pac = true
646 log file = $ctx->{logdir}/log.\%m
647 log level = $ctx->{server_loglevel}
651 dns update command = $ctx->{samba_dnsupdate}
652 spn update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
653 gpo update command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba-gpupdate -s $ctx->{smb_conf} --target=Computer
654 samba kcc command = $ctx->{python} $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_kcc
655 dreplsrv:periodic_startup_interval = 0
656 dsdb:schema update allowed = yes
660 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
662 idmap_ldb:use rfc2307=yes
663 winbind enum users = yes
664 winbind enum groups = yes
666 rpc server port:netlogon = 1026
672 # Begin extra options
673 $ctx->{smb_conf_extra_options}
678 #Default the KDC IP to the server's IP
679 if (not defined($ctx->{kdc_ipv4})) {
680 $ctx->{kdc_ipv4} = $ctx->{ipv4};
682 if (not defined($ctx->{kdc_ipv6})) {
683 $ctx->{kdc_ipv6} = $ctx->{ipv6};
686 Samba::mk_krb5_conf($ctx);
687 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
689 open(PWD, ">$ctx->{nsswrap_passwd}");
690 if ($ctx->{unix_uid} != 0) {
691 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
693 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
694 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
695 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
696 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
697 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
698 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
701 my $uid_rfc2307test = 65533;
703 open(GRP, ">$ctx->{nsswrap_group}");
704 if ($ctx->{unix_gid} != 0) {
705 print GRP "root:x:0:\n";
707 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
708 print GRP "wheel:x:10:
711 nogroup:x:65534:nobody
714 my $gid_rfc2307test = 65532;
716 my $hostname = lc($ctx->{hostname});
717 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
718 if ($hostname eq "localdc") {
719 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
720 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
722 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
723 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
727 if (defined($ctx->{resolv_conf})) {
728 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
729 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
730 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
734 my $configuration = "--configfile=$ctx->{smb_conf}";
736 #Ensure the config file is valid before we start
737 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
738 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
739 system("$testparm -v --suppress-prompt $configuration >&2");
740 warn("Failed to create a valid smb.conf configuration $testparm!");
743 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) {
744 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
749 KRB5_CONFIG => $ctx->{krb5_conf},
750 KRB5_CCACHE => $ctx->{krb5_ccache},
751 MITKDC_CONFIG => $ctx->{mitkdc_conf},
752 PIDDIR => $ctx->{piddir},
753 SERVER => $ctx->{hostname},
754 SERVER_IP => $ctx->{ipv4},
755 SERVER_IPV6 => $ctx->{ipv6},
756 NETBIOSNAME => $ctx->{netbiosname},
757 DOMAIN => $ctx->{domain},
758 USERNAME => $ctx->{username},
759 REALM => $ctx->{realm},
760 DNSNAME => $ctx->{dnsname},
761 SAMSID => $ctx->{samsid},
762 PASSWORD => $ctx->{password},
763 LDAPDIR => $ctx->{ldapdir},
764 LDAP_INSTANCE => $ctx->{ldap_instance},
765 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
766 NCALRPCDIR => $ctx->{ncalrpcdir},
767 LOCKDIR => $ctx->{lockdir},
768 STATEDIR => $ctx->{statedir},
769 CACHEDIR => $ctx->{cachedir},
770 PRIVATEDIR => $ctx->{privatedir},
771 BINDDNSDIR => $ctx->{binddnsdir},
772 SERVERCONFFILE => $ctx->{smb_conf},
773 CONFIGURATION => $configuration,
774 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
775 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
776 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
777 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
778 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
779 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
780 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
781 SAMBA_TEST_LOG_POS => 0,
782 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
783 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
784 LOCAL_PATH => $ctx->{share},
785 UID_RFC2307TEST => $uid_rfc2307test,
786 GID_RFC2307TEST => $gid_rfc2307test,
787 SERVER_ROLE => $ctx->{server_role},
788 RESOLV_CONF => $ctx->{resolv_conf}
791 if (defined($ctx->{use_resolv_wrapper})) {
792 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
794 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
797 if ($ctx->{server_role} eq "domain controller") {
798 $ret->{DOMSID} = $ret->{SAMSID};
805 # Step2 runs the provision script
807 sub provision_raw_step2($$$)
809 my ($self, $ctx, $ret) = @_;
811 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
812 unless (system($provision_cmd) == 0) {
813 warn("Unable to provision: \n$provision_cmd\n");
817 my $testallowed_account = "testallowed";
818 my $samba_tool_cmd = "";
819 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
820 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
821 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
822 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
823 unless (system($samba_tool_cmd) == 0) {
824 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
829 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
830 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
831 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
832 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
834 if ($ctx->{server_role} ne "domain controller") {
835 $base_dn = "DC=$ctx->{netbiosname}";
838 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
839 $testallowed_account = "testallowed account";
840 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
841 print LDIF "dn: $user_dn
843 replace: samAccountName
844 samAccountName: $testallowed_account
849 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
850 print LDIF "dn: $user_dn
852 replace: userPrincipalName
853 userPrincipalName: testallowed upn\@$ctx->{realm}
854 replace: servicePrincipalName
855 servicePrincipalName: host/testallowed
860 $samba_tool_cmd = "";
861 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
862 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
863 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
864 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
865 unless (system($samba_tool_cmd) == 0) {
866 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
870 my $user_dn = "cn=testdenied,cn=users,$base_dn";
871 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
872 print LDIF "dn: $user_dn
874 replace: userPrincipalName
875 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
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} testupnspn $ctx->{password}";
885 unless (system($samba_tool_cmd) == 0) {
886 warn("Unable to add testupnspn user: \n$samba_tool_cmd\n");
890 my $user_dn = "cn=testupnspn,cn=users,$base_dn";
891 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
892 print LDIF "dn: $user_dn
894 replace: userPrincipalName
895 userPrincipalName: http/testupnspn.$ctx->{dnsname}\@$ctx->{realm}
896 replace: servicePrincipalName
897 servicePrincipalName: http/testupnspn.$ctx->{dnsname}
902 $samba_tool_cmd = "";
903 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
904 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
905 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
906 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
907 unless (system($samba_tool_cmd) == 0) {
908 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
912 # Create to users alice and bob!
913 my $user_account_array = ["alice", "bob", "jane"];
915 foreach my $user_account (@{$user_account_array}) {
916 my $samba_tool_cmd = "";
918 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
919 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
920 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
921 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
922 unless (system($samba_tool_cmd) == 0) {
923 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
929 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
930 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
931 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
933 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
934 my $user_dn = "cn=jane,cn=users,$base_dn";
936 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
937 print LDIF "dn: $user_dn
939 replace: userPrincipalName
940 userPrincipalName: jane.doe\@$ctx->{realm}
948 sub provision($$$$$$$$$$)
950 my ($self, $prefix, $server_role, $hostname,
951 $domain, $realm, $functional_level,
952 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
953 $extra_provision_options) = @_;
955 my $samsid = Samba::random_domain_sid();
957 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
962 $password, $kdc_ipv4, $kdc_ipv6);
964 if (defined($extra_provision_options)) {
965 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
967 push (@{$ctx->{provision_options}}, "--use-ntvfs");
970 $ctx->{share} = "$ctx->{prefix_abs}/share";
971 push(@{$ctx->{directories}}, "$ctx->{share}");
972 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
973 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
975 # precreate directories for printer drivers
976 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
977 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
978 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
981 $msdfs = "yes" if ($server_role eq "domain controller");
982 $ctx->{smb_conf_extra_options} = "
985 server max protocol = SMB2
989 # fruit:copyfile is a global option
992 $extra_smbconf_options
997 posix:sharedelay = 100000
998 posix:oplocktimeout = 3
999 posix:writetimeupdatedelay = 500000
1002 path = $ctx->{share}
1004 posix:sharedelay = 100000
1005 posix:oplocktimeout = 3
1006 posix:writetimeupdatedelay = 500000
1008 force create mode = 777
1011 path = $ctx->{share}
1014 force create mode = 0
1015 directory mask = 0777
1016 force directory mode = 0
1019 path = $ctx->{share}/test1
1021 posix:sharedelay = 100000
1022 posix:oplocktimeout = 3
1023 posix:writetimeupdatedelay = 500000
1026 path = $ctx->{share}/test2
1028 posix:sharedelay = 100000
1029 posix:oplocktimeout = 3
1030 posix:writetimeupdatedelay = 500000
1033 path = $ctx->{share}/_ignore_cifs_
1035 ntvfs handler = cifs
1036 cifs:server = $ctx->{netbiosname}
1038 cifs:use-s4u2proxy = yes
1039 # There is no username specified here, instead the client is expected
1040 # to log in with kerberos, and the serverwill use delegated credentials.
1041 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1044 path = $ctx->{share}
1046 ntvfs handler = simple
1049 path = $ctx->{statedir}/sysvol
1053 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1058 ntvfs handler = cifsposix
1061 path = $ctx->{share}
1062 vfs objects = catia fruit streams_xattr acl_xattr
1064 fruit:resource = file
1065 fruit:metadata = netatalk
1066 fruit:locking = netatalk
1067 fruit:encoding = native
1069 $extra_smbconf_shares
1072 if (defined($self->{ldap})) {
1073 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
1074 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
1076 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
1077 $ldap_uri =~ s|/|%2F|g;
1078 $ldap_uri = "ldapi://$ldap_uri";
1079 $ctx->{ldap_uri} = $ldap_uri;
1081 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
1084 my $ret = $self->provision_raw_step1($ctx);
1085 unless (defined $ret) {
1089 if (defined($self->{ldap})) {
1090 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1091 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1092 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1093 if ($self->{ldap} eq "openldap") {
1094 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1095 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1097 } elsif ($self->{ldap} eq "fedora-ds") {
1098 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1099 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1100 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1105 return $self->provision_raw_step2($ctx, $ret);
1108 sub provision_s4member($$$$$)
1110 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1111 print "PROVISIONING MEMBER...\n";
1112 my $extra_smb_conf = "
1113 passdb backend = samba_dsdb
1114 winbindd:use external pipes = true
1116 # the source4 smb server doesn't allow signing by default
1117 server signing = enabled
1118 raw NTLMv2 auth = yes
1120 rpc_server:default = external
1121 rpc_server:svcctl = embedded
1122 rpc_server:srvsvc = embedded
1123 rpc_server:eventlog = embedded
1124 rpc_server:ntsvcs = embedded
1125 rpc_server:winreg = embedded
1126 rpc_server:spoolss = embedded
1127 rpc_daemon:spoolssd = embedded
1128 rpc_server:tcpip = no
1131 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1133 my $ret = $self->provision($prefix,
1140 $dcvars->{SERVER_IP},
1141 $dcvars->{SERVER_IPV6},
1142 $extra_smb_conf, "", undef);
1147 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1148 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1149 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1150 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1151 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1153 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1155 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1156 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1157 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1158 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1159 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1161 unless (system($cmd) == 0) {
1162 warn("Join failed\n$cmd");
1166 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1167 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1168 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1169 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1170 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1171 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1173 $ret->{DOMSID} = $dcvars->{DOMSID};
1174 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1175 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1176 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1177 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1178 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1179 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1184 sub provision_rpc_proxy($$$)
1186 my ($self, $prefix, $dcvars) = @_;
1187 print "PROVISIONING RPC PROXY...\n";
1189 my $extra_smbconf_options = "
1190 passdb backend = samba_dsdb
1193 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1194 dcerpc endpoint servers = epmapper, remote
1195 dcerpc_remote:interfaces = rpcecho
1198 path = /tmp/_ignore_cifs_to_dc_/_none_
1200 ntvfs handler = cifs
1201 cifs:server = $dcvars->{SERVER}
1203 cifs:use-s4u2proxy = yes
1204 # There is no username specified here, instead the client is expected
1205 # to log in with kerberos, and the serverwill use delegated credentials.
1206 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1210 my $ret = $self->provision($prefix,
1217 $dcvars->{SERVER_IP},
1218 $dcvars->{SERVER_IPV6},
1219 $extra_smbconf_options, "", undef);
1224 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1226 # The joind runs in the context of the rpc_proxy/member for now
1227 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1228 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1229 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1230 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1232 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1234 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1235 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1236 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1237 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1238 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1240 unless (system($cmd) == 0) {
1241 warn("Join failed\n$cmd");
1245 # Setting up delegation runs in the context of the DC for now
1247 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1248 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1249 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1250 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1251 $cmd .= " $dcvars->{CONFIGURATION}";
1254 unless (system($cmd) == 0) {
1255 warn("Delegation failed\n$cmd");
1259 # Setting up delegation runs in the context of the DC for now
1261 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1262 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1263 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1264 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1265 $cmd .= " $dcvars->{CONFIGURATION}";
1267 unless (system($cmd) == 0) {
1268 warn("Delegation failed\n$cmd");
1272 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1273 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1274 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1275 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1276 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1277 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1279 $ret->{DOMSID} = $dcvars->{DOMSID};
1280 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1281 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1282 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1283 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1284 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1285 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1290 sub provision_promoted_dc($$$)
1292 my ($self, $prefix, $dcvars) = @_;
1293 print "PROVISIONING PROMOTED DC...\n";
1295 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1296 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1302 $dcvars->{PASSWORD},
1303 $dcvars->{SERVER_IP},
1304 $dcvars->{SERVER_IPV6});
1306 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1308 $ctx->{smb_conf_extra_options} = "
1310 server max protocol = SMB2
1312 ntlm auth = ntlmv2-only
1315 path = $ctx->{statedir}/sysvol
1319 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1324 my $ret = $self->provision_raw_step1($ctx);
1329 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1330 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1331 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1332 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1333 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1335 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1337 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1338 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1339 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1340 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1341 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1343 unless (system($cmd) == 0) {
1344 warn("Join failed\n$cmd");
1348 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1349 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1350 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1351 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1352 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1354 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1356 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1357 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1358 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1359 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1360 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1362 unless (system($cmd) == 0) {
1363 warn("Join failed\n$cmd");
1367 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1368 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1369 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1370 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1372 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1373 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1374 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1375 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1376 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1377 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1382 sub provision_vampire_dc($$$)
1384 my ($self, $prefix, $dcvars, $fl) = @_;
1385 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1386 my $name = "localvampiredc";
1387 my $extra_conf = "";
1389 if ($fl == "2000") {
1390 $name = "vampire2000dc";
1392 $extra_conf = "drs: immediate link sync = yes
1393 drs: max link sync = 250";
1396 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1397 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1403 $dcvars->{PASSWORD},
1404 $dcvars->{SERVER_IP},
1405 $dcvars->{SERVER_IPV6});
1407 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1409 $ctx->{smb_conf_extra_options} = "
1411 server max protocol = SMB2
1413 ntlm auth = mschapv2-and-ntlmv2-only
1417 path = $ctx->{statedir}/sysvol
1421 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1426 my $ret = $self->provision_raw_step1($ctx);
1431 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1432 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1433 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1434 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1435 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1437 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1439 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1440 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1441 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1442 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1443 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1444 $cmd .= " --backend-store=mdb";
1446 unless (system($cmd) == 0) {
1447 warn("Join failed\n$cmd");
1451 if ($fl == "2000") {
1452 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1453 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1454 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1455 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1457 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1458 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1459 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1460 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1462 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1463 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1464 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1465 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1466 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1467 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1468 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1473 sub provision_subdom_dc($$$)
1475 my ($self, $prefix, $dcvars) = @_;
1476 print "PROVISIONING SUBDOMAIN DC...\n";
1478 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1479 my $samsid = undef; # TODO pass the domain sid all the way down
1480 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1483 "sub.samba.example.com",
1486 $dcvars->{PASSWORD},
1489 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1491 $ctx->{smb_conf_extra_options} = "
1493 server max protocol = SMB2
1496 path = $ctx->{statedir}/sysvol
1500 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1505 my $ret = $self->provision_raw_step1($ctx);
1510 Samba::mk_krb5_conf($ctx);
1511 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1513 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1514 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1515 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1516 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1517 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1519 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1521 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1522 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1523 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1524 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1525 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1526 $cmd .= " --adminpass=$ret->{PASSWORD}";
1528 unless (system($cmd) == 0) {
1529 warn("Join failed\n$cmd");
1533 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1534 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1535 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1536 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1538 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1539 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1540 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1541 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1542 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1543 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1548 sub provision_ad_dc_ntvfs($$)
1550 my ($self, $prefix) = @_;
1552 # We keep the old 'winbind' name here in server services to
1553 # ensure upgrades which used that name still work with the now
1556 print "PROVISIONING AD DC (NTVFS)...\n";
1557 my $extra_conf_options = "netbios aliases = localDC1-a
1558 server services = +winbind -winbindd
1559 ldap server require strong auth = allow_sasl_over_tls
1560 allow nt4 crypto = yes
1561 raw NTLMv2 auth = yes
1562 lsa over netlogon = yes
1563 rpc server port = 1027
1564 auth event notification = true
1565 dsdb event notification = true
1566 dsdb password event notification = true
1567 dsdb group change notification = true
1568 server schannel = auto
1570 my $ret = $self->provision($prefix,
1571 "domain controller",
1574 "samba.example.com",
1579 $extra_conf_options,
1586 unless($self->add_wins_config("$prefix/private")) {
1587 warn("Unable to add wins configuration");
1590 $ret->{NETBIOSALIAS} = "localdc1-a";
1591 $ret->{DC_SERVER} = $ret->{SERVER};
1592 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1593 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1594 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1595 $ret->{DC_USERNAME} = $ret->{USERNAME};
1596 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1597 $ret->{DC_REALM} = $ret->{REALM};
1602 sub provision_fl2000dc($$)
1604 my ($self, $prefix) = @_;
1606 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1607 my $extra_conf_options = "
1608 spnego:simulate_w2k=yes
1609 ntlmssp_server:force_old_spnego=yes
1611 my $extra_provision_options = undef;
1612 # This environment uses plain text secrets
1613 # i.e. secret attributes are not encrypted on disk.
1614 # This allows testing of the --plaintext-secrets option for
1616 push (@{$extra_provision_options}, "--plaintext-secrets");
1617 my $ret = $self->provision($prefix,
1618 "domain controller",
1621 "samba2000.example.com",
1626 $extra_conf_options,
1628 $extra_provision_options);
1633 unless($self->add_wins_config("$prefix/private")) {
1634 warn("Unable to add wins configuration");
1637 $ret->{DC_SERVER} = $ret->{SERVER};
1638 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1639 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1640 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1641 $ret->{DC_USERNAME} = $ret->{USERNAME};
1642 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1643 $ret->{DC_REALM} = $ret->{REALM};
1648 sub provision_fl2003dc($$$)
1650 my ($self, $prefix, $dcvars) = @_;
1651 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1652 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1654 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1655 my $extra_conf_options = "allow dns updates = nonsecure and secure
1656 dcesrv:header signing = no
1657 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1658 my $ret = $self->provision($prefix,
1659 "domain controller",
1662 "samba2003.example.com",
1667 $extra_conf_options,
1670 unless (defined $ret) {
1674 $ret->{DC_SERVER} = $ret->{SERVER};
1675 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1676 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1677 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1678 $ret->{DC_USERNAME} = $ret->{USERNAME};
1679 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1680 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1681 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1683 my @samba_tool_options;
1684 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1685 push (@samba_tool_options, "domain");
1686 push (@samba_tool_options, "passwordsettings");
1687 push (@samba_tool_options, "set");
1688 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1689 push (@samba_tool_options, "--min-pwd-age=0");
1690 push (@samba_tool_options, "--history-length=1");
1692 my $samba_tool_cmd = join(" ", @samba_tool_options);
1694 unless (system($samba_tool_cmd) == 0) {
1695 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1699 unless($self->add_wins_config("$prefix/private")) {
1700 warn("Unable to add wins configuration");
1707 sub provision_fl2008r2dc($$$)
1709 my ($self, $prefix, $dcvars) = @_;
1711 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1712 my $extra_conf_options = "ldap server require strong auth = no";
1713 my $ret = $self->provision($prefix,
1714 "domain controller",
1717 "samba2008R2.example.com",
1722 $extra_conf_options,
1725 unless (defined $ret) {
1729 unless ($self->add_wins_config("$prefix/private")) {
1730 warn("Unable to add wins configuration");
1733 $ret->{DC_SERVER} = $ret->{SERVER};
1734 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1735 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1736 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1737 $ret->{DC_USERNAME} = $ret->{USERNAME};
1738 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1739 $ret->{DC_REALM} = $ret->{REALM};
1745 sub provision_rodc($$$)
1747 my ($self, $prefix, $dcvars) = @_;
1748 print "PROVISIONING RODC...\n";
1750 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1751 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1757 $dcvars->{PASSWORD},
1758 $dcvars->{SERVER_IP},
1759 $dcvars->{SERVER_IPV6});
1764 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1766 $ctx->{share} = "$ctx->{prefix_abs}/share";
1767 push(@{$ctx->{directories}}, "$ctx->{share}");
1769 $ctx->{smb_conf_extra_options} = "
1771 server max protocol = SMB2
1772 password server = $dcvars->{DC_SERVER}
1775 path = $ctx->{statedir}/sysvol
1779 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1783 path = $ctx->{share}
1785 posix:sharedelay = 10000
1786 posix:oplocktimeout = 3
1787 posix:writetimeupdatedelay = 50000
1791 my $ret = $self->provision_raw_step1($ctx);
1796 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1797 my $cmd = "NSS_WRAPPER_HOSTS='$ret->{NSS_WRAPPER_HOSTS}' ";
1798 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1799 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1800 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1802 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1804 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1805 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1806 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1807 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1808 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1810 unless (system($cmd) == 0) {
1811 warn("RODC join failed\n$cmd");
1815 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1816 # user password verified on the RODC
1817 my $testallowed_account = "testallowed account";
1818 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1819 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1820 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1821 $cmd .= " --server=$dcvars->{DC_SERVER}";
1823 unless (system($cmd) == 0) {
1824 warn("RODC join failed\n$cmd");
1828 # we overwrite the kdc after the RODC join
1829 # so that use the RODC as kdc and test
1831 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1832 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1833 Samba::mk_krb5_conf($ctx);
1834 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1836 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1837 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1838 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1839 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1841 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1842 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1843 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1844 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1845 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1846 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1851 sub read_config_h($)
1855 open(LF, "<$name") or die("unable to read $name: $!");
1858 next if not (/^#define /);
1859 if (/^#define (.*?)[ \t]+(.*?)$/) {
1863 if (/^#define (.*?)[ \t]+$/) {
1872 sub provision_ad_dc($$$$$$)
1874 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args,
1875 $extra_provision_options) = @_;
1877 my $prefix_abs = abs_path($prefix);
1879 my $bindir_abs = abs_path($self->{bindir});
1880 my $lockdir="$prefix_abs/lockdir";
1881 my $conffile="$prefix_abs/etc/smb.conf";
1883 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1884 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1888 if (defined($ENV{CONFIG_H})) {
1889 $config_h = read_config_h($ENV{CONFIG_H});
1892 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1893 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1895 my $extra_smbconf_options = "
1896 server services = -smb +s3fs
1897 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1899 dbwrap_tdb_mutexes:* = yes
1902 ${password_hash_gpg_key_ids}
1905 kernel change notify = no
1910 printcap name = /dev/null
1915 smbd:sharedelay = 100000
1916 smbd:writetimeupdatedelay = 500000
1919 check parent directory delete on close = yes
1921 dcerpc endpoint servers = -winreg -srvsvc
1923 printcap name = /dev/null
1925 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1926 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1929 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1930 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1931 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1932 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1933 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1934 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1935 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1937 print notify backchannel = yes
1939 server schannel = auto
1940 auth event notification = true
1941 dsdb event notification = true
1942 dsdb password event notification = true
1943 dsdb group change notification = true
1947 my $extra_smbconf_shares = "
1951 smb encrypt = required
1955 case sensitive = yes
1963 hide unreadable = yes
1967 kernel share modes = no
1986 push (@{$extra_provision_options}, "--backend-store=mdb");
1987 print "PROVISIONING AD DC...\n";
1988 my $ret = $self->provision($prefix,
1989 "domain controller",
1997 $extra_smbconf_options,
1998 $extra_smbconf_shares,
1999 $extra_provision_options);
2000 unless (defined $ret) {
2004 unless($self->add_wins_config("$prefix/private")) {
2005 warn("Unable to add wins configuration");
2009 $ret->{DC_SERVER} = $ret->{SERVER};
2010 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2011 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2012 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2013 $ret->{DC_USERNAME} = $ret->{USERNAME};
2014 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2019 sub provision_chgdcpass($$)
2021 my ($self, $prefix) = @_;
2023 print "PROVISIONING CHGDCPASS...\n";
2024 my $extra_provision_options = undef;
2025 # This environment disallows the use of this password
2026 # (and also removes the default AD complexity checks)
2027 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
2028 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
2029 my $ret = $self->provision($prefix,
2030 "domain controller",
2033 "chgdcpassword.samba.example.com",
2038 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
2040 $extra_provision_options);
2041 unless (defined $ret) {
2045 unless($self->add_wins_config("$prefix/private")) {
2046 warn("Unable to add wins configuration");
2050 # Remove secrets.tdb from this environment to test that we
2051 # still start up on systems without the new matching
2052 # secrets.tdb records.
2053 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
2054 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
2058 $ret->{DC_SERVER} = $ret->{SERVER};
2059 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
2060 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
2061 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
2062 $ret->{DC_USERNAME} = $ret->{USERNAME};
2063 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
2064 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
2069 sub teardown_env_terminate($$)
2071 my ($self, $envvars) = @_;
2074 # This should cause samba to terminate gracefully
2075 close($envvars->{STDIN_PIPE});
2077 $pid = $envvars->{SAMBA_PID};
2081 # This should give it time to write out the gcov data
2082 until ($count > 15) {
2083 if (Samba::cleanup_child($pid, "samba") != 0) {
2090 # After 15 Seconds, work out why this thing is still alive
2091 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
2092 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
2094 until ($count > 30) {
2095 if (Samba::cleanup_child($pid, "samba") != 0) {
2102 if (kill(0, $pid)) {
2103 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
2107 until ($count > 40) {
2108 if (Samba::cleanup_child($pid, "samba") != 0) {
2114 # If it is still around, kill it
2115 if (kill(0, $pid)) {
2116 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2122 sub teardown_env($$)
2124 my ($self, $envvars) = @_;
2125 teardown_env_terminate($self, $envvars);
2127 $self->slapd_stop($envvars) if ($self->{ldap});
2129 print $self->getlog_env($envvars);
2136 my ($self, $envvars) = @_;
2137 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2140 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2142 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2146 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2149 return "" if $out eq $title;
2156 my ($self, $envvars) = @_;
2157 my $samba_pid = $envvars->{SAMBA_PID};
2159 if (not defined($samba_pid)) {
2161 } elsif ($samba_pid > 0) {
2162 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2164 if ($childpid == 0) {
2173 # Declare the environments Samba4 makes available.
2174 # To be set up, they will be called as
2175 # samba4->setup_$envname($self, $path, $dep_1_vars, $dep_2_vars, ...)
2176 %Samba4::ENV_DEPS = (
2177 # name => [dep_1, dep_2, ...],
2181 ad_dc_no_ntlm => [],
2186 fl2008r2dc => ["ad_dc"],
2187 fl2003dc => ["ad_dc"],
2190 vampire_2000_dc => ["fl2000dc"],
2191 vampire_dc => ["ad_dc_ntvfs"],
2192 promoted_dc => ["ad_dc_ntvfs"],
2193 subdom_dc => ["ad_dc_ntvfs"],
2195 rodc => ["ad_dc_ntvfs"],
2196 rpc_proxy => ["ad_dc_ntvfs"],
2199 s4member_dflt_domain => ["ad_dc_ntvfs"],
2200 s4member => ["ad_dc_ntvfs"],
2202 restoredc => ["backupfromdc"],
2203 renamedc => ["backupfromdc"],
2204 offlinebackupdc => ["backupfromdc"],
2205 labdc => ["backupfromdc"],
2212 my ($self, $path, $dc_vars) = @_;
2214 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2217 if (not defined($self->check_or_start($env, "standard"))) {
2225 sub setup_s4member_dflt_domain
2227 my ($self, $path, $dc_vars) = @_;
2229 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2230 "winbind use default domain = yes");
2233 if (not defined($self->check_or_start($env, "standard"))) {
2243 my ($self, $path, $dc_vars) = @_;
2245 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2248 if (not defined($self->check_or_start($env, "standard"))) {
2255 sub setup_ad_dc_ntvfs
2257 my ($self, $path) = @_;
2259 my $env = $self->provision_ad_dc_ntvfs($path);
2261 if (not defined($self->check_or_start($env, "standard"))) {
2262 warn("Failed to start ad_dc_ntvfs");
2271 my ($self, $path) = @_;
2273 my $env = $self->provision_chgdcpass($path);
2275 if (not defined($self->check_or_start($env, "standard"))) {
2284 my ($self, $path) = @_;
2286 my $env = $self->provision_fl2000dc($path);
2288 if (not defined($self->check_or_start($env, "standard"))) {
2298 my ($self, $path, $dc_vars) = @_;
2300 my $env = $self->provision_fl2003dc($path);
2303 if (not defined($self->check_or_start($env, "standard"))) {
2307 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2312 sub setup_fl2008r2dc
2314 my ($self, $path, $dc_vars) = @_;
2316 my $env = $self->provision_fl2008r2dc($path);
2319 if (not defined($self->check_or_start($env, "standard"))) {
2323 my $upn_array = ["$env->{REALM}.upn"];
2324 my $spn_array = ["$env->{REALM}.spn"];
2326 $self->setup_namespaces($env, $upn_array, $spn_array);
2328 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2334 sub setup_vampire_dc
2336 return setup_generic_vampire_dc(@_, "2008");
2339 sub setup_vampire_2000_dc
2341 return setup_generic_vampire_dc(@_, "2000");
2344 sub setup_generic_vampire_dc
2346 my ($self, $path, $dc_vars, $fl) = @_;
2348 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2351 if (not defined($self->check_or_start($env, "single"))) {
2355 # force replicated DC to update repsTo/repsFrom
2356 # for vampired partitions
2357 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2359 # as 'vampired' dc may add data in its local replica
2360 # we need to synchronize data between DCs
2361 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2362 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2363 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2364 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2365 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2367 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2369 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2370 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2371 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2372 $cmd .= " $dc_vars->{CONFIGURATION}";
2373 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2374 # replicate Configuration NC
2375 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2376 unless(system($cmd_repl) == 0) {
2377 warn("Failed to replicate\n$cmd_repl");
2380 # replicate Default NC
2381 $cmd_repl = "$cmd \"$base_dn\"";
2382 unless(system($cmd_repl) == 0) {
2383 warn("Failed to replicate\n$cmd_repl");
2387 # Pull in a full set of changes from the main DC
2388 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2389 $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2390 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2391 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2392 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2394 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2396 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2397 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2398 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2399 $cmd .= " $dc_vars->{CONFIGURATION}";
2400 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2401 # replicate Configuration NC
2402 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2403 unless(system($cmd_repl) == 0) {
2404 warn("Failed to replicate\n$cmd_repl");
2407 # replicate Default NC
2408 $cmd_repl = "$cmd \"$base_dn\"";
2409 unless(system($cmd_repl) == 0) {
2410 warn("Failed to replicate\n$cmd_repl");
2418 sub setup_promoted_dc
2420 my ($self, $path, $dc_vars) = @_;
2422 my $env = $self->provision_promoted_dc($path, $dc_vars);
2425 if (not defined($self->check_or_start($env, "single"))) {
2429 # force source and replicated DC to update repsTo/repsFrom
2430 # for vampired partitions
2431 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2432 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2433 # as 'vampired' dc may add data in its local replica
2434 # we need to synchronize data between DCs
2435 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2436 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2437 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2438 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2439 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2440 $cmd .= " $dc_vars->{CONFIGURATION}";
2441 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2442 # replicate Configuration NC
2443 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2444 unless(system($cmd_repl) == 0) {
2445 warn("Failed to replicate\n$cmd_repl");
2448 # replicate Default NC
2449 $cmd_repl = "$cmd \"$base_dn\"";
2450 unless(system($cmd_repl) == 0) {
2451 warn("Failed to replicate\n$cmd_repl");
2461 my ($self, $path, $dc_vars) = @_;
2463 my $env = $self->provision_subdom_dc($path, $dc_vars);
2466 if (not defined($self->check_or_start($env, "single"))) {
2470 # force replicated DC to update repsTo/repsFrom
2471 # for primary domain partitions
2472 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2473 my $cmd = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2474 # as 'subdomain' dc may add data in its local replica
2475 # we need to synchronize data between DCs
2476 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2477 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2478 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2479 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2480 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2481 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2482 $cmd .= " $dc_vars->{CONFIGURATION}";
2483 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2484 # replicate Configuration NC
2485 my $cmd_repl = "$cmd \"$config_dn\"";
2486 unless(system($cmd_repl) == 0) {
2487 warn("Failed to replicate\n$cmd_repl");
2490 # replicate Default NC
2491 $cmd_repl = "$cmd \"$base_dn\"";
2492 unless(system($cmd_repl) == 0) {
2493 warn("Failed to replicate\n$cmd_repl");
2503 my ($self, $path, $dc_vars) = @_;
2505 my $env = $self->provision_rodc($path, $dc_vars);
2511 if (not defined($self->check_or_start($env, "standard"))) {
2515 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2518 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2519 $cmd .= "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2520 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2521 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2522 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2523 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2524 $cmd .= " $dc_vars->{CONFIGURATION}";
2525 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2526 # replicate Configuration NC
2527 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2528 unless(system($cmd_repl) == 0) {
2529 warn("Failed to replicate\n$cmd_repl");
2532 # replicate Default NC
2533 $cmd_repl = "$cmd \"$base_dn\"";
2534 unless(system($cmd_repl) == 0) {
2535 warn("Failed to replicate\n$cmd_repl");
2544 my ($self, $path) = @_;
2546 # If we didn't build with ADS, pretend this env was never available
2547 if (not $self->{target3}->have_ads()) {
2551 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2552 "addom.samba.example.com", "", undef);
2557 if (not defined($self->check_or_start($env, "prefork"))) {
2561 my $upn_array = ["$env->{REALM}.upn"];
2562 my $spn_array = ["$env->{REALM}.spn"];
2564 $self->setup_namespaces($env, $upn_array, $spn_array);
2569 sub setup_ad_dc_no_nss
2571 my ($self, $path) = @_;
2573 # If we didn't build with ADS, pretend this env was never available
2574 if (not $self->{target3}->have_ads()) {
2578 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2579 "adnonssdom.samba.example.com", "", undef);
2584 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2585 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2587 if (not defined($self->check_or_start($env, "single"))) {
2591 my $upn_array = ["$env->{REALM}.upn"];
2592 my $spn_array = ["$env->{REALM}.spn"];
2594 $self->setup_namespaces($env, $upn_array, $spn_array);
2599 sub setup_ad_dc_no_ntlm
2601 my ($self, $path) = @_;
2603 # If we didn't build with ADS, pretend this env was never available
2604 if (not $self->{target3}->have_ads()) {
2608 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2609 "adnontlmdom.samba.example.com",
2610 "ntlm auth = disabled", undef);
2615 if (not defined($self->check_or_start($env, "prefork"))) {
2619 my $upn_array = ["$env->{REALM}.upn"];
2620 my $spn_array = ["$env->{REALM}.spn"];
2622 $self->setup_namespaces($env, $upn_array, $spn_array);
2627 # Sets up a DC that's solely used to do a domain backup from. We then use the
2628 # backupfrom-DC to create the restore-DC - this proves that the backup/restore
2629 # process will create a Samba DC that will actually start up.
2630 # We don't use the backup-DC for anything else because its domain will conflict
2631 # with the restore DC.
2632 sub setup_backupfromdc
2634 my ($self, $path) = @_;
2636 # If we didn't build with ADS, pretend this env was never available
2637 if (not $self->{target3}->have_ads()) {
2641 my $provision_args = ["--site=Backup-Site"];
2643 my $env = $self->provision_ad_dc($path, "backupfromdc", "BACKUPDOMAIN",
2644 "backupdom.samba.example.com", "",
2650 if (not defined($self->check_or_start($env, "standard"))) {
2654 my $upn_array = ["$env->{REALM}.upn"];
2655 my $spn_array = ["$env->{REALM}.spn"];
2657 $self->setup_namespaces($env, $upn_array, $spn_array);
2662 # returns the server/user-auth params needed to run an online backup cmd
2663 sub get_backup_server_args
2665 # dcvars contains the env info for the backup DC testenv
2666 my ($self, $dcvars) = @_;
2667 my $server = $dcvars->{DC_SERVER_IP};
2668 my $server_args = "--server=$server ";
2669 $server_args .= "-U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
2671 return $server_args;
2674 # Creates a backup of a running testenv DC
2677 # note: dcvars contains the env info for the backup DC testenv
2678 my ($self, $env, $dcvars, $backupdir, $backup_cmd) = @_;
2680 # get all the env variables we pass in with the samba-tool command
2681 my $cmd_env = "NSS_WRAPPER_HOSTS='$env->{NSS_WRAPPER_HOSTS}' ";
2682 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2683 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2684 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2686 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2688 # Note: use the backupfrom-DC's krb5.conf to do the backup
2689 $cmd_env .= " KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
2690 $cmd_env .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2692 # use samba-tool to create a backup from the 'backupfromdc' DC
2694 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2696 $cmd .= "$cmd_env $samba_tool domain backup $backup_cmd";
2697 $cmd .= " --targetdir=$backupdir";
2699 print "Executing: $cmd\n";
2700 unless(system($cmd) == 0) {
2701 warn("Failed to create backup using: \n$cmd");
2705 # get the name of the backup file created
2706 opendir(DIR, $backupdir);
2707 my @files = grep(/\.tar/, readdir(DIR));
2710 if(scalar @files != 1) {
2711 warn("Backup file not found in directory $backupdir\n");
2714 my $backup_file = "$backupdir/$files[0]";
2715 print "Using backup file $backup_file...\n";
2717 return $backup_file;
2720 # Restores a backup-file to populate a testenv for a new DC
2721 sub restore_backup_file
2723 my ($self, $backup_file, $restore_opts, $restoredir, $smbconf) = @_;
2725 # pass the restore command the testenv's smb.conf that we've already
2726 # generated. But move it to a temp-dir first, so that the restore doesn't
2728 my $tmpdir = File::Temp->newdir();
2729 my $tmpconf = "$tmpdir/smb.conf";
2730 my $cmd = "cp $smbconf $tmpconf";
2731 unless(system($cmd) == 0) {
2732 warn("Failed to backup smb.conf using: \n$cmd");
2736 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2737 $cmd = "$samba_tool domain backup restore --backup-file=$backup_file";
2738 $cmd .= " --targetdir=$restoredir $restore_opts --configfile=$tmpconf";
2740 print "Executing: $cmd\n";
2741 unless(system($cmd) == 0) {
2742 warn("Failed to restore backup using: \n$cmd");
2746 print "Restore complete\n";
2750 # sets up the initial directory and returns the new testenv's env info
2751 # (without actually doing a 'domain join')
2752 sub prepare_dc_testenv
2754 my ($self, $prefix, $dcname, $domain, $realm, $password) = @_;
2756 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
2766 # the restore uses a slightly different state-dir location to other testenvs
2767 $ctx->{statedir} = "$ctx->{prefix_abs}/state";
2768 push(@{$ctx->{directories}}, "$ctx->{statedir}");
2770 # add support for sysvol/netlogon/tmp shares
2771 $ctx->{share} = "$ctx->{prefix_abs}/share";
2772 push(@{$ctx->{directories}}, "$ctx->{share}");
2774 $ctx->{smb_conf_extra_options} = "
2776 server max protocol = SMB2
2779 path = $ctx->{statedir}/sysvol
2783 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
2787 path = $ctx->{share}
2789 posix:sharedelay = 10000
2790 posix:oplocktimeout = 3
2791 posix:writetimeupdatedelay = 50000
2795 my $env = $self->provision_raw_step1($ctx);
2797 $env->{DC_SERVER} = $env->{SERVER};
2798 $env->{DC_SERVER_IP} = $env->{SERVER_IP};
2799 $env->{DC_SERVER_IPV6} = $env->{SERVER_IPV6};
2800 $env->{DC_NETBIOSNAME} = $env->{NETBIOSNAME};
2801 $env->{DC_USERNAME} = $env->{USERNAME};
2802 $env->{DC_PASSWORD} = $env->{PASSWORD};
2804 return ($env, $ctx);
2808 # Set up a DC testenv solely by using the samba-tool domain backup/restore
2809 # commands. This proves that we can backup an online DC ('backupfromdc') and
2810 # use the backup file to create a valid, working samba DC.
2813 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2814 my ($self, $prefix, $dcvars) = @_;
2815 print "Preparing RESTORE DC...\n";
2817 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "restoredc",
2820 $dcvars->{PASSWORD});
2822 # create a backup of the 'backupfromdc'
2823 my $backupdir = File::Temp->newdir();
2824 my $server_args = $self->get_backup_server_args($dcvars);
2825 my $backup_args = "online $server_args";
2826 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2828 unless($backup_file) {
2832 # restore the backup file to populate the restore-DC testenv
2833 my $restore_dir = abs_path($prefix);
2834 my $ret = $self->restore_backup_file($backup_file,
2835 "--newservername=$env->{SERVER}",
2836 $restore_dir, $env->{SERVERCONFFILE});
2837 unless ($ret == 0) {
2841 # start samba for the restored DC
2842 if (not defined($self->check_or_start($env, "standard"))) {
2849 # Set up a DC testenv solely by using the 'samba-tool domain backup rename' and
2850 # restore commands. This proves that we can backup and rename an online DC
2851 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2854 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2855 my ($self, $prefix, $dcvars) = @_;
2856 print "Preparing RENAME DC...\n";
2858 my $realm = "renamedom.samba.example.com";
2859 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "renamedc",
2860 "RENAMEDOMAIN", $realm,
2861 $dcvars->{PASSWORD});
2863 # create a backup of the 'backupfromdc' which renames the domain
2864 my $backupdir = File::Temp->newdir();
2865 my $server_args = $self->get_backup_server_args($dcvars);
2866 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2867 $backup_args .= " --backend-store=tdb";
2868 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2870 unless($backup_file) {
2874 # restore the backup file to populate the rename-DC testenv
2875 my $restore_dir = abs_path($prefix);
2876 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2877 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2878 $restore_dir, $env->{SERVERCONFFILE});
2879 unless ($ret == 0) {
2883 # start samba for the restored DC
2884 if (not defined($self->check_or_start($env, "standard"))) {
2888 my $upn_array = ["$env->{REALM}.upn"];
2889 my $spn_array = ["$env->{REALM}.spn"];
2891 $self->setup_namespaces($env, $upn_array, $spn_array);
2896 # Set up a DC testenv solely by using the 'samba-tool domain backup offline' and
2897 # restore commands. This proves that we do an offline backup of a local DC
2898 # ('backupfromdc') and use the backup file to create a valid, working samba DC.
2899 sub setup_offlinebackupdc
2901 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2902 my ($self, $prefix, $dcvars) = @_;
2903 print "Preparing OFFLINE BACKUP DC...\n";
2905 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "offlinebackupdc",
2908 $dcvars->{PASSWORD});
2910 # create an offline backup of the 'backupfromdc' target
2911 my $backupdir = File::Temp->newdir();
2912 my $cmd = "offline -s $dcvars->{SERVERCONFFILE}";
2913 my $backup_file = $self->create_backup($env, $dcvars,
2916 unless($backup_file) {
2920 # restore the backup file to populate the rename-DC testenv
2921 my $restore_dir = abs_path($prefix);
2922 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2923 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2924 $restore_dir, $env->{SERVERCONFFILE});
2925 unless ($ret == 0) {
2929 # re-create the testenv's krb5.conf (the restore may have overwritten it)
2930 Samba::mk_krb5_conf($ctx);
2932 # start samba for the restored DC
2933 if (not defined($self->check_or_start($env, "standard"))) {
2940 # Set up a DC testenv solely by using the samba-tool 'domain backup rename' and
2941 # restore commands, using the --no-secrets option. This proves that we can
2942 # create a realistic lab environment from an online DC ('backupfromdc').
2945 # note: dcvars contains the env info for the dependent testenv ('backupfromdc')
2946 my ($self, $prefix, $dcvars) = @_;
2947 print "Preparing LAB-DOMAIN DC...\n";
2949 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, "labdc",
2951 "labdom.samba.example.com",
2952 $dcvars->{PASSWORD});
2954 # create a backup of the 'backupfromdc' which renames the domain and uses
2955 # the --no-secrets option to scrub any sensitive info
2956 my $backupdir = File::Temp->newdir();
2957 my $server_args = $self->get_backup_server_args($dcvars);
2958 my $backup_args = "rename $env->{DOMAIN} $env->{REALM} $server_args";
2959 $backup_args .= " --no-secrets --backend-store=mdb";
2960 my $backup_file = $self->create_backup($env, $dcvars, $backupdir,
2962 unless($backup_file) {
2966 # restore the backup file to populate the lab-DC testenv
2967 my $restore_dir = abs_path($prefix);
2968 my $restore_opts = "--newservername=$env->{SERVER} --host-ip=$env->{SERVER_IP}";
2969 my $ret = $self->restore_backup_file($backup_file, $restore_opts,
2970 $restore_dir, $env->{SERVERCONFFILE});
2971 unless ($ret == 0) {
2975 # because we don't include any secrets in the backup, we need to reset the
2976 # admin user's password back to what the testenv expects
2977 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2978 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
2979 $cmd .= "--newpassword=$env->{PASSWORD} -H $restore_dir/private/sam.ldb";
2981 unless(system($cmd) == 0) {
2982 warn("Failed to reset admin's password: \n$cmd");
2986 # start samba for the restored DC
2987 if (not defined($self->check_or_start($env, "standard"))) {
2991 my $upn_array = ["$env->{REALM}.upn"];
2992 my $spn_array = ["$env->{REALM}.spn"];
2994 $self->setup_namespaces($env, $upn_array, $spn_array);
2999 # Inspects a backup *.tar.bz2 file and determines the realm/domain it contains
3000 sub get_backup_domain_realm
3002 my ($self, $backup_file) = @_;
3004 print "Determining REALM/DOMAIN values in backup...\n";
3006 # The backup will have the correct domain/realm values in the smb.conf.
3007 # So we can work out the env variables the testenv should use based on
3008 # that. Let's start by extracting the smb.conf
3009 my $tar = Archive::Tar->new($backup_file);
3010 my $tmpdir = File::Temp->newdir();
3011 my $smbconf = "$tmpdir/smb.conf";
3013 # note that the filepaths within the tar-file differ slightly for online
3014 # and offline backups
3015 if ($tar->contains_file("etc/smb.conf")) {
3016 $tar->extract_file("etc/smb.conf", $smbconf);
3017 } elsif ($tar->contains_file("./etc/smb.conf")) {
3018 $tar->extract_file("./etc/smb.conf", $smbconf);
3020 warn("Could not find smb.conf in $backup_file");
3021 return undef, undef;
3024 # now use testparm to read the values we're interested in
3025 my $testparm = Samba::bindir_path($self, "testparm");
3026 my $domain = `$testparm $smbconf -sl --parameter-name=WORKGROUP`;
3027 my $realm = `$testparm $smbconf -sl --parameter-name=REALM`;
3030 print "Backup-file REALM is $realm, DOMAIN is $domain\n";
3032 return ($domain, $realm);
3035 # This spins up a custom testenv that can be based on any backup-file you want.
3036 # This is just intended for manual testing (rather than automated test-cases)
3039 my ($self, $prefix) = @_;
3040 print "Preparing CUSTOM RESTORE DC...\n";
3041 my $dc_name = "customdc";
3042 my $password = "locDCpass1";
3043 my $backup_file = $ENV{'BACKUP_FILE'};
3045 # user must specify a backup file to restore via an ENV variable, i.e.
3046 # BACKUP_FILE=backup-blah.tar.bz2 SELFTEST_TESTENV=customdc make testenv
3047 if (not defined($backup_file)) {
3048 warn("Please specify BACKUP_FILE");
3052 # work out the correct domain/realm env values from the backup-file
3053 my ($domain, $realm) = $self->get_backup_domain_realm($backup_file);
3055 # create a placeholder directory and smb.conf, as well as the env vars.
3056 my ($env, $ctx) = $self->prepare_dc_testenv($prefix, $dc_name,
3057 $domain, $realm, $password);
3059 # restore the specified backup file to populate the testenv
3060 my $restore_dir = abs_path($prefix);
3061 my $ret = $self->restore_backup_file($backup_file,
3062 "--newservername=$env->{SERVER}",
3063 $restore_dir, $env->{SERVERCONFFILE});
3064 unless ($ret == 0) {
3068 # Change the admin password to the testenv default, just in case it's
3069 # different, or in case this was a --no-secrets backup
3070 my $samba_tool = Samba::bindir_path($self, "samba-tool");
3071 my $cmd = "$samba_tool user setpassword $env->{USERNAME} ";
3072 $cmd .= "--newpassword=$password -H $restore_dir/private/sam.ldb";
3074 unless(system($cmd) == 0) {
3075 warn("Failed to reset admin's password: \n$cmd");
3079 # re-create the testenv's krb5.conf (the restore may have overwritten it,
3080 # if the backup-file was an offline backup)
3081 Samba::mk_krb5_conf($ctx);
3083 # start samba for the restored DC
3084 if (not defined($self->check_or_start($env, "standard"))) {
3088 # if this was a backup-rename, then we may need to setup namespaces
3089 my $upn_array = ["$env->{REALM}.upn"];
3090 my $spn_array = ["$env->{REALM}.spn"];
3092 $self->setup_namespaces($env, $upn_array, $spn_array);
3099 my ($self, $path) = @_;
3102 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",