replmd: Refactor adding the backlink in replmd_process_linked_attribute()
[Samba.git] / selftest / target / Samba4.pm
blob8b2af7ff063054c0fbd875fdb2f77cf67ea596b1
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
6 package Samba4;
8 use strict;
9 use Cwd qw(abs_path);
10 use FindBin qw($RealBin);
11 use POSIX;
12 use SocketWrapper;
13 use target::Samba;
14 use target::Samba3;
16 sub new($$$$$) {
17 my ($classname, $bindir, $ldap, $srcdir, $server_maxtime) = @_;
19 my $self = {
20 vars => {},
21 ldap => $ldap,
22 bindir => $bindir,
23 srcdir => $srcdir,
24 server_maxtime => $server_maxtime,
25 target3 => new Samba3($bindir, $srcdir, $server_maxtime)
27 bless $self;
28 return $self;
31 sub scriptdir_path($$) {
32 my ($self, $path) = @_;
33 return "$self->{srcdir}/source4/scripting/$path";
36 sub openldap_start($$$) {
39 sub slapd_start($$)
41 my $count = 0;
42 my ($self, $env_vars, $STDIN_READER) = @_;
43 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
45 my $uri = $env_vars->{LDAP_URI};
47 if (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") == 0) {
48 print "A SLAPD is still listening to $uri before we started the LDAP backend. Aborting!";
49 return 1;
51 # running slapd in the background means it stays in the same process group, so it can be
52 # killed by timelimit
53 my $pid = fork();
54 if ($pid == 0) {
55 open STDOUT, ">$env_vars->{LDAPDIR}/logs";
56 open STDERR, '>&STDOUT';
57 close($env_vars->{STDIN_PIPE});
58 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
60 if ($self->{ldap} eq "fedora-ds") {
61 exec("$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd", "-D", $env_vars->{FEDORA_DS_DIR}, "-d0", "-i", $env_vars->{FEDORA_DS_PIDFILE});
62 } elsif ($self->{ldap} eq "openldap") {
63 exec($ENV{OPENLDAP_SLAPD}, "-dnone", "-F", $env_vars->{SLAPD_CONF_D}, "-h", $uri);
65 die("Unable to start slapd: $!");
67 $env_vars->{SLAPD_PID} = $pid;
68 sleep(1);
69 while (system("$ldbsearch -H $uri -s base -b \"\" supportedLDAPVersion > /dev/null") != 0) {
70 $count++;
71 if ($count > 40) {
72 $self->slapd_stop($env_vars);
73 return 0;
75 sleep(1);
77 return 1;
80 sub slapd_stop($$)
82 my ($self, $envvars) = @_;
83 kill 9, $envvars->{SLAPD_PID};
84 return 1;
87 sub check_or_start($$$)
89 my ($self, $env_vars, $process_model) = @_;
90 my $STDIN_READER;
92 my $env_ok = $self->check_env($env_vars);
93 if ($env_ok) {
94 return $env_vars->{SAMBA_PID};
95 } elsif (defined($env_vars->{SAMBA_PID})) {
96 warn("SAMBA PID $env_vars->{SAMBA_PID} is not running (died)");
97 return undef;
100 # use a pipe for stdin in the child processes. This allows
101 # those processes to monitor the pipe for EOF to ensure they
102 # exit when the test script exits
103 pipe($STDIN_READER, $env_vars->{STDIN_PIPE});
105 # Start slapd before samba, but with the fifo on stdin
106 if (defined($self->{ldap})) {
107 unless($self->slapd_start($env_vars, $STDIN_READER)) {
108 warn("couldn't start slapd (main run)");
109 return undef;
113 print "STARTING SAMBA...\n";
114 my $pid = fork();
115 if ($pid == 0) {
116 # we want out from samba to go to the log file, but also
117 # to the users terminal when running 'make test' on the command
118 # line. This puts it on stderr on the terminal
119 open STDOUT, "| tee $env_vars->{SAMBA_TEST_LOG} 1>&2";
120 open STDERR, '>&STDOUT';
122 SocketWrapper::set_default_iface($env_vars->{SOCKET_WRAPPER_DEFAULT_IFACE});
124 $ENV{KRB5_CONFIG} = $env_vars->{KRB5_CONFIG};
125 $ENV{KRB5CCNAME} = "$env_vars->{KRB5_CCACHE}.samba";
126 if (defined($ENV{MITKRB5})) {
127 $ENV{KRB5_KDC_PROFILE} = $env_vars->{MITKDC_CONFIG};
129 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
130 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
132 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
133 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
134 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
135 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
136 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
137 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
139 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
140 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
141 } else {
142 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
145 $ENV{UID_WRAPPER} = "1";
146 $ENV{UID_WRAPPER_ROOT} = "1";
148 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
149 my @preargs = ();
150 my @optargs = ();
151 if (defined($ENV{SAMBA_OPTIONS})) {
152 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
154 if(defined($ENV{SAMBA_VALGRIND})) {
155 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
158 close($env_vars->{STDIN_PIPE});
159 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
161 exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--no-process-group", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
163 $env_vars->{SAMBA_PID} = $pid;
164 print "DONE ($pid)\n";
166 close($STDIN_READER);
168 if ($self->wait_for_start($env_vars) != 0) {
169 warn("Samba $pid failed to start up");
170 return undef;
173 return $pid;
176 sub wait_for_start($$)
178 my ($self, $testenv_vars) = @_;
179 my $count = 0;
180 my $ret = 0;
182 if (not $self->check_env($testenv_vars)) {
183 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
184 return -1;
187 # This will return quickly when things are up, but be slow if we
188 # need to wait for (eg) SSL init
189 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
191 do {
192 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
193 if ($ret != 0) {
194 sleep(1);
195 } else {
196 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
199 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
200 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
201 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
202 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
204 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
205 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
206 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
208 $count++;
209 } while ($ret != 0 && $count < 20);
210 if ($count == 20) {
211 warn("nbt not reachable after 20 retries\n");
212 teardown_env($self, $testenv_vars);
213 return 0;
216 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
217 if ($testenv_vars->{SERVER_ROLE} eq "domain controller") {
218 # Add hosts file for name lookups
219 $ENV{NSS_WRAPPER_HOSTS} = $testenv_vars->{NSS_WRAPPER_HOSTS};
220 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
221 $ENV{RESOLV_WRAPPER_CONF} = $testenv_vars->{RESOLV_WRAPPER_CONF};
222 } else {
223 $ENV{RESOLV_WRAPPER_HOSTS} = $testenv_vars->{RESOLV_WRAPPER_HOSTS};
226 print "waiting for working LDAP and a RID Set to be allocated\n";
227 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
228 my $count = 0;
229 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
231 my $search_dn = $base_dn;
232 if ($testenv_vars->{NETBIOSNAME} ne "RODC") {
233 # TODO currently no check for actual rIDAllocationPool
234 $search_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
236 my $max_wait = 60;
237 my $cmd = "$ldbsearch $testenv_vars->{CONFIGURATION} -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$search_dn\"";
238 while (system("$cmd >/dev/null") != 0) {
239 $count++;
240 if ($count > $max_wait) {
241 warn("Timed out ($max_wait sec) waiting for working LDAP and a RID Set to be allocated by $testenv_vars->{NETBIOSNAME} PID $testenv_vars->{SAMBA_PID}");
242 $ret = -1;
243 last;
245 sleep(1);
249 my $wbinfo = Samba::bindir_path($self, "wbinfo");
251 $count = 0;
252 do {
253 my $cmd = "NSS_WRAPPER_PASSWD=$testenv_vars->{NSS_WRAPPER_PASSWD} ";
254 $cmd .= "NSS_WRAPPER_GROUP=$testenv_vars->{NSS_WRAPPER_GROUP} ";
255 $cmd .= "SELFTEST_WINBINDD_SOCKET_DIR=$testenv_vars->{SELFTEST_WINBINDD_SOCKET_DIR} ";
256 $cmd .= "$wbinfo -p";
257 $ret = system($cmd);
259 if ($ret != 0) {
260 sleep(1);
262 $count++;
263 } while ($ret != 0 && $count < 20);
264 if ($count == 20) {
265 warn("winbind not reachable after 20 retries\n");
266 teardown_env($self, $testenv_vars);
267 return 0;
270 print $self->getlog_env($testenv_vars);
272 return $ret
275 sub write_ldb_file($$$)
277 my ($self, $file, $ldif) = @_;
279 my $ldbadd = Samba::bindir_path($self, "ldbadd");
280 open(LDIF, "|$ldbadd -H $file >/dev/null");
281 print LDIF $ldif;
282 return(close(LDIF));
285 sub add_wins_config($$)
287 my ($self, $privatedir) = @_;
289 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
290 dn: name=TORTURE_11,CN=PARTNERS
291 objectClass: wreplPartner
292 name: TORTURE_11
293 address: 127.0.0.11
294 pullInterval: 0
295 pushChangeCount: 0
296 type: 0x3
300 sub mk_fedora_ds($$)
302 my ($self, $ctx) = @_;
304 #Make the subdirectory be as fedora DS would expect
305 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
307 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
309 return ($fedora_ds_dir, $pidfile);
312 sub mk_openldap($$)
314 my ($self, $ctx) = @_;
316 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
317 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
319 return ($slapd_conf_d, $pidfile);
322 sub setup_namespaces($$:$$)
324 my ($self, $localenv, $upn_array, $spn_array) = @_;
326 @{$upn_array} = [] unless defined($upn_array);
327 my $upn_args = "";
328 foreach my $upn (@{$upn_array}) {
329 $upn_args .= " --add-upn-suffix=$upn";
332 @{$spn_array} = [] unless defined($spn_array);
333 my $spn_args = "";
334 foreach my $spn (@{$spn_array}) {
335 $spn_args .= " --add-spn-suffix=$spn";
338 my $samba_tool = Samba::bindir_path($self, "samba-tool");
340 my $cmd_env = "";
341 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
342 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
343 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
344 } else {
345 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
347 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
348 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
350 my $cmd_config = " $localenv->{CONFIGURATION}";
352 my $namespaces = $cmd_env;
353 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
354 $namespaces .= $cmd_config;
355 unless (system($namespaces) == 0) {
356 warn("Failed to add namespaces \n$namespaces");
357 return;
360 return;
363 sub setup_trust($$$$$)
365 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
367 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
368 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
369 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
370 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
371 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
372 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
373 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
374 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
376 my $samba_tool = Samba::bindir_path($self, "samba-tool");
377 # setup the trust
378 my $cmd_env = "";
379 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
380 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
381 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
382 } else {
383 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
385 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
386 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
388 my $cmd_config = " $localenv->{CONFIGURATION}";
389 my $cmd_creds = $cmd_config;
390 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
392 my $create = $cmd_env;
393 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
394 $create .= " $extra_args";
395 $create .= $cmd_creds;
396 unless (system($create) == 0) {
397 warn("Failed to create trust \n$create");
398 return undef;
401 return $localenv
404 sub provision_raw_prepare($$$$$$$$$$$)
406 my ($self, $prefix, $server_role, $hostname,
407 $domain, $realm, $functional_level,
408 $password, $kdc_ipv4, $kdc_ipv6) = @_;
409 my $ctx;
410 my $netbiosname = uc($hostname);
412 unless(-d $prefix or mkdir($prefix, 0777)) {
413 warn("Unable to create $prefix");
414 return undef;
416 my $prefix_abs = abs_path($prefix);
418 die ("prefix=''") if $prefix_abs eq "";
419 die ("prefix='/'") if $prefix_abs eq "/";
421 unless (system("rm -rf $prefix_abs/*") == 0) {
422 warn("Unable to clean up");
426 my $swiface = Samba::get_interface($hostname);
428 $ctx->{prefix} = $prefix;
429 $ctx->{prefix_abs} = $prefix_abs;
431 $ctx->{server_role} = $server_role;
432 $ctx->{hostname} = $hostname;
433 $ctx->{netbiosname} = $netbiosname;
434 $ctx->{swiface} = $swiface;
435 $ctx->{password} = $password;
436 $ctx->{kdc_ipv4} = $kdc_ipv4;
437 $ctx->{kdc_ipv6} = $kdc_ipv6;
438 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
439 if ($functional_level eq "2000") {
440 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
444 # Set smbd log level here.
446 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
447 $ctx->{username} = "Administrator";
448 $ctx->{domain} = $domain;
449 $ctx->{realm} = uc($realm);
450 $ctx->{dnsname} = lc($realm);
452 $ctx->{functional_level} = $functional_level;
454 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
455 chomp $unix_name;
456 $ctx->{unix_name} = $unix_name;
457 $ctx->{unix_uid} = $>;
458 my @mygid = split(" ", $();
459 $ctx->{unix_gid} = $mygid[0];
460 $ctx->{unix_gids_str} = $);
461 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
463 $ctx->{etcdir} = "$prefix_abs/etc";
464 $ctx->{piddir} = "$prefix_abs/pid";
465 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
466 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
467 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
468 $ctx->{mitkdc_conf} = "$ctx->{etcdir}/mitkdc.conf";
469 $ctx->{privatedir} = "$prefix_abs/private";
470 $ctx->{binddnsdir} = "$prefix_abs/bind-dns";
471 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
472 $ctx->{lockdir} = "$prefix_abs/lockdir";
473 $ctx->{logdir} = "$prefix_abs/logs";
474 $ctx->{statedir} = "$prefix_abs/statedir";
475 $ctx->{cachedir} = "$prefix_abs/cachedir";
476 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
477 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
478 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
479 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
480 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
481 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
482 if ($ENV{SAMBA_DNS_FAKING}) {
483 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
484 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
485 } else {
486 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
487 $ctx->{use_resolv_wrapper} = 1;
489 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
491 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
493 $ctx->{ipv4} = "127.0.0.$swiface";
494 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
495 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
497 push(@{$ctx->{directories}}, $ctx->{privatedir});
498 push(@{$ctx->{directories}}, $ctx->{binddnsdir});
499 push(@{$ctx->{directories}}, $ctx->{etcdir});
500 push(@{$ctx->{directories}}, $ctx->{piddir});
501 push(@{$ctx->{directories}}, $ctx->{lockdir});
502 push(@{$ctx->{directories}}, $ctx->{logdir});
503 push(@{$ctx->{directories}}, $ctx->{statedir});
504 push(@{$ctx->{directories}}, $ctx->{cachedir});
506 $ctx->{smb_conf_extra_options} = "";
508 my @provision_options = ();
509 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
510 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
511 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
512 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
513 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
514 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
515 if (defined($ctx->{use_resolv_wrapper})) {
516 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
517 } else {
518 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
520 if (defined($ENV{GDB_PROVISION})) {
521 push (@provision_options, "gdb --args");
522 if (!defined($ENV{PYTHON})) {
523 push (@provision_options, "env");
524 push (@provision_options, "python");
527 if (defined($ENV{VALGRIND_PROVISION})) {
528 push (@provision_options, "valgrind");
529 if (!defined($ENV{PYTHON})) {
530 push (@provision_options, "env");
531 push (@provision_options, "python");
534 if (defined($ENV{PYTHON})) {
535 push (@provision_options, $ENV{PYTHON});
537 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
538 push (@provision_options, "domain");
539 push (@provision_options, "provision");
540 push (@provision_options, "--configfile=$ctx->{smb_conf}");
541 push (@provision_options, "--host-name=$ctx->{hostname}");
542 push (@provision_options, "--host-ip=$ctx->{ipv4}");
543 push (@provision_options, "--quiet");
544 push (@provision_options, "--domain=$ctx->{domain}");
545 push (@provision_options, "--realm=$ctx->{realm}");
546 push (@provision_options, "--adminpass=$ctx->{password}");
547 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
548 push (@provision_options, "--machinepass=machine$ctx->{password}");
549 push (@provision_options, "--root=$ctx->{unix_name}");
550 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
551 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
553 @{$ctx->{provision_options}} = @provision_options;
555 return $ctx;
559 # Step1 creates the basic configuration
561 sub provision_raw_step1($$)
563 my ($self, $ctx) = @_;
565 mkdir($_, 0777) foreach (@{$ctx->{directories}});
568 ## lockdir and piddir must be 0755
570 chmod 0755, $ctx->{lockdir};
571 chmod 0755, $ctx->{piddir};
573 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
574 warn("can't open $ctx->{smb_conf}$?");
575 return undef;
578 Samba::prepare_keyblobs($ctx);
579 my $crlfile = "$ctx->{tlsdir}/crl.pem";
580 $crlfile = "" unless -e ${crlfile};
582 print CONFFILE "
583 [global]
584 netbios name = $ctx->{netbiosname}
585 posix:eadb = $ctx->{statedir}/eadb.tdb
586 workgroup = $ctx->{domain}
587 realm = $ctx->{realm}
588 private dir = $ctx->{privatedir}
589 binddns dir = $ctx->{binddnsdir}
590 pid directory = $ctx->{piddir}
591 ncalrpc dir = $ctx->{ncalrpcdir}
592 lock dir = $ctx->{lockdir}
593 state directory = $ctx->{statedir}
594 cache directory = $ctx->{cachedir}
595 winbindd socket directory = $ctx->{winbindd_socket_dir}
596 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
597 winbind separator = /
598 interfaces = $ctx->{interfaces}
599 tls dh params file = $ctx->{tlsdir}/dhparms.pem
600 tls crlfile = ${crlfile}
601 tls verify peer = no_check
602 panic action = $RealBin/gdb_backtrace \%d
603 wins support = yes
604 server role = $ctx->{server_role}
605 server services = +echo +smb -s3fs
606 dcerpc endpoint servers = +winreg +srvsvc
607 notify:inotify = false
608 ldb:nosync = true
609 ldap server require strong auth = yes
610 #We don't want to pass our self-tests if the PAC code is wrong
611 gensec:require_pac = true
612 log file = $ctx->{logdir}/log.\%m
613 log level = $ctx->{server_loglevel}
614 lanman auth = Yes
615 ntlm auth = Yes
616 rndc command = true
617 dns update command = $ctx->{samba_dnsupdate}
618 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
619 dreplsrv:periodic_startup_interval = 0
620 dsdb:schema update allowed = yes
622 prefork children = 4
624 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
626 idmap_ldb:use rfc2307=yes
627 winbind enum users = yes
628 winbind enum groups = yes
630 rpc server port:netlogon = 1026
634 print CONFFILE "
636 # Begin extra options
637 $ctx->{smb_conf_extra_options}
638 # End extra options
640 close(CONFFILE);
642 #Default the KDC IP to the server's IP
643 if (not defined($ctx->{kdc_ipv4})) {
644 $ctx->{kdc_ipv4} = $ctx->{ipv4};
646 if (not defined($ctx->{kdc_ipv6})) {
647 $ctx->{kdc_ipv6} = $ctx->{ipv6};
650 Samba::mk_krb5_conf($ctx);
651 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
653 open(PWD, ">$ctx->{nsswrap_passwd}");
654 if ($ctx->{unix_uid} != 0) {
655 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
657 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
658 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
659 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
660 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
661 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
662 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
664 close(PWD);
665 my $uid_rfc2307test = 65533;
667 open(GRP, ">$ctx->{nsswrap_group}");
668 if ($ctx->{unix_gid} != 0) {
669 print GRP "root:x:0:\n";
671 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
672 print GRP "wheel:x:10:
673 users:x:65531:
674 nobody:x:65533:
675 nogroup:x:65534:nobody
677 close(GRP);
678 my $gid_rfc2307test = 65532;
680 my $hostname = lc($ctx->{hostname});
681 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
682 if ($hostname eq "localdc") {
683 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
684 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
685 } else {
686 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
687 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
689 close(HOSTS);
691 if (defined($ctx->{resolv_conf})) {
692 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
693 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
694 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
695 close(RESOLV_CONF);
698 my $configuration = "--configfile=$ctx->{smb_conf}";
700 #Ensure the config file is valid before we start
701 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
702 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
703 system("$testparm -v --suppress-prompt $configuration >&2");
704 warn("Failed to create a valid smb.conf configuration $testparm!");
705 return undef;
707 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) {
708 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
709 return undef;
712 my $ret = {
713 KRB5_CONFIG => $ctx->{krb5_conf},
714 KRB5_CCACHE => $ctx->{krb5_ccache},
715 MITKDC_CONFIG => $ctx->{mitkdc_conf},
716 PIDDIR => $ctx->{piddir},
717 SERVER => $ctx->{hostname},
718 SERVER_IP => $ctx->{ipv4},
719 SERVER_IPV6 => $ctx->{ipv6},
720 NETBIOSNAME => $ctx->{netbiosname},
721 DOMAIN => $ctx->{domain},
722 USERNAME => $ctx->{username},
723 REALM => $ctx->{realm},
724 PASSWORD => $ctx->{password},
725 LDAPDIR => $ctx->{ldapdir},
726 LDAP_INSTANCE => $ctx->{ldap_instance},
727 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
728 NCALRPCDIR => $ctx->{ncalrpcdir},
729 LOCKDIR => $ctx->{lockdir},
730 STATEDIR => $ctx->{statedir},
731 CACHEDIR => $ctx->{cachedir},
732 PRIVATEDIR => $ctx->{privatedir},
733 BINDDNSDIR => $ctx->{binddnsdir},
734 SERVERCONFFILE => $ctx->{smb_conf},
735 CONFIGURATION => $configuration,
736 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
737 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
738 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
739 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
740 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
741 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
742 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
743 SAMBA_TEST_LOG_POS => 0,
744 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
745 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
746 LOCAL_PATH => $ctx->{share},
747 UID_RFC2307TEST => $uid_rfc2307test,
748 GID_RFC2307TEST => $gid_rfc2307test,
749 SERVER_ROLE => $ctx->{server_role},
750 RESOLV_CONF => $ctx->{resolv_conf}
753 if (defined($ctx->{use_resolv_wrapper})) {
754 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
755 } else {
756 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
759 return $ret;
763 # Step2 runs the provision script
765 sub provision_raw_step2($$$)
767 my ($self, $ctx, $ret) = @_;
769 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
770 unless (system($provision_cmd) == 0) {
771 warn("Unable to provision: \n$provision_cmd\n");
772 return undef;
775 my $testallowed_account = "testallowed";
776 my $samba_tool_cmd = "";
777 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
778 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
779 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
780 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
781 unless (system($samba_tool_cmd) == 0) {
782 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
783 return undef;
786 my $ldbmodify = "";
787 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
788 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
789 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
790 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
792 if ($ctx->{server_role} ne "domain controller") {
793 $base_dn = "DC=$ctx->{netbiosname}";
796 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
797 $testallowed_account = "testallowed account";
798 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
799 print LDIF "dn: $user_dn
800 changetype: modify
801 replace: samAccountName
802 samAccountName: $testallowed_account
805 close(LDIF);
807 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
808 print LDIF "dn: $user_dn
809 changetype: modify
810 replace: userPrincipalName
811 userPrincipalName: testallowed upn\@$ctx->{realm}
812 replace: servicePrincipalName
813 servicePrincipalName: host/testallowed
816 close(LDIF);
818 $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} testdenied $ctx->{password}";
823 unless (system($samba_tool_cmd) == 0) {
824 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
825 return undef;
828 my $user_dn = "cn=testdenied,cn=users,$base_dn";
829 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
830 print LDIF "dn: $user_dn
831 changetype: modify
832 replace: userPrincipalName
833 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
836 close(LDIF);
838 $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 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
843 unless (system($samba_tool_cmd) == 0) {
844 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
845 return undef;
848 # Create to users alice and bob!
849 my $user_account_array = ["alice", "bob"];
851 foreach my $user_account (@{$user_account_array}) {
852 my $samba_tool_cmd = "";
854 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
855 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
856 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
857 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
858 unless (system($samba_tool_cmd) == 0) {
859 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
860 return undef;
864 return $ret;
867 sub provision($$$$$$$$$$)
869 my ($self, $prefix, $server_role, $hostname,
870 $domain, $realm, $functional_level,
871 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
872 $extra_provision_options) = @_;
874 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
875 $hostname,
876 $domain, $realm, $functional_level,
877 $password, $kdc_ipv4, $kdc_ipv6);
879 if (defined($extra_provision_options)) {
880 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
881 } else {
882 push (@{$ctx->{provision_options}}, "--use-ntvfs");
885 $ctx->{share} = "$ctx->{prefix_abs}/share";
886 push(@{$ctx->{directories}}, "$ctx->{share}");
887 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
888 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
890 # precreate directories for printer drivers
891 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
892 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
893 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
895 my $msdfs = "no";
896 $msdfs = "yes" if ($server_role eq "domain controller");
897 $ctx->{smb_conf_extra_options} = "
899 max xmit = 32K
900 server max protocol = SMB2
901 host msdfs = $msdfs
902 lanman auth = yes
904 # fruit:copyfile is a global option
905 fruit:copyfile = yes
907 $extra_smbconf_options
909 [tmp]
910 path = $ctx->{share}
911 read only = no
912 posix:sharedelay = 100000
913 posix:oplocktimeout = 3
914 posix:writetimeupdatedelay = 500000
916 [xcopy_share]
917 path = $ctx->{share}
918 read only = no
919 posix:sharedelay = 100000
920 posix:oplocktimeout = 3
921 posix:writetimeupdatedelay = 500000
922 create mask = 777
923 force create mode = 777
925 [posix_share]
926 path = $ctx->{share}
927 read only = no
928 create mask = 0777
929 force create mode = 0
930 directory mask = 0777
931 force directory mode = 0
933 [test1]
934 path = $ctx->{share}/test1
935 read only = no
936 posix:sharedelay = 100000
937 posix:oplocktimeout = 3
938 posix:writetimeupdatedelay = 500000
940 [test2]
941 path = $ctx->{share}/test2
942 read only = no
943 posix:sharedelay = 100000
944 posix:oplocktimeout = 3
945 posix:writetimeupdatedelay = 500000
947 [cifs]
948 path = $ctx->{share}/_ignore_cifs_
949 read only = no
950 ntvfs handler = cifs
951 cifs:server = $ctx->{netbiosname}
952 cifs:share = tmp
953 cifs:use-s4u2proxy = yes
954 # There is no username specified here, instead the client is expected
955 # to log in with kerberos, and the serverwill use delegated credentials.
956 # Or the server tries s4u2self/s4u2proxy to impersonate the client
958 [simple]
959 path = $ctx->{share}
960 read only = no
961 ntvfs handler = simple
963 [sysvol]
964 path = $ctx->{statedir}/sysvol
965 read only = no
967 [netlogon]
968 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
969 read only = no
971 [cifsposix]
972 copy = simple
973 ntvfs handler = cifsposix
975 [vfs_fruit]
976 path = $ctx->{share}
977 vfs objects = catia fruit streams_xattr acl_xattr
978 ea support = yes
979 fruit:resource = file
980 fruit:metadata = netatalk
981 fruit:locking = netatalk
982 fruit:encoding = native
984 $extra_smbconf_shares
987 if (defined($self->{ldap})) {
988 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
989 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
991 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
992 $ldap_uri =~ s|/|%2F|g;
993 $ldap_uri = "ldapi://$ldap_uri";
994 $ctx->{ldap_uri} = $ldap_uri;
996 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
999 my $ret = $self->provision_raw_step1($ctx);
1000 unless (defined $ret) {
1001 return undef;
1004 if (defined($self->{ldap})) {
1005 $ret->{LDAP_URI} = $ctx->{ldap_uri};
1006 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
1007 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
1008 if ($self->{ldap} eq "openldap") {
1009 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
1010 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
1012 } elsif ($self->{ldap} eq "fedora-ds") {
1013 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
1014 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
1015 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
1020 return $self->provision_raw_step2($ctx, $ret);
1023 sub provision_s4member($$$$$)
1025 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
1026 print "PROVISIONING MEMBER...\n";
1027 my $extra_smb_conf = "
1028 passdb backend = samba_dsdb
1029 winbindd:use external pipes = true
1031 # the source4 smb server doesn't allow signing by default
1032 server signing = enabled
1034 rpc_server:default = external
1035 rpc_server:svcctl = embedded
1036 rpc_server:srvsvc = embedded
1037 rpc_server:eventlog = embedded
1038 rpc_server:ntsvcs = embedded
1039 rpc_server:winreg = embedded
1040 rpc_server:spoolss = embedded
1041 rpc_daemon:spoolssd = embedded
1042 rpc_server:tcpip = no
1044 if ($more_conf) {
1045 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1047 my $ret = $self->provision($prefix,
1048 "member server",
1049 $hostname,
1050 "SAMBADOMAIN",
1051 "samba.example.com",
1052 "2008",
1053 "locMEMpass3",
1054 $dcvars->{SERVER_IP},
1055 $dcvars->{SERVER_IPV6},
1056 $extra_smb_conf, "", undef);
1057 unless ($ret) {
1058 return undef;
1061 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1062 my $cmd = "";
1063 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1064 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1065 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1066 } else {
1067 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1069 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1070 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1071 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1072 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1073 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1075 unless (system($cmd) == 0) {
1076 warn("Join failed\n$cmd");
1077 return undef;
1080 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1081 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1082 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1083 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1084 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1085 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1087 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1088 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1089 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1090 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1091 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1092 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1094 return $ret;
1097 sub provision_rpc_proxy($$$)
1099 my ($self, $prefix, $dcvars) = @_;
1100 print "PROVISIONING RPC PROXY...\n";
1102 my $extra_smbconf_options = "
1103 passdb backend = samba_dsdb
1105 # rpc_proxy
1106 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1107 dcerpc endpoint servers = epmapper, remote
1108 dcerpc_remote:interfaces = rpcecho
1110 [cifs_to_dc]
1111 path = /tmp/_ignore_cifs_to_dc_/_none_
1112 read only = no
1113 ntvfs handler = cifs
1114 cifs:server = $dcvars->{SERVER}
1115 cifs:share = cifs
1116 cifs:use-s4u2proxy = yes
1117 # There is no username specified here, instead the client is expected
1118 # to log in with kerberos, and the serverwill use delegated credentials.
1119 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1123 my $ret = $self->provision($prefix,
1124 "member server",
1125 "localrpcproxy",
1126 "SAMBADOMAIN",
1127 "samba.example.com",
1128 "2008",
1129 "locRPCproxypass4",
1130 $dcvars->{SERVER_IP},
1131 $dcvars->{SERVER_IPV6},
1132 $extra_smbconf_options, "", undef);
1133 unless ($ret) {
1134 return undef;
1137 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1139 # The joind runs in the context of the rpc_proxy/member for now
1140 my $cmd = "";
1141 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1142 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1143 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1144 } else {
1145 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1147 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1148 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1149 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1150 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1151 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1153 unless (system($cmd) == 0) {
1154 warn("Join failed\n$cmd");
1155 return undef;
1158 # Setting up delegation runs in the context of the DC for now
1159 $cmd = "";
1160 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1161 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1162 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1163 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1164 $cmd .= " $dcvars->{CONFIGURATION}";
1165 print $cmd;
1167 unless (system($cmd) == 0) {
1168 warn("Delegation failed\n$cmd");
1169 return undef;
1172 # Setting up delegation runs in the context of the DC for now
1173 $cmd = "";
1174 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1175 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1176 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1177 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1178 $cmd .= " $dcvars->{CONFIGURATION}";
1180 unless (system($cmd) == 0) {
1181 warn("Delegation failed\n$cmd");
1182 return undef;
1185 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1186 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1187 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1188 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1189 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1190 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1192 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1193 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1194 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1195 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1196 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1197 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1199 return $ret;
1202 sub provision_promoted_dc($$$)
1204 my ($self, $prefix, $dcvars) = @_;
1205 print "PROVISIONING PROMOTED DC...\n";
1207 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1208 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1209 "promotedvdc",
1210 "SAMBADOMAIN",
1211 "samba.example.com",
1212 "2008",
1213 $dcvars->{PASSWORD},
1214 $dcvars->{SERVER_IP},
1215 $dcvars->{SERVER_IPV6});
1217 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1219 $ctx->{smb_conf_extra_options} = "
1220 max xmit = 32K
1221 server max protocol = SMB2
1223 ntlm auth = ntlmv2-only
1225 [sysvol]
1226 path = $ctx->{statedir}/sysvol
1227 read only = yes
1229 [netlogon]
1230 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1231 read only = no
1235 my $ret = $self->provision_raw_step1($ctx);
1236 unless ($ret) {
1237 return undef;
1240 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1241 my $cmd = "";
1242 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1243 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1244 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1245 } else {
1246 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1248 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1249 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1250 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1251 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1252 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1254 unless (system($cmd) == 0) {
1255 warn("Join failed\n$cmd");
1256 return undef;
1259 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1260 my $cmd = "";
1261 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1262 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1263 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1264 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1265 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1266 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1268 unless (system($cmd) == 0) {
1269 warn("Join failed\n$cmd");
1270 return undef;
1273 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1274 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1275 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1276 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1278 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1279 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1280 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1281 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1282 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1283 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1285 return $ret;
1288 sub provision_vampire_dc($$$)
1290 my ($self, $prefix, $dcvars, $fl) = @_;
1291 print "PROVISIONING VAMPIRE DC @ FL $fl...\n";
1292 my $name = "localvampiredc";
1293 my $extra_conf = "";
1295 if ($fl == "2000") {
1296 $name = "vampire2000dc";
1297 } else {
1298 $extra_conf = "drs: immediate link sync = yes
1299 drs: max link sync = 250";
1302 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1303 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1304 $name,
1305 $dcvars->{DOMAIN},
1306 $dcvars->{REALM},
1307 $fl,
1308 $dcvars->{PASSWORD},
1309 $dcvars->{SERVER_IP},
1310 $dcvars->{SERVER_IPV6});
1312 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1314 $ctx->{smb_conf_extra_options} = "
1315 max xmit = 32K
1316 server max protocol = SMB2
1318 ntlm auth = mschapv2-and-ntlmv2-only
1319 $extra_conf
1321 [sysvol]
1322 path = $ctx->{statedir}/sysvol
1323 read only = yes
1325 [netlogon]
1326 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1327 read only = no
1331 my $ret = $self->provision_raw_step1($ctx);
1332 unless ($ret) {
1333 return undef;
1336 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1337 my $cmd = "";
1338 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1339 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1340 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1341 } else {
1342 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1344 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1345 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1346 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1347 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1348 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1350 unless (system($cmd) == 0) {
1351 warn("Join failed\n$cmd");
1352 return undef;
1355 if ($fl == "2000") {
1356 $ret->{VAMPIRE_2000_DC_SERVER} = $ret->{SERVER};
1357 $ret->{VAMPIRE_2000_DC_SERVER_IP} = $ret->{SERVER_IP};
1358 $ret->{VAMPIRE_2000_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1359 $ret->{VAMPIRE_2000_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1360 } else {
1361 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1362 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1363 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1364 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1366 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1367 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1368 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1369 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1370 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1371 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1372 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1374 return $ret;
1377 sub provision_subdom_dc($$$)
1379 my ($self, $prefix, $dcvars) = @_;
1380 print "PROVISIONING SUBDOMAIN DC...\n";
1382 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1383 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1384 "localsubdc",
1385 "SAMBASUBDOM",
1386 "sub.samba.example.com",
1387 "2008",
1388 $dcvars->{PASSWORD},
1389 undef);
1391 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1393 $ctx->{smb_conf_extra_options} = "
1394 max xmit = 32K
1395 server max protocol = SMB2
1397 [sysvol]
1398 path = $ctx->{statedir}/sysvol
1399 read only = yes
1401 [netlogon]
1402 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1403 read only = no
1407 my $ret = $self->provision_raw_step1($ctx);
1408 unless ($ret) {
1409 return undef;
1412 Samba::mk_krb5_conf($ctx);
1413 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1415 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1416 my $cmd = "";
1417 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1418 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1419 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1420 } else {
1421 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1423 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1424 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1425 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1426 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1427 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1428 $cmd .= " --adminpass=$ret->{PASSWORD}";
1430 unless (system($cmd) == 0) {
1431 warn("Join failed\n$cmd");
1432 return undef;
1435 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1436 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1437 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1438 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1440 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1441 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1442 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1443 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1444 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1445 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1447 return $ret;
1450 sub provision_ad_dc_ntvfs($$)
1452 my ($self, $prefix) = @_;
1454 # We keep the old 'winbind' name here in server services to
1455 # ensure upgrades which used that name still work with the now
1456 # alias.
1458 print "PROVISIONING AD DC (NTVFS)...\n";
1459 my $extra_conf_options = "netbios aliases = localDC1-a
1460 server services = +winbind -winbindd
1461 ldap server require strong auth = allow_sasl_over_tls
1462 allow nt4 crypto = yes
1463 lsa over netlogon = yes
1464 rpc server port = 1027
1465 auth event notification = true
1467 my $ret = $self->provision($prefix,
1468 "domain controller",
1469 "localdc",
1470 "SAMBADOMAIN",
1471 "samba.example.com",
1472 "2008",
1473 "locDCpass1",
1474 undef,
1475 undef,
1476 $extra_conf_options,
1478 undef);
1479 unless ($ret) {
1480 return undef;
1483 unless($self->add_wins_config("$prefix/private")) {
1484 warn("Unable to add wins configuration");
1485 return undef;
1487 $ret->{NETBIOSALIAS} = "localdc1-a";
1488 $ret->{DC_SERVER} = $ret->{SERVER};
1489 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1490 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1491 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1492 $ret->{DC_USERNAME} = $ret->{USERNAME};
1493 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1494 $ret->{DC_REALM} = $ret->{REALM};
1496 return $ret;
1499 sub provision_fl2000dc($$)
1501 my ($self, $prefix) = @_;
1503 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1504 my $extra_conf_options = "
1505 spnego:simulate_w2k=yes
1506 ntlmssp_server:force_old_spnego=yes
1508 my $ret = $self->provision($prefix,
1509 "domain controller",
1510 "dc5",
1511 "SAMBA2000",
1512 "samba2000.example.com",
1513 "2000",
1514 "locDCpass5",
1515 undef,
1516 undef,
1517 $extra_conf_options,
1519 undef);
1520 unless ($ret) {
1521 return undef;
1524 unless($self->add_wins_config("$prefix/private")) {
1525 warn("Unable to add wins configuration");
1526 return undef;
1528 $ret->{DC_SERVER} = $ret->{SERVER};
1529 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1530 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1531 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1532 $ret->{DC_USERNAME} = $ret->{USERNAME};
1533 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1534 $ret->{DC_REALM} = $ret->{REALM};
1536 return $ret;
1539 sub provision_fl2003dc($$$)
1541 my ($self, $prefix, $dcvars) = @_;
1542 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1543 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1545 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1546 my $extra_conf_options = "allow dns updates = nonsecure and secure
1547 dcesrv:header signing = no
1548 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1549 my $ret = $self->provision($prefix,
1550 "domain controller",
1551 "dc6",
1552 "SAMBA2003",
1553 "samba2003.example.com",
1554 "2003",
1555 "locDCpass6",
1556 undef,
1557 undef,
1558 $extra_conf_options,
1560 undef);
1561 unless (defined $ret) {
1562 return undef;
1565 $ret->{DC_SERVER} = $ret->{SERVER};
1566 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1567 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1568 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1569 $ret->{DC_USERNAME} = $ret->{USERNAME};
1570 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1571 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1572 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1574 my @samba_tool_options;
1575 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1576 push (@samba_tool_options, "domain");
1577 push (@samba_tool_options, "passwordsettings");
1578 push (@samba_tool_options, "set");
1579 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1580 push (@samba_tool_options, "--min-pwd-age=0");
1581 push (@samba_tool_options, "--history-length=1");
1583 my $samba_tool_cmd = join(" ", @samba_tool_options);
1585 unless (system($samba_tool_cmd) == 0) {
1586 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1587 return undef;
1590 unless($self->add_wins_config("$prefix/private")) {
1591 warn("Unable to add wins configuration");
1592 return undef;
1595 return $ret;
1598 sub provision_fl2008r2dc($$$)
1600 my ($self, $prefix, $dcvars) = @_;
1602 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1603 my $extra_conf_options = "ldap server require strong auth = no";
1604 my $ret = $self->provision($prefix,
1605 "domain controller",
1606 "dc7",
1607 "SAMBA2008R2",
1608 "samba2008R2.example.com",
1609 "2008_R2",
1610 "locDCpass7",
1611 undef,
1612 undef,
1613 $extra_conf_options,
1615 undef);
1616 unless (defined $ret) {
1617 return undef;
1620 unless ($self->add_wins_config("$prefix/private")) {
1621 warn("Unable to add wins configuration");
1622 return undef;
1624 $ret->{DC_SERVER} = $ret->{SERVER};
1625 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1626 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1627 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1628 $ret->{DC_USERNAME} = $ret->{USERNAME};
1629 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1630 $ret->{DC_REALM} = $ret->{REALM};
1632 return $ret;
1636 sub provision_rodc($$$)
1638 my ($self, $prefix, $dcvars) = @_;
1639 print "PROVISIONING RODC...\n";
1641 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1642 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1643 "rodc",
1644 "SAMBADOMAIN",
1645 "samba.example.com",
1646 "2008",
1647 $dcvars->{PASSWORD},
1648 $dcvars->{SERVER_IP},
1649 $dcvars->{SERVER_IPV6});
1650 unless ($ctx) {
1651 return undef;
1654 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1656 $ctx->{share} = "$ctx->{prefix_abs}/share";
1657 push(@{$ctx->{directories}}, "$ctx->{share}");
1659 $ctx->{smb_conf_extra_options} = "
1660 max xmit = 32K
1661 server max protocol = SMB2
1662 password server = $dcvars->{DC_SERVER}
1664 [sysvol]
1665 path = $ctx->{statedir}/sysvol
1666 read only = yes
1668 [netlogon]
1669 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1670 read only = yes
1672 [tmp]
1673 path = $ctx->{share}
1674 read only = no
1675 posix:sharedelay = 10000
1676 posix:oplocktimeout = 3
1677 posix:writetimeupdatedelay = 50000
1681 my $ret = $self->provision_raw_step1($ctx);
1682 unless ($ret) {
1683 return undef;
1686 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1687 my $cmd = "";
1688 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1689 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1690 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1691 } else {
1692 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1694 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1695 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1696 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1697 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1698 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1700 unless (system($cmd) == 0) {
1701 warn("RODC join failed\n$cmd");
1702 return undef;
1705 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1706 # user password verified on the RODC
1707 my $testallowed_account = "testallowed account";
1708 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1709 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1710 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1711 $cmd .= " --server=$dcvars->{DC_SERVER}";
1713 unless (system($cmd) == 0) {
1714 warn("RODC join failed\n$cmd");
1715 return undef;
1718 # we overwrite the kdc after the RODC join
1719 # so that use the RODC as kdc and test
1720 # the proxy code
1721 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1722 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1723 Samba::mk_krb5_conf($ctx);
1724 Samba::mk_mitkdc_conf($ctx, abs_path(Samba::bindir_path($self, "shared")));
1726 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1727 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1728 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1729 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1731 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1732 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1733 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1734 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1735 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1736 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1738 return $ret;
1741 sub read_config_h($)
1743 my ($name) = @_;
1744 my %ret = {};
1745 open(LF, "<$name") or die("unable to read $name: $!");
1746 while (<LF>) {
1747 chomp;
1748 next if not (/^#define /);
1749 if (/^#define (.*?)[ \t]+(.*?)$/) {
1750 $ret{$1} = $2;
1751 next;
1753 if (/^#define (.*?)[ \t]+$/) {
1754 $ret{$1} = 1;;
1755 next;
1758 close(LF);
1759 return \%ret;
1762 sub provision_ad_dc($$$$$$)
1764 my ($self, $prefix, $hostname, $domain, $realm, $smbconf_args) = @_;
1766 my $prefix_abs = abs_path($prefix);
1768 my $bindir_abs = abs_path($self->{bindir});
1769 my $lockdir="$prefix_abs/lockdir";
1770 my $conffile="$prefix_abs/etc/smb.conf";
1772 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1773 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1775 my $config_h = {};
1777 if (defined($ENV{CONFIG_H})) {
1778 $config_h = read_config_h($ENV{CONFIG_H});
1781 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1782 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1784 my $extra_smbconf_options = "
1785 server services = -smb +s3fs
1786 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1788 dbwrap_tdb_mutexes:* = yes
1789 ${require_mutexes}
1791 ${password_hash_gpg_key_ids}
1793 kernel oplocks = no
1794 kernel change notify = no
1795 smb2 leases = no
1797 logging = file
1798 printing = bsd
1799 printcap name = /dev/null
1801 max protocol = SMB3
1802 read only = no
1804 smbd:sharedelay = 100000
1805 smbd:writetimeupdatedelay = 500000
1806 create mask = 755
1807 dos filemode = yes
1809 dcerpc endpoint servers = -winreg -srvsvc
1811 printcap name = /dev/null
1813 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1814 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1816 printing = vlp
1817 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1818 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1819 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1820 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1821 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1822 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1823 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1824 lpq cache time = 0
1825 print notify backchannel = yes
1827 auth event notification = true
1828 $smbconf_args
1831 my $extra_smbconf_shares = "
1833 [tmpenc]
1834 copy = tmp
1835 smb encrypt = required
1837 [tmpcase]
1838 copy = tmp
1839 case sensitive = yes
1841 [tmpguest]
1842 copy = tmp
1843 guest ok = yes
1845 [hideunread]
1846 copy = tmp
1847 hide unreadable = yes
1849 [durable]
1850 copy = tmp
1851 kernel share modes = no
1852 kernel oplocks = no
1853 posix locking = no
1855 [print\$]
1856 copy = tmp
1858 [print1]
1859 copy = tmp
1860 printable = yes
1862 [print2]
1863 copy = print1
1864 [print3]
1865 copy = print1
1866 [lp]
1867 copy = print1
1870 print "PROVISIONING AD DC...\n";
1871 my $ret = $self->provision($prefix,
1872 "domain controller",
1873 $hostname,
1874 $domain,
1875 $realm,
1876 "2008",
1877 "locDCpass1",
1878 undef,
1879 undef,
1880 $extra_smbconf_options,
1881 $extra_smbconf_shares,
1882 undef);
1883 unless (defined $ret) {
1884 return undef;
1887 unless($self->add_wins_config("$prefix/private")) {
1888 warn("Unable to add wins configuration");
1889 return undef;
1892 $ret->{DC_SERVER} = $ret->{SERVER};
1893 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1894 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1895 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1896 $ret->{DC_USERNAME} = $ret->{USERNAME};
1897 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1899 return $ret;
1902 sub provision_chgdcpass($$)
1904 my ($self, $prefix) = @_;
1906 print "PROVISIONING CHGDCPASS...\n";
1907 my $extra_provision_options = undef;
1908 # This environment disallows the use of this password
1909 # (and also removes the default AD complexity checks)
1910 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1911 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1912 my $ret = $self->provision($prefix,
1913 "domain controller",
1914 "chgdcpass",
1915 "CHDCDOMAIN",
1916 "chgdcpassword.samba.example.com",
1917 "2008",
1918 "chgDCpass1",
1919 undef,
1920 undef,
1921 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
1923 $extra_provision_options);
1924 unless (defined $ret) {
1925 return undef;
1928 unless($self->add_wins_config("$prefix/private")) {
1929 warn("Unable to add wins configuration");
1930 return undef;
1933 # Remove secrets.tdb from this environment to test that we
1934 # still start up on systems without the new matching
1935 # secrets.tdb records.
1936 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1937 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1938 return undef;
1941 $ret->{DC_SERVER} = $ret->{SERVER};
1942 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1943 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1944 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1945 $ret->{DC_USERNAME} = $ret->{USERNAME};
1946 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1947 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1949 return $ret;
1952 sub teardown_env_terminate($$)
1954 my ($self, $envvars) = @_;
1955 my $pid;
1957 # This should cause samba to terminate gracefully
1958 close($envvars->{STDIN_PIPE});
1960 $pid = $envvars->{SAMBA_PID};
1961 my $count = 0;
1962 my $childpid;
1964 # This should give it time to write out the gcov data
1965 until ($count > 15) {
1966 if (Samba::cleanup_child($pid, "samba") != 0) {
1967 return;
1969 sleep(1);
1970 $count++;
1973 # After 15 Seconds, work out why this thing is still alive
1974 warn "server process $pid took more than $count seconds to exit, showing backtrace:\n";
1975 system("$self->{srcdir}/selftest/gdb_backtrace $pid");
1977 until ($count > 30) {
1978 if (Samba::cleanup_child($pid, "samba") != 0) {
1979 return;
1981 sleep(1);
1982 $count++;
1985 if (kill(0, $pid)) {
1986 warn "server process $pid took more than $count seconds to exit, sending SIGTERM\n";
1987 kill "TERM", $pid;
1990 until ($count > 40) {
1991 if (Samba::cleanup_child($pid, "samba") != 0) {
1992 return;
1994 sleep(1);
1995 $count++;
1997 # If it is still around, kill it
1998 if (kill(0, $pid)) {
1999 warn "server process $pid took more than $count seconds to exit, killing\n with SIGKILL\n";
2000 kill 9, $pid;
2002 return;
2005 sub teardown_env($$)
2007 my ($self, $envvars) = @_;
2008 teardown_env_terminate($self, $envvars);
2010 $self->slapd_stop($envvars) if ($self->{ldap});
2012 print $self->getlog_env($envvars);
2014 return;
2017 sub getlog_env($$)
2019 my ($self, $envvars) = @_;
2020 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
2021 my $out = $title;
2023 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
2025 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
2026 while (<LOG>) {
2027 $out .= $_;
2029 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
2030 close(LOG);
2032 return "" if $out eq $title;
2034 return $out;
2037 sub check_env($$)
2039 my ($self, $envvars) = @_;
2040 my $samba_pid = $envvars->{SAMBA_PID};
2042 if (not defined($samba_pid)) {
2043 return 0;
2044 } elsif ($samba_pid > 0) {
2045 my $childpid = Samba::cleanup_child($samba_pid, "samba");
2047 if ($childpid == 0) {
2048 return 1;
2050 return 0;
2051 } else {
2052 return 1;
2057 sub setup_env($$$)
2059 my ($self, $envname, $path) = @_;
2060 my $target3 = $self->{target3};
2062 $ENV{ENVNAME} = $envname;
2064 if (defined($self->{vars}->{$envname})) {
2065 return $self->{vars}->{$envname};
2068 if ($envname eq "ad_dc_ntvfs") {
2069 return $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2070 } elsif ($envname eq "fl2000dc") {
2071 return $self->setup_fl2000dc("$path/fl2000dc");
2072 } elsif ($envname eq "vampire_2000_dc") {
2073 if (not defined($self->{vars}->{fl2000dc})) {
2074 $self->setup_fl2000dc("$path/fl2000dc");
2076 return $self->setup_vampire_dc("$path/vampire_2000_dc", $self->{vars}->{fl2000dc}, "2000");
2077 } elsif ($envname eq "fl2003dc") {
2078 if (not defined($self->{vars}->{ad_dc})) {
2079 $self->setup_ad_dc("$path/ad_dc");
2081 return $self->setup_fl2003dc("$path/fl2003dc", $self->{vars}->{ad_dc});
2082 } elsif ($envname eq "fl2008r2dc") {
2083 if (not defined($self->{vars}->{ad_dc})) {
2084 $self->setup_ad_dc("$path/ad_dc");
2086 return $self->setup_fl2008r2dc("$path/fl2008r2dc", $self->{vars}->{ad_dc});
2087 } elsif ($envname eq "rpc_proxy") {
2088 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2089 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2091 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{ad_dc_ntvfs});
2092 } elsif ($envname eq "vampire_dc") {
2093 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2094 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2096 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{ad_dc_ntvfs}, "2008");
2097 } elsif ($envname eq "promoted_dc") {
2098 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2099 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2101 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{ad_dc_ntvfs});
2102 } elsif ($envname eq "subdom_dc") {
2103 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2104 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2106 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{ad_dc_ntvfs});
2107 } elsif ($envname eq "s4member_dflt_domain") {
2108 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2109 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2111 return $self->setup_s4member_dflt_domain("$path/s4member_dflt_domain", $self->{vars}->{ad_dc_ntvfs});
2112 } elsif ($envname eq "s4member") {
2113 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2114 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2116 return $self->setup_s4member("$path/s4member", $self->{vars}->{ad_dc_ntvfs});
2117 } elsif ($envname eq "rodc") {
2118 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2119 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2121 return $self->setup_rodc("$path/rodc", $self->{vars}->{ad_dc_ntvfs});
2122 } elsif ($envname eq "chgdcpass") {
2123 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
2124 } elsif ($envname eq "ad_member") {
2125 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2126 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2128 return $target3->setup_admember("$path/ad_member", $self->{vars}->{ad_dc_ntvfs}, 29);
2129 } elsif ($envname eq "ad_dc") {
2130 return $self->setup_ad_dc("$path/ad_dc");
2131 } elsif ($envname eq "ad_dc_no_nss") {
2132 return $self->setup_ad_dc_no_nss("$path/ad_dc_no_nss");
2133 } elsif ($envname eq "ad_dc_no_ntlm") {
2134 return $self->setup_ad_dc_no_ntlm("$path/ad_dc_no_ntlm");
2135 } elsif ($envname eq "ad_member_rfc2307") {
2136 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2137 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2139 return $target3->setup_admember_rfc2307("$path/ad_member_rfc2307",
2140 $self->{vars}->{ad_dc_ntvfs}, 34);
2141 } elsif ($envname eq "ad_member_idmap_rid") {
2142 if (not defined($self->{vars}->{ad_dc})) {
2143 $self->setup_ad_dc("$path/ad_dc");
2145 return $target3->setup_ad_member_idmap_rid("$path/ad_member_idmap_rid",
2146 $self->{vars}->{ad_dc});
2147 } elsif ($envname eq "ad_member_idmap_ad") {
2148 if (not defined($self->{vars}->{ad_dc})) {
2149 $self->setup_ad_dc("$path/ad_dc");
2151 return $target3->setup_ad_member_idmap_ad("$path/ad_member_idmap_ad",
2152 $self->{vars}->{ad_dc});
2153 } elsif ($envname eq "none") {
2154 return $self->setup_none("$path/none");
2155 } else {
2156 return "UNKNOWN";
2160 sub setup_s4member($$$)
2162 my ($self, $path, $dc_vars) = @_;
2164 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2166 if (defined $env) {
2167 if (not defined($self->check_or_start($env, "standard"))) {
2168 return undef;
2171 $self->{vars}->{s4member} = $env;
2174 return $env;
2177 sub setup_s4member_dflt_domain($$$)
2179 my ($self, $path, $dc_vars) = @_;
2181 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2182 "winbind use default domain = yes");
2184 if (defined $env) {
2185 if (not defined($self->check_or_start($env, "standard"))) {
2186 return undef;
2189 $self->{vars}->{s4member_dflt_domain} = $env;
2192 return $env;
2195 sub setup_rpc_proxy($$$)
2197 my ($self, $path, $dc_vars) = @_;
2199 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2201 if (defined $env) {
2202 if (not defined($self->check_or_start($env, "standard"))) {
2203 return undef;
2206 $self->{vars}->{rpc_proxy} = $env;
2208 return $env;
2211 sub setup_ad_dc_ntvfs($$)
2213 my ($self, $path) = @_;
2215 my $env = $self->provision_ad_dc_ntvfs($path);
2216 if (defined $env) {
2217 if (not defined($self->check_or_start($env, "standard"))) {
2218 warn("Failed to start ad_dc_ntvfs");
2219 return undef;
2222 $self->{vars}->{ad_dc_ntvfs} = $env;
2224 return $env;
2227 sub setup_chgdcpass($$)
2229 my ($self, $path) = @_;
2231 my $env = $self->provision_chgdcpass($path);
2232 if (defined $env) {
2233 if (not defined($self->check_or_start($env, "standard"))) {
2234 return undef;
2237 $self->{vars}->{chgdcpass} = $env;
2239 return $env;
2242 sub setup_fl2000dc($$)
2244 my ($self, $path) = @_;
2246 my $env = $self->provision_fl2000dc($path);
2247 if (defined $env) {
2248 if (not defined($self->check_or_start($env, "standard"))) {
2249 return undef;
2252 $self->{vars}->{fl2000dc} = $env;
2255 return $env;
2258 sub setup_fl2003dc($$$)
2260 my ($self, $path, $dc_vars) = @_;
2262 my $env = $self->provision_fl2003dc($path);
2264 if (defined $env) {
2265 if (not defined($self->check_or_start($env, "standard"))) {
2266 return undef;
2269 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2271 $self->{vars}->{fl2003dc} = $env;
2273 return $env;
2276 sub setup_fl2008r2dc($$$)
2278 my ($self, $path, $dc_vars) = @_;
2280 my $env = $self->provision_fl2008r2dc($path);
2282 if (defined $env) {
2283 if (not defined($self->check_or_start($env, "standard"))) {
2284 return undef;
2287 my $upn_array = ["$env->{REALM}.upn"];
2288 my $spn_array = ["$env->{REALM}.spn"];
2290 $self->setup_namespaces($env, $upn_array, $spn_array);
2292 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2294 $self->{vars}->{fl2008r2dc} = $env;
2297 return $env;
2300 sub setup_vampire_dc($$$$)
2302 my ($self, $path, $dc_vars, $fl) = @_;
2304 my $env = $self->provision_vampire_dc($path, $dc_vars, $fl);
2306 if (defined $env) {
2307 if (not defined($self->check_or_start($env, "single"))) {
2308 return undef;
2311 $self->{vars}->{vampire_dc} = $env;
2313 # force replicated DC to update repsTo/repsFrom
2314 # for vampired partitions
2315 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2317 # as 'vampired' dc may add data in its local replica
2318 # we need to synchronize data between DCs
2319 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2320 my $cmd = "";
2321 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2322 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2323 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2324 } else {
2325 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2327 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2328 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2329 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2330 $cmd .= " $dc_vars->{CONFIGURATION}";
2331 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2332 # replicate Configuration NC
2333 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2334 unless(system($cmd_repl) == 0) {
2335 warn("Failed to replicate\n$cmd_repl");
2336 return undef;
2338 # replicate Default NC
2339 $cmd_repl = "$cmd \"$base_dn\"";
2340 unless(system($cmd_repl) == 0) {
2341 warn("Failed to replicate\n$cmd_repl");
2342 return undef;
2345 # Pull in a full set of changes from the main DC
2346 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2347 $cmd = "";
2348 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2349 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2350 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2351 } else {
2352 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2354 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2355 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2356 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2357 $cmd .= " $dc_vars->{CONFIGURATION}";
2358 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2359 # replicate Configuration NC
2360 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2361 unless(system($cmd_repl) == 0) {
2362 warn("Failed to replicate\n$cmd_repl");
2363 return undef;
2365 # replicate Default NC
2366 $cmd_repl = "$cmd \"$base_dn\"";
2367 unless(system($cmd_repl) == 0) {
2368 warn("Failed to replicate\n$cmd_repl");
2369 return undef;
2373 return $env;
2376 sub setup_promoted_dc($$$)
2378 my ($self, $path, $dc_vars) = @_;
2380 my $env = $self->provision_promoted_dc($path, $dc_vars);
2382 if (defined $env) {
2383 if (not defined($self->check_or_start($env, "single"))) {
2384 return undef;
2387 $self->{vars}->{promoted_dc} = $env;
2389 # force source and replicated DC to update repsTo/repsFrom
2390 # for vampired partitions
2391 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2392 my $cmd = "";
2393 # as 'vampired' dc may add data in its local replica
2394 # we need to synchronize data between DCs
2395 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2396 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2397 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2398 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2399 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2400 $cmd .= " $dc_vars->{CONFIGURATION}";
2401 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2402 # replicate Configuration NC
2403 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2404 unless(system($cmd_repl) == 0) {
2405 warn("Failed to replicate\n$cmd_repl");
2406 return undef;
2408 # replicate Default NC
2409 $cmd_repl = "$cmd \"$base_dn\"";
2410 unless(system($cmd_repl) == 0) {
2411 warn("Failed to replicate\n$cmd_repl");
2412 return undef;
2416 return $env;
2419 sub setup_subdom_dc($$$)
2421 my ($self, $path, $dc_vars) = @_;
2423 my $env = $self->provision_subdom_dc($path, $dc_vars);
2425 if (defined $env) {
2426 if (not defined($self->check_or_start($env, "single"))) {
2427 return undef;
2430 $self->{vars}->{subdom_dc} = $env;
2432 # force replicated DC to update repsTo/repsFrom
2433 # for primary domain partitions
2434 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2435 my $cmd = "";
2436 # as 'subdomain' dc may add data in its local replica
2437 # we need to synchronize data between DCs
2438 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2439 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2440 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2441 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2442 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2443 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2444 $cmd .= " $dc_vars->{CONFIGURATION}";
2445 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2446 # replicate Configuration NC
2447 my $cmd_repl = "$cmd \"$config_dn\"";
2448 unless(system($cmd_repl) == 0) {
2449 warn("Failed to replicate\n$cmd_repl");
2450 return undef;
2452 # replicate Default NC
2453 $cmd_repl = "$cmd \"$base_dn\"";
2454 unless(system($cmd_repl) == 0) {
2455 warn("Failed to replicate\n$cmd_repl");
2456 return undef;
2460 return $env;
2463 sub setup_rodc($$$)
2465 my ($self, $path, $dc_vars) = @_;
2467 my $env = $self->provision_rodc($path, $dc_vars);
2469 unless ($env) {
2470 return undef;
2473 if (not defined($self->check_or_start($env, "standard"))) {
2474 return undef;
2477 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2478 my $cmd = "";
2480 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2481 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2482 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2483 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2484 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2485 $cmd .= " $dc_vars->{CONFIGURATION}";
2486 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2487 # replicate Configuration NC
2488 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2489 unless(system($cmd_repl) == 0) {
2490 warn("Failed to replicate\n$cmd_repl");
2491 return undef;
2493 # replicate Default NC
2494 $cmd_repl = "$cmd \"$base_dn\"";
2495 unless(system($cmd_repl) == 0) {
2496 warn("Failed to replicate\n$cmd_repl");
2497 return undef;
2500 $self->{vars}->{rodc} = $env;
2502 return $env;
2505 sub setup_ad_dc($$)
2507 my ($self, $path) = @_;
2509 # If we didn't build with ADS, pretend this env was never available
2510 if (not $self->{target3}->have_ads()) {
2511 return "UNKNOWN";
2514 my $env = $self->provision_ad_dc($path, "addc", "ADDOMAIN",
2515 "addom.samba.example.com", "");
2516 unless ($env) {
2517 return undef;
2520 if (not defined($self->check_or_start($env, "single"))) {
2521 return undef;
2524 my $upn_array = ["$env->{REALM}.upn"];
2525 my $spn_array = ["$env->{REALM}.spn"];
2527 $self->setup_namespaces($env, $upn_array, $spn_array);
2529 $self->{vars}->{ad_dc} = $env;
2530 return $env;
2533 sub setup_ad_dc_no_nss($$)
2535 my ($self, $path) = @_;
2537 # If we didn't build with ADS, pretend this env was never available
2538 if (not $self->{target3}->have_ads()) {
2539 return "UNKNOWN";
2542 my $env = $self->provision_ad_dc($path, "addc_no_nss", "ADNONSSDOMAIN",
2543 "adnonssdom.samba.example.com", "");
2544 unless ($env) {
2545 return undef;
2548 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2549 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2551 if (not defined($self->check_or_start($env, "single"))) {
2552 return undef;
2555 my $upn_array = ["$env->{REALM}.upn"];
2556 my $spn_array = ["$env->{REALM}.spn"];
2558 $self->setup_namespaces($env, $upn_array, $spn_array);
2560 $self->{vars}->{ad_dc_no_nss} = $env;
2561 return $env;
2564 sub setup_ad_dc_no_ntlm($$)
2566 my ($self, $path) = @_;
2568 # If we didn't build with ADS, pretend this env was never available
2569 if (not $self->{target3}->have_ads()) {
2570 return "UNKNOWN";
2573 my $env = $self->provision_ad_dc($path, "addc_no_ntlm", "ADNONTLMDOMAIN",
2574 "adnontlmdom.samba.example.com",
2575 "ntlm auth = disabled");
2576 unless ($env) {
2577 return undef;
2580 if (not defined($self->check_or_start($env, "prefork"))) {
2581 return undef;
2584 my $upn_array = ["$env->{REALM}.upn"];
2585 my $spn_array = ["$env->{REALM}.spn"];
2587 $self->setup_namespaces($env, $upn_array, $spn_array);
2589 $self->{vars}->{ad_dc_no_ntlm} = $env;
2590 return $env;
2593 sub setup_none($$)
2595 my ($self, $path) = @_;
2597 my $ret = {
2598 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
2599 SAMBA_PID => -1,