smbd: Fix a comment
[Samba.git] / selftest / target / Samba4.pm
blob40cca9451ec01af230ef9dc2ff35280d4d0ac044
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 $ENV{SELFTEST_WINBINDD_SOCKET_DIR} = $env_vars->{SELFTEST_WINBINDD_SOCKET_DIR};
127 $ENV{NMBD_SOCKET_DIR} = $env_vars->{NMBD_SOCKET_DIR};
129 $ENV{NSS_WRAPPER_PASSWD} = $env_vars->{NSS_WRAPPER_PASSWD};
130 $ENV{NSS_WRAPPER_GROUP} = $env_vars->{NSS_WRAPPER_GROUP};
131 $ENV{NSS_WRAPPER_HOSTS} = $env_vars->{NSS_WRAPPER_HOSTS};
132 $ENV{NSS_WRAPPER_HOSTNAME} = $env_vars->{NSS_WRAPPER_HOSTNAME};
133 $ENV{NSS_WRAPPER_MODULE_SO_PATH} = $env_vars->{NSS_WRAPPER_MODULE_SO_PATH};
134 $ENV{NSS_WRAPPER_MODULE_FN_PREFIX} = $env_vars->{NSS_WRAPPER_MODULE_FN_PREFIX};
136 if (defined($env_vars->{RESOLV_WRAPPER_CONF})) {
137 $ENV{RESOLV_WRAPPER_CONF} = $env_vars->{RESOLV_WRAPPER_CONF};
138 } else {
139 $ENV{RESOLV_WRAPPER_HOSTS} = $env_vars->{RESOLV_WRAPPER_HOSTS};
142 $ENV{UID_WRAPPER} = "1";
143 $ENV{UID_WRAPPER_ROOT} = "1";
145 $ENV{MAKE_TEST_BINARY} = Samba::bindir_path($self, "samba");
146 my @preargs = ();
147 my @optargs = ();
148 if (defined($ENV{SAMBA_OPTIONS})) {
149 @optargs = split(/ /, $ENV{SAMBA_OPTIONS});
151 if(defined($ENV{SAMBA_VALGRIND})) {
152 @preargs = split(/ /,$ENV{SAMBA_VALGRIND});
155 close($env_vars->{STDIN_PIPE});
156 open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
158 exec(@preargs, Samba::bindir_path($self, "samba"), "-M", $process_model, "-i", "--maximum-runtime=$self->{server_maxtime}", $env_vars->{CONFIGURATION}, @optargs) or die("Unable to start samba: $!");
160 $env_vars->{SAMBA_PID} = $pid;
161 print "DONE ($pid)\n";
163 close($STDIN_READER);
165 if ($self->wait_for_start($env_vars) != 0) {
166 warn("Samba $pid failed to start up");
167 return undef;
170 return $pid;
173 sub wait_for_start($$)
175 my ($self, $testenv_vars) = @_;
176 my $count = 0;
177 my $ret = 0;
179 if (not $self->check_env($testenv_vars)) {
180 warn("unable to confirm Samba $testenv_vars->{SAMBA_PID} is running");
181 return -1;
184 # This will return quickly when things are up, but be slow if we
185 # need to wait for (eg) SSL init
186 my $nmblookup = Samba::bindir_path($self, "nmblookup4");
188 do {
189 $ret = system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
190 if ($ret != 0) {
191 sleep(1);
192 } else {
193 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
194 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
195 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
196 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{NETBIOSNAME}");
197 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
198 system("$nmblookup $testenv_vars->{CONFIGURATION} $testenv_vars->{SERVER}");
199 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{SERVER}");
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->{NETBIOSNAME}");
203 system("$nmblookup $testenv_vars->{CONFIGURATION} -U $testenv_vars->{SERVER_IP} $testenv_vars->{NETBIOSNAME}");
205 $count++;
206 } while ($ret != 0 && $count < 20);
207 if ($count == 10) {
208 warn("nbt not reachable after 20 retries\n");
209 teardown_env($self, $testenv_vars);
210 return 0;
213 # Ensure we have the first RID Set before we start tests. This makes the tests more reliable.
214 if ($testenv_vars->{SERVER_ROLE} eq "domain controller" and not ($testenv_vars->{NETBIOSNAME} eq "RODC")) {
215 # Add hosts file for name lookups
216 $ENV{NSS_WRAPPER_HOSTS} = $testenv_vars->{NSS_WRAPPER_HOSTS};
217 if (defined($testenv_vars->{RESOLV_WRAPPER_CONF})) {
218 $ENV{RESOLV_WRAPPER_CONF} = $testenv_vars->{RESOLV_WRAPPER_CONF};
219 } else {
220 $ENV{RESOLV_WRAPPER_HOSTS} = $testenv_vars->{RESOLV_WRAPPER_HOSTS};
223 print "waiting for working LDAP and a RID Set to be allocated\n";
224 my $ldbsearch = Samba::bindir_path($self, "ldbsearch");
225 my $count = 0;
226 my $base_dn = "DC=".join(",DC=", split(/\./, $testenv_vars->{REALM}));
227 my $rid_set_dn = "cn=RID Set,cn=$testenv_vars->{NETBIOSNAME},ou=domain controllers,$base_dn";
228 my $max_wait = 60;
229 my $cmd = "$ldbsearch $testenv_vars->{CONFIGURATION} -H ldap://$testenv_vars->{SERVER} -U$testenv_vars->{USERNAME}%$testenv_vars->{PASSWORD} -s base -b \"$rid_set_dn\" rIDAllocationPool";
230 while (system("$cmd >/dev/null") != 0) {
231 $count++;
232 if ($count > $max_wait) {
233 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}");
234 $ret = -1;
235 last;
237 sleep(1);
240 print $self->getlog_env($testenv_vars);
242 return $ret
245 sub write_ldb_file($$$)
247 my ($self, $file, $ldif) = @_;
249 my $ldbadd = Samba::bindir_path($self, "ldbadd");
250 open(LDIF, "|$ldbadd -H $file >/dev/null");
251 print LDIF $ldif;
252 return(close(LDIF));
255 sub add_wins_config($$)
257 my ($self, $privatedir) = @_;
259 return $self->write_ldb_file("$privatedir/wins_config.ldb", "
260 dn: name=TORTURE_11,CN=PARTNERS
261 objectClass: wreplPartner
262 name: TORTURE_11
263 address: 127.0.0.11
264 pullInterval: 0
265 pushChangeCount: 0
266 type: 0x3
270 sub mk_fedora_ds($$)
272 my ($self, $ctx) = @_;
274 #Make the subdirectory be as fedora DS would expect
275 my $fedora_ds_dir = "$ctx->{ldapdir}/slapd-$ctx->{ldap_instance}";
277 my $pidfile = "$fedora_ds_dir/logs/slapd-$ctx->{ldap_instance}.pid";
279 return ($fedora_ds_dir, $pidfile);
282 sub mk_openldap($$)
284 my ($self, $ctx) = @_;
286 my $slapd_conf_d = "$ctx->{ldapdir}/slapd.d";
287 my $pidfile = "$ctx->{ldapdir}/slapd.pid";
289 return ($slapd_conf_d, $pidfile);
292 sub setup_namespaces($$:$$)
294 my ($self, $localenv, $upn_array, $spn_array) = @_;
296 @{$upn_array} = [] unless defined($upn_array);
297 my $upn_args = "";
298 foreach my $upn (@{$upn_array}) {
299 $upn_args .= " --add-upn-suffix=$upn";
302 @{$spn_array} = [] unless defined($spn_array);
303 my $spn_args = "";
304 foreach my $spn (@{$spn_array}) {
305 $spn_args .= " --add-spn-suffix=$spn";
308 my $samba_tool = Samba::bindir_path($self, "samba-tool");
310 my $cmd_env = "";
311 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
312 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
313 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
314 } else {
315 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
317 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
318 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
320 my $cmd_config = " $localenv->{CONFIGURATION}";
322 my $namespaces = $cmd_env;
323 $namespaces .= " $samba_tool domain trust namespaces $upn_args $spn_args";
324 $namespaces .= $cmd_config;
325 unless (system($namespaces) == 0) {
326 warn("Failed to add namespaces \n$namespaces");
327 return;
330 return;
333 sub setup_trust($$$$$)
335 my ($self, $localenv, $remoteenv, $type, $extra_args) = @_;
337 $localenv->{TRUST_SERVER} = $remoteenv->{SERVER};
338 $localenv->{TRUST_SERVER_IP} = $remoteenv->{SERVER_IP};
339 $localenv->{TRUST_SERVER_IPV6} = $remoteenv->{SERVER_IPV6};
340 $localenv->{TRUST_NETBIOSNAME} = $remoteenv->{NETBIOSNAME};
341 $localenv->{TRUST_USERNAME} = $remoteenv->{USERNAME};
342 $localenv->{TRUST_PASSWORD} = $remoteenv->{PASSWORD};
343 $localenv->{TRUST_DOMAIN} = $remoteenv->{DOMAIN};
344 $localenv->{TRUST_REALM} = $remoteenv->{REALM};
346 my $samba_tool = Samba::bindir_path($self, "samba-tool");
347 # setup the trust
348 my $cmd_env = "";
349 $cmd_env .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$localenv->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
350 if (defined($localenv->{RESOLV_WRAPPER_CONF})) {
351 $cmd_env .= "RESOLV_WRAPPER_CONF=\"$localenv->{RESOLV_WRAPPER_CONF}\" ";
352 } else {
353 $cmd_env .= "RESOLV_WRAPPER_HOSTS=\"$localenv->{RESOLV_WRAPPER_HOSTS}\" ";
355 $cmd_env .= " KRB5_CONFIG=\"$localenv->{KRB5_CONFIG}\" ";
356 $cmd_env .= "KRB5CCNAME=\"$localenv->{KRB5_CCACHE}\" ";
358 my $cmd_config = " $localenv->{CONFIGURATION}";
359 my $cmd_creds = $cmd_config;
360 $cmd_creds .= " -U$localenv->{TRUST_DOMAIN}\\\\$localenv->{TRUST_USERNAME}\%$localenv->{TRUST_PASSWORD}";
362 my $create = $cmd_env;
363 $create .= " $samba_tool domain trust create --type=${type} $localenv->{TRUST_REALM}";
364 $create .= " $extra_args";
365 $create .= $cmd_creds;
366 unless (system($create) == 0) {
367 warn("Failed to create trust \n$create");
368 return undef;
371 return $localenv
374 sub provision_raw_prepare($$$$$$$$$$$)
376 my ($self, $prefix, $server_role, $hostname,
377 $domain, $realm, $functional_level,
378 $password, $kdc_ipv4, $kdc_ipv6) = @_;
379 my $ctx;
380 my $netbiosname = uc($hostname);
382 unless(-d $prefix or mkdir($prefix, 0777)) {
383 warn("Unable to create $prefix");
384 return undef;
386 my $prefix_abs = abs_path($prefix);
388 die ("prefix=''") if $prefix_abs eq "";
389 die ("prefix='/'") if $prefix_abs eq "/";
391 unless (system("rm -rf $prefix_abs/*") == 0) {
392 warn("Unable to clean up");
396 my $swiface = Samba::get_interface($hostname);
398 $ctx->{prefix} = $prefix;
399 $ctx->{prefix_abs} = $prefix_abs;
401 $ctx->{server_role} = $server_role;
402 $ctx->{hostname} = $hostname;
403 $ctx->{netbiosname} = $netbiosname;
404 $ctx->{swiface} = $swiface;
405 $ctx->{password} = $password;
406 $ctx->{kdc_ipv4} = $kdc_ipv4;
407 $ctx->{kdc_ipv6} = $kdc_ipv6;
408 $ctx->{krb5_ccname} = "$prefix_abs/krb5cc_%{uid}";
409 if ($functional_level eq "2000") {
410 $ctx->{supported_enctypes} = "arcfour-hmac-md5 des-cbc-md5 des-cbc-crc"
414 # Set smbd log level here.
416 $ctx->{server_loglevel} =$ENV{SERVER_LOG_LEVEL} || 1;
417 $ctx->{username} = "Administrator";
418 $ctx->{domain} = $domain;
419 $ctx->{realm} = uc($realm);
420 $ctx->{dnsname} = lc($realm);
422 $ctx->{functional_level} = $functional_level;
424 my $unix_name = ($ENV{USER} or $ENV{LOGNAME} or `whoami`);
425 chomp $unix_name;
426 $ctx->{unix_name} = $unix_name;
427 $ctx->{unix_uid} = $>;
428 my @mygid = split(" ", $();
429 $ctx->{unix_gid} = $mygid[0];
430 $ctx->{unix_gids_str} = $);
431 @{$ctx->{unix_gids}} = split(" ", $ctx->{unix_gids_str});
433 $ctx->{etcdir} = "$prefix_abs/etc";
434 $ctx->{piddir} = "$prefix_abs/pid";
435 $ctx->{smb_conf} = "$ctx->{etcdir}/smb.conf";
436 $ctx->{krb5_conf} = "$ctx->{etcdir}/krb5.conf";
437 $ctx->{krb5_ccache} = "$prefix_abs/krb5_ccache";
438 $ctx->{privatedir} = "$prefix_abs/private";
439 $ctx->{ncalrpcdir} = "$prefix_abs/ncalrpc";
440 $ctx->{lockdir} = "$prefix_abs/lockdir";
441 $ctx->{logdir} = "$prefix_abs/logs";
442 $ctx->{statedir} = "$prefix_abs/statedir";
443 $ctx->{cachedir} = "$prefix_abs/cachedir";
444 $ctx->{winbindd_socket_dir} = "$prefix_abs/winbindd_socket";
445 $ctx->{winbindd_privileged_socket_dir} = "$prefix_abs/winbindd_privileged_socket";
446 $ctx->{ntp_signd_socket_dir} = "$prefix_abs/ntp_signd_socket";
447 $ctx->{nsswrap_passwd} = "$ctx->{etcdir}/passwd";
448 $ctx->{nsswrap_group} = "$ctx->{etcdir}/group";
449 $ctx->{nsswrap_hosts} = "$ENV{SELFTEST_PREFIX}/hosts";
450 $ctx->{nsswrap_hostname} = "$ctx->{hostname}.$ctx->{dnsname}";
451 if ($ENV{SAMBA_DNS_FAKING}) {
452 $ctx->{dns_host_file} = "$ENV{SELFTEST_PREFIX}/dns_host_file";
453 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces --use-file=$ctx->{dns_host_file}";
454 } else {
455 $ctx->{samba_dnsupdate} = "$ENV{SRCDIR_ABS}/source4/scripting/bin/samba_dnsupdate -s $ctx->{smb_conf} --all-interfaces";
456 $ctx->{use_resolv_wrapper} = 1;
458 $ctx->{resolv_conf} = "$ctx->{etcdir}/resolv.conf";
460 $ctx->{tlsdir} = "$ctx->{privatedir}/tls";
462 $ctx->{ipv4} = "127.0.0.$swiface";
463 $ctx->{ipv6} = sprintf("fd00:0000:0000:0000:0000:0000:5357:5f%02x", $swiface);
464 $ctx->{interfaces} = "$ctx->{ipv4}/8 $ctx->{ipv6}/64";
466 push(@{$ctx->{directories}}, $ctx->{privatedir});
467 push(@{$ctx->{directories}}, $ctx->{etcdir});
468 push(@{$ctx->{directories}}, $ctx->{piddir});
469 push(@{$ctx->{directories}}, $ctx->{lockdir});
470 push(@{$ctx->{directories}}, $ctx->{logdir});
471 push(@{$ctx->{directories}}, $ctx->{statedir});
472 push(@{$ctx->{directories}}, $ctx->{cachedir});
474 $ctx->{smb_conf_extra_options} = "";
476 my @provision_options = ();
477 push (@provision_options, "KRB5_CONFIG=\"$ctx->{krb5_conf}\"");
478 push (@provision_options, "KRB5_CCACHE=\"$ctx->{krb5_ccache}\"");
479 push (@provision_options, "NSS_WRAPPER_PASSWD=\"$ctx->{nsswrap_passwd}\"");
480 push (@provision_options, "NSS_WRAPPER_GROUP=\"$ctx->{nsswrap_group}\"");
481 push (@provision_options, "NSS_WRAPPER_HOSTS=\"$ctx->{nsswrap_hosts}\"");
482 push (@provision_options, "NSS_WRAPPER_HOSTNAME=\"$ctx->{nsswrap_hostname}\"");
483 if (defined($ctx->{use_resolv_wrapper})) {
484 push (@provision_options, "RESOLV_WRAPPER_CONF=\"$ctx->{resolv_conf}\"");
485 } else {
486 push (@provision_options, "RESOLV_WRAPPER_HOSTS=\"$ctx->{dns_host_file}\"");
488 if (defined($ENV{GDB_PROVISION})) {
489 push (@provision_options, "gdb --args");
490 if (!defined($ENV{PYTHON})) {
491 push (@provision_options, "env");
492 push (@provision_options, "python");
495 if (defined($ENV{VALGRIND_PROVISION})) {
496 push (@provision_options, "valgrind");
497 if (!defined($ENV{PYTHON})) {
498 push (@provision_options, "env");
499 push (@provision_options, "python");
502 if (defined($ENV{PYTHON})) {
503 push (@provision_options, $ENV{PYTHON});
505 push (@provision_options, Samba::bindir_path($self, "samba-tool"));
506 push (@provision_options, "domain");
507 push (@provision_options, "provision");
508 push (@provision_options, "--configfile=$ctx->{smb_conf}");
509 push (@provision_options, "--host-name=$ctx->{hostname}");
510 push (@provision_options, "--host-ip=$ctx->{ipv4}");
511 push (@provision_options, "--quiet");
512 push (@provision_options, "--domain=$ctx->{domain}");
513 push (@provision_options, "--realm=$ctx->{realm}");
514 push (@provision_options, "--adminpass=$ctx->{password}");
515 push (@provision_options, "--krbtgtpass=krbtgt$ctx->{password}");
516 push (@provision_options, "--machinepass=machine$ctx->{password}");
517 push (@provision_options, "--root=$ctx->{unix_name}");
518 push (@provision_options, "--server-role=\"$ctx->{server_role}\"");
519 push (@provision_options, "--function-level=\"$ctx->{functional_level}\"");
521 @{$ctx->{provision_options}} = @provision_options;
523 return $ctx;
527 # Step1 creates the basic configuration
529 sub provision_raw_step1($$)
531 my ($self, $ctx) = @_;
533 mkdir($_, 0777) foreach (@{$ctx->{directories}});
536 ## lockdir and piddir must be 0755
538 chmod 0755, $ctx->{lockdir};
539 chmod 0755, $ctx->{piddir};
541 unless (open(CONFFILE, ">$ctx->{smb_conf}")) {
542 warn("can't open $ctx->{smb_conf}$?");
543 return undef;
546 Samba::prepare_keyblobs($ctx);
547 my $crlfile = "$ctx->{tlsdir}/crl.pem";
548 $crlfile = "" unless -e ${crlfile};
550 print CONFFILE "
551 [global]
552 netbios name = $ctx->{netbiosname}
553 posix:eadb = $ctx->{statedir}/eadb.tdb
554 workgroup = $ctx->{domain}
555 realm = $ctx->{realm}
556 private dir = $ctx->{privatedir}
557 pid directory = $ctx->{piddir}
558 ncalrpc dir = $ctx->{ncalrpcdir}
559 lock dir = $ctx->{lockdir}
560 state directory = $ctx->{statedir}
561 cache directory = $ctx->{cachedir}
562 winbindd socket directory = $ctx->{winbindd_socket_dir}
563 winbindd privileged socket directory = $ctx->{winbindd_privileged_socket_dir}
564 ntp signd socket directory = $ctx->{ntp_signd_socket_dir}
565 winbind separator = /
566 interfaces = $ctx->{interfaces}
567 tls dh params file = $ctx->{tlsdir}/dhparms.pem
568 tls crlfile = ${crlfile}
569 tls verify peer = no_check
570 panic action = $RealBin/gdb_backtrace \%d
571 wins support = yes
572 server role = $ctx->{server_role}
573 server services = +echo +smb -s3fs
574 dcerpc endpoint servers = +winreg +srvsvc
575 notify:inotify = false
576 ldb:nosync = true
577 ldap server require strong auth = yes
578 #We don't want to pass our self-tests if the PAC code is wrong
579 gensec:require_pac = true
580 log file = $ctx->{logdir}/log.\%m
581 log level = $ctx->{server_loglevel}
582 lanman auth = Yes
583 ntlm auth = Yes
584 rndc command = true
585 dns update command = $ctx->{samba_dnsupdate}
586 spn update command = $ENV{SRCDIR_ABS}/source4/scripting/bin/samba_spnupdate -s $ctx->{smb_conf}
587 dreplsrv:periodic_startup_interval = 0
588 dsdb:schema update allowed = yes
590 vfs objects = dfs_samba4 acl_xattr fake_acls xattr_tdb streams_depot
592 idmap_ldb:use rfc2307=yes
593 winbind enum users = yes
594 winbind enum groups = yes
597 print CONFFILE "
599 # Begin extra options
600 $ctx->{smb_conf_extra_options}
601 # End extra options
603 close(CONFFILE);
605 #Default the KDC IP to the server's IP
606 if (not defined($ctx->{kdc_ipv4})) {
607 $ctx->{kdc_ipv4} = $ctx->{ipv4};
609 if (not defined($ctx->{kdc_ipv6})) {
610 $ctx->{kdc_ipv6} = $ctx->{ipv6};
613 Samba::mk_krb5_conf($ctx);
615 open(PWD, ">$ctx->{nsswrap_passwd}");
616 if ($ctx->{unix_uid} != 0) {
617 print PWD "root:x:0:0:root gecos:$ctx->{prefix_abs}:/bin/false\n";
619 print PWD "$ctx->{unix_name}:x:$ctx->{unix_uid}:65531:$ctx->{unix_name} gecos:$ctx->{prefix_abs}:/bin/false\n";
620 print PWD "nobody:x:65534:65533:nobody gecos:$ctx->{prefix_abs}:/bin/false
621 pdbtest:x:65533:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
622 pdbtest2:x:65532:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
623 pdbtest3:x:65531:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
624 pdbtest4:x:65530:65533:pdbtest gecos:$ctx->{prefix_abs}:/bin/false
626 close(PWD);
627 my $uid_rfc2307test = 65533;
629 open(GRP, ">$ctx->{nsswrap_group}");
630 if ($ctx->{unix_gid} != 0) {
631 print GRP "root:x:0:\n";
633 print GRP "$ctx->{unix_name}:x:$ctx->{unix_gid}:\n";
634 print GRP "wheel:x:10:
635 users:x:65531:
636 nobody:x:65533:
637 nogroup:x:65534:nobody
639 close(GRP);
640 my $gid_rfc2307test = 65532;
642 my $hostname = lc($ctx->{hostname});
643 open(HOSTS, ">>$ctx->{nsswrap_hosts}");
644 if ($hostname eq "localdc") {
645 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
646 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} $ctx->{dnsname} ${hostname}\n";
647 } else {
648 print HOSTS "$ctx->{ipv4} ${hostname}.$ctx->{dnsname} ${hostname}\n";
649 print HOSTS "$ctx->{ipv6} ${hostname}.$ctx->{dnsname} ${hostname}\n";
651 close(HOSTS);
653 if (defined($ctx->{resolv_conf})) {
654 open(RESOLV_CONF, ">$ctx->{resolv_conf}");
655 print RESOLV_CONF "nameserver $ctx->{kdc_ipv4}\n";
656 print RESOLV_CONF "nameserver $ctx->{kdc_ipv6}\n";
657 close(RESOLV_CONF);
660 my $configuration = "--configfile=$ctx->{smb_conf}";
662 #Ensure the config file is valid before we start
663 my $testparm = Samba::bindir_path($self, "samba-tool") . " testparm";
664 if (system("$testparm $configuration -v --suppress-prompt >/dev/null 2>&1") != 0) {
665 system("$testparm -v --suppress-prompt $configuration >&2");
666 warn("Failed to create a valid smb.conf configuration $testparm!");
667 return undef;
669 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) {
670 warn("Failed to create a valid smb.conf configuration! $testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global");
671 return undef;
674 my $ret = {
675 KRB5_CONFIG => $ctx->{krb5_conf},
676 KRB5_CCACHE => $ctx->{krb5_ccache},
677 PIDDIR => $ctx->{piddir},
678 SERVER => $ctx->{hostname},
679 SERVER_IP => $ctx->{ipv4},
680 SERVER_IPV6 => $ctx->{ipv6},
681 NETBIOSNAME => $ctx->{netbiosname},
682 DOMAIN => $ctx->{domain},
683 USERNAME => $ctx->{username},
684 REALM => $ctx->{realm},
685 PASSWORD => $ctx->{password},
686 LDAPDIR => $ctx->{ldapdir},
687 LDAP_INSTANCE => $ctx->{ldap_instance},
688 SELFTEST_WINBINDD_SOCKET_DIR => $ctx->{winbindd_socket_dir},
689 NCALRPCDIR => $ctx->{ncalrpcdir},
690 LOCKDIR => $ctx->{lockdir},
691 STATEDIR => $ctx->{statedir},
692 CACHEDIR => $ctx->{cachedir},
693 PRIVATEDIR => $ctx->{privatedir},
694 SERVERCONFFILE => $ctx->{smb_conf},
695 CONFIGURATION => $configuration,
696 SOCKET_WRAPPER_DEFAULT_IFACE => $ctx->{swiface},
697 NSS_WRAPPER_PASSWD => $ctx->{nsswrap_passwd},
698 NSS_WRAPPER_GROUP => $ctx->{nsswrap_group},
699 NSS_WRAPPER_HOSTS => $ctx->{nsswrap_hosts},
700 NSS_WRAPPER_HOSTNAME => $ctx->{nsswrap_hostname},
701 SAMBA_TEST_FIFO => "$ctx->{prefix}/samba_test.fifo",
702 SAMBA_TEST_LOG => "$ctx->{prefix}/samba_test.log",
703 SAMBA_TEST_LOG_POS => 0,
704 NSS_WRAPPER_MODULE_SO_PATH => Samba::nss_wrapper_winbind_so_path($self),
705 NSS_WRAPPER_MODULE_FN_PREFIX => "winbind",
706 LOCAL_PATH => $ctx->{share},
707 UID_RFC2307TEST => $uid_rfc2307test,
708 GID_RFC2307TEST => $gid_rfc2307test,
709 SERVER_ROLE => $ctx->{server_role},
710 RESOLV_CONF => $ctx->{resolv_conf}
713 if (defined($ctx->{use_resolv_wrapper})) {
714 $ret->{RESOLV_WRAPPER_CONF} = $ctx->{resolv_conf};
715 } else {
716 $ret->{RESOLV_WRAPPER_HOSTS} = $ctx->{dns_host_file};
719 return $ret;
723 # Step2 runs the provision script
725 sub provision_raw_step2($$$)
727 my ($self, $ctx, $ret) = @_;
729 my $provision_cmd = join(" ", @{$ctx->{provision_options}});
730 unless (system($provision_cmd) == 0) {
731 warn("Unable to provision: \n$provision_cmd\n");
732 return undef;
735 my $testallowed_account = "testallowed";
736 my $samba_tool_cmd = "";
737 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
738 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
739 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
740 . " user create --configfile=$ctx->{smb_conf} $testallowed_account $ctx->{password}";
741 unless (system($samba_tool_cmd) == 0) {
742 warn("Unable to add testallowed user: \n$samba_tool_cmd\n");
743 return undef;
746 my $ldbmodify = "";
747 $ldbmodify .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
748 $ldbmodify .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
749 $ldbmodify .= Samba::bindir_path($self, "ldbmodify");
750 my $base_dn = "DC=".join(",DC=", split(/\./, $ctx->{realm}));
752 if ($ctx->{server_role} ne "domain controller") {
753 $base_dn = "DC=$ctx->{netbiosname}";
756 my $user_dn = "cn=$testallowed_account,cn=users,$base_dn";
757 $testallowed_account = "testallowed account";
758 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
759 print LDIF "dn: $user_dn
760 changetype: modify
761 replace: samAccountName
762 samAccountName: $testallowed_account
765 close(LDIF);
767 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
768 print LDIF "dn: $user_dn
769 changetype: modify
770 replace: userPrincipalName
771 userPrincipalName: testallowed upn\@$ctx->{realm}
772 replace: servicePrincipalName
773 servicePrincipalName: host/testallowed
776 close(LDIF);
778 $samba_tool_cmd = "";
779 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
780 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
781 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
782 . " user create --configfile=$ctx->{smb_conf} testdenied $ctx->{password}";
783 unless (system($samba_tool_cmd) == 0) {
784 warn("Unable to add testdenied user: \n$samba_tool_cmd\n");
785 return undef;
788 my $user_dn = "cn=testdenied,cn=users,$base_dn";
789 open(LDIF, "|$ldbmodify -H $ctx->{privatedir}/sam.ldb");
790 print LDIF "dn: $user_dn
791 changetype: modify
792 replace: userPrincipalName
793 userPrincipalName: testdenied_upn\@$ctx->{realm}.upn
796 close(LDIF);
798 $samba_tool_cmd = "";
799 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
800 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
801 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
802 . " group addmembers --configfile=$ctx->{smb_conf} 'Allowed RODC Password Replication Group' '$testallowed_account'";
803 unless (system($samba_tool_cmd) == 0) {
804 warn("Unable to add '$testallowed_account' user to 'Allowed RODC Password Replication Group': \n$samba_tool_cmd\n");
805 return undef;
808 # Create to users alice and bob!
809 my $user_account_array = ["alice", "bob"];
811 foreach my $user_account (@{$user_account_array}) {
812 my $samba_tool_cmd = "";
814 $samba_tool_cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
815 $samba_tool_cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
816 $samba_tool_cmd .= Samba::bindir_path($self, "samba-tool")
817 . " user create --configfile=$ctx->{smb_conf} $user_account Secret007";
818 unless (system($samba_tool_cmd) == 0) {
819 warn("Unable to create user: $user_account\n$samba_tool_cmd\n");
820 return undef;
824 return $ret;
827 sub provision($$$$$$$$$$)
829 my ($self, $prefix, $server_role, $hostname,
830 $domain, $realm, $functional_level,
831 $password, $kdc_ipv4, $kdc_ipv6, $extra_smbconf_options, $extra_smbconf_shares,
832 $extra_provision_options) = @_;
834 my $ctx = $self->provision_raw_prepare($prefix, $server_role,
835 $hostname,
836 $domain, $realm, $functional_level,
837 $password, $kdc_ipv4, $kdc_ipv6);
839 if (defined($extra_provision_options)) {
840 push (@{$ctx->{provision_options}}, @{$extra_provision_options});
841 } else {
842 push (@{$ctx->{provision_options}}, "--use-ntvfs");
845 $ctx->{share} = "$ctx->{prefix_abs}/share";
846 push(@{$ctx->{directories}}, "$ctx->{share}");
847 push(@{$ctx->{directories}}, "$ctx->{share}/test1");
848 push(@{$ctx->{directories}}, "$ctx->{share}/test2");
850 # precreate directories for printer drivers
851 push(@{$ctx->{directories}}, "$ctx->{share}/W32X86");
852 push(@{$ctx->{directories}}, "$ctx->{share}/x64");
853 push(@{$ctx->{directories}}, "$ctx->{share}/WIN40");
855 my $msdfs = "no";
856 $msdfs = "yes" if ($server_role eq "domain controller");
857 $ctx->{smb_conf_extra_options} = "
859 max xmit = 32K
860 server max protocol = SMB2
861 host msdfs = $msdfs
862 lanman auth = yes
863 allow nt4 crypto = yes
865 # fruit:copyfile is a global option
866 fruit:copyfile = yes
868 $extra_smbconf_options
870 [tmp]
871 path = $ctx->{share}
872 read only = no
873 posix:sharedelay = 100000
874 posix:oplocktimeout = 3
875 posix:writetimeupdatedelay = 500000
877 [xcopy_share]
878 path = $ctx->{share}
879 read only = no
880 posix:sharedelay = 100000
881 posix:oplocktimeout = 3
882 posix:writetimeupdatedelay = 500000
883 create mask = 777
884 force create mode = 777
886 [posix_share]
887 path = $ctx->{share}
888 read only = no
889 create mask = 0777
890 force create mode = 0
891 directory mask = 0777
892 force directory mode = 0
894 [test1]
895 path = $ctx->{share}/test1
896 read only = no
897 posix:sharedelay = 100000
898 posix:oplocktimeout = 3
899 posix:writetimeupdatedelay = 500000
901 [test2]
902 path = $ctx->{share}/test2
903 read only = no
904 posix:sharedelay = 100000
905 posix:oplocktimeout = 3
906 posix:writetimeupdatedelay = 500000
908 [cifs]
909 path = $ctx->{share}/_ignore_cifs_
910 read only = no
911 ntvfs handler = cifs
912 cifs:server = $ctx->{netbiosname}
913 cifs:share = tmp
914 cifs:use-s4u2proxy = yes
915 # There is no username specified here, instead the client is expected
916 # to log in with kerberos, and the serverwill use delegated credentials.
917 # Or the server tries s4u2self/s4u2proxy to impersonate the client
919 [simple]
920 path = $ctx->{share}
921 read only = no
922 ntvfs handler = simple
924 [sysvol]
925 path = $ctx->{statedir}/sysvol
926 read only = no
928 [netlogon]
929 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
930 read only = no
932 [cifsposix]
933 copy = simple
934 ntvfs handler = cifsposix
936 [vfs_fruit]
937 path = $ctx->{share}
938 vfs objects = catia fruit streams_xattr acl_xattr
939 ea support = yes
940 fruit:ressource = file
941 fruit:metadata = netatalk
942 fruit:locking = netatalk
943 fruit:encoding = native
945 $extra_smbconf_shares
948 if (defined($self->{ldap})) {
949 $ctx->{ldapdir} = "$ctx->{privatedir}/ldap";
950 push(@{$ctx->{directories}}, "$ctx->{ldapdir}");
952 my $ldap_uri= "$ctx->{ldapdir}/ldapi";
953 $ldap_uri =~ s|/|%2F|g;
954 $ldap_uri = "ldapi://$ldap_uri";
955 $ctx->{ldap_uri} = $ldap_uri;
957 $ctx->{ldap_instance} = lc($ctx->{netbiosname});
960 my $ret = $self->provision_raw_step1($ctx);
961 unless (defined $ret) {
962 return undef;
965 if (defined($self->{ldap})) {
966 $ret->{LDAP_URI} = $ctx->{ldap_uri};
967 push (@{$ctx->{provision_options}}, "--ldap-backend-type=" . $self->{ldap});
968 push (@{$ctx->{provision_options}}, "--ldap-backend-nosync");
969 if ($self->{ldap} eq "openldap") {
970 push (@{$ctx->{provision_options}}, "--slapd-path=" . $ENV{OPENLDAP_SLAPD});
971 ($ret->{SLAPD_CONF_D}, $ret->{OPENLDAP_PIDFILE}) = $self->mk_openldap($ctx) or die("Unable to create openldap directories");
973 } elsif ($self->{ldap} eq "fedora-ds") {
974 push (@{$ctx->{provision_options}}, "--slapd-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/ns-slapd");
975 push (@{$ctx->{provision_options}}, "--setup-ds-path=" . "$ENV{FEDORA_DS_ROOT}/sbin/setup-ds.pl");
976 ($ret->{FEDORA_DS_DIR}, $ret->{FEDORA_DS_PIDFILE}) = $self->mk_fedora_ds($ctx) or die("Unable to create fedora ds directories");
981 return $self->provision_raw_step2($ctx, $ret);
984 sub provision_s4member($$$$$)
986 my ($self, $prefix, $dcvars, $hostname, $more_conf) = @_;
987 print "PROVISIONING MEMBER...\n";
988 my $extra_smb_conf = "
989 passdb backend = samba_dsdb
990 winbindd:use external pipes = true
992 # the source4 smb server doesn't allow signing by default
993 server signing = enabled
995 rpc_server:default = external
996 rpc_server:svcctl = embedded
997 rpc_server:srvsvc = embedded
998 rpc_server:eventlog = embedded
999 rpc_server:ntsvcs = embedded
1000 rpc_server:winreg = embedded
1001 rpc_server:spoolss = embedded
1002 rpc_daemon:spoolssd = embedded
1003 rpc_server:tcpip = no
1005 if ($more_conf) {
1006 $extra_smb_conf = $extra_smb_conf . $more_conf . "\n";
1008 my $ret = $self->provision($prefix,
1009 "member server",
1010 $hostname,
1011 "SAMBADOMAIN",
1012 "samba.example.com",
1013 "2008",
1014 "locMEMpass3",
1015 $dcvars->{SERVER_IP},
1016 $dcvars->{SERVER_IPV6},
1017 $extra_smb_conf, "", undef);
1018 unless ($ret) {
1019 return undef;
1022 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1023 my $cmd = "";
1024 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1025 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1026 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1027 } else {
1028 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1030 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1031 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1032 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1033 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1034 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1036 unless (system($cmd) == 0) {
1037 warn("Join failed\n$cmd");
1038 return undef;
1041 $ret->{MEMBER_SERVER} = $ret->{SERVER};
1042 $ret->{MEMBER_SERVER_IP} = $ret->{SERVER_IP};
1043 $ret->{MEMBER_SERVER_IPV6} = $ret->{SERVER_IPV6};
1044 $ret->{MEMBER_NETBIOSNAME} = $ret->{NETBIOSNAME};
1045 $ret->{MEMBER_USERNAME} = $ret->{USERNAME};
1046 $ret->{MEMBER_PASSWORD} = $ret->{PASSWORD};
1048 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1049 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1050 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1051 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1052 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1053 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1055 return $ret;
1058 sub provision_rpc_proxy($$$)
1060 my ($self, $prefix, $dcvars) = @_;
1061 print "PROVISIONING RPC PROXY...\n";
1063 my $extra_smbconf_options = "
1064 passdb backend = samba_dsdb
1066 # rpc_proxy
1067 dcerpc_remote:binding = ncacn_ip_tcp:$dcvars->{SERVER}
1068 dcerpc endpoint servers = epmapper, remote
1069 dcerpc_remote:interfaces = rpcecho
1071 [cifs_to_dc]
1072 path = /tmp/_ignore_cifs_to_dc_/_none_
1073 read only = no
1074 ntvfs handler = cifs
1075 cifs:server = $dcvars->{SERVER}
1076 cifs:share = cifs
1077 cifs:use-s4u2proxy = yes
1078 # There is no username specified here, instead the client is expected
1079 # to log in with kerberos, and the serverwill use delegated credentials.
1080 # Or the server tries s4u2self/s4u2proxy to impersonate the client
1084 my $ret = $self->provision($prefix,
1085 "member server",
1086 "localrpcproxy",
1087 "SAMBADOMAIN",
1088 "samba.example.com",
1089 "2008",
1090 "locRPCproxypass4",
1091 $dcvars->{SERVER_IP},
1092 $dcvars->{SERVER_IPV6},
1093 $extra_smbconf_options, "", undef);
1094 unless ($ret) {
1095 return undef;
1098 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1100 # The joind runs in the context of the rpc_proxy/member for now
1101 my $cmd = "";
1102 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1103 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1104 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1105 } else {
1106 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1108 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1109 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1110 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} member";
1111 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1112 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1114 unless (system($cmd) == 0) {
1115 warn("Join failed\n$cmd");
1116 return undef;
1119 # Setting up delegation runs in the context of the DC for now
1120 $cmd = "";
1121 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1122 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1123 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1124 $cmd .= "$samba_tool delegation for-any-protocol '$ret->{NETBIOSNAME}\$' on";
1125 $cmd .= " $dcvars->{CONFIGURATION}";
1126 print $cmd;
1128 unless (system($cmd) == 0) {
1129 warn("Delegation failed\n$cmd");
1130 return undef;
1133 # Setting up delegation runs in the context of the DC for now
1134 $cmd = "";
1135 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$dcvars->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1136 $cmd .= "KRB5_CONFIG=\"$dcvars->{KRB5_CONFIG}\" ";
1137 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1138 $cmd .= "$samba_tool delegation add-service '$ret->{NETBIOSNAME}\$' cifs/$dcvars->{SERVER}";
1139 $cmd .= " $dcvars->{CONFIGURATION}";
1141 unless (system($cmd) == 0) {
1142 warn("Delegation failed\n$cmd");
1143 return undef;
1146 $ret->{RPC_PROXY_SERVER} = $ret->{SERVER};
1147 $ret->{RPC_PROXY_SERVER_IP} = $ret->{SERVER_IP};
1148 $ret->{RPC_PROXY_SERVER_IPV6} = $ret->{SERVER_IPV6};
1149 $ret->{RPC_PROXY_NETBIOSNAME} = $ret->{NETBIOSNAME};
1150 $ret->{RPC_PROXY_USERNAME} = $ret->{USERNAME};
1151 $ret->{RPC_PROXY_PASSWORD} = $ret->{PASSWORD};
1153 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1154 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1155 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1156 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1157 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1158 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1160 return $ret;
1163 sub provision_promoted_dc($$$)
1165 my ($self, $prefix, $dcvars) = @_;
1166 print "PROVISIONING PROMOTED DC...\n";
1168 # We do this so that we don't run the provision. That's the job of 'samba-tool domain dcpromo'.
1169 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1170 "promotedvdc",
1171 "SAMBADOMAIN",
1172 "samba.example.com",
1173 "2008",
1174 $dcvars->{PASSWORD},
1175 $dcvars->{SERVER_IP},
1176 $dcvars->{SERVER_IPV6});
1178 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1180 $ctx->{smb_conf_extra_options} = "
1181 max xmit = 32K
1182 server max protocol = SMB2
1184 [sysvol]
1185 path = $ctx->{statedir}/sysvol
1186 read only = yes
1188 [netlogon]
1189 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1190 read only = no
1194 my $ret = $self->provision_raw_step1($ctx);
1195 unless ($ret) {
1196 return undef;
1199 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1200 my $cmd = "";
1201 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1202 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1203 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1204 } else {
1205 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1207 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1208 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1209 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} MEMBER --realm=$dcvars->{REALM}";
1210 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1211 $cmd .= " --machinepass=machine$ret->{PASSWORD}";
1213 unless (system($cmd) == 0) {
1214 warn("Join failed\n$cmd");
1215 return undef;
1218 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1219 my $cmd = "";
1220 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1221 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1222 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1223 $cmd .= "$samba_tool domain dcpromo $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1224 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1225 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs --dns-backend=BIND9_DLZ";
1227 unless (system($cmd) == 0) {
1228 warn("Join failed\n$cmd");
1229 return undef;
1232 $ret->{PROMOTED_DC_SERVER} = $ret->{SERVER};
1233 $ret->{PROMOTED_DC_SERVER_IP} = $ret->{SERVER_IP};
1234 $ret->{PROMOTED_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1235 $ret->{PROMOTED_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1237 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1238 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1239 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1240 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1241 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1242 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1244 return $ret;
1247 sub provision_vampire_dc($$$)
1249 my ($self, $prefix, $dcvars) = @_;
1250 print "PROVISIONING VAMPIRE DC...\n";
1252 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1253 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1254 "localvampiredc",
1255 "SAMBADOMAIN",
1256 "samba.example.com",
1257 "2008",
1258 $dcvars->{PASSWORD},
1259 $dcvars->{SERVER_IP},
1260 $dcvars->{SERVER_IPV6});
1262 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1264 $ctx->{smb_conf_extra_options} = "
1265 max xmit = 32K
1266 server max protocol = SMB2
1268 [sysvol]
1269 path = $ctx->{statedir}/sysvol
1270 read only = yes
1272 [netlogon]
1273 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1274 read only = no
1278 my $ret = $self->provision_raw_step1($ctx);
1279 unless ($ret) {
1280 return undef;
1283 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1284 my $cmd = "";
1285 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1286 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1287 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1288 } else {
1289 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1291 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1292 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1293 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} DC --realm=$dcvars->{REALM}";
1294 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD} --domain-critical-only";
1295 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1297 unless (system($cmd) == 0) {
1298 warn("Join failed\n$cmd");
1299 return undef;
1302 $ret->{VAMPIRE_DC_SERVER} = $ret->{SERVER};
1303 $ret->{VAMPIRE_DC_SERVER_IP} = $ret->{SERVER_IP};
1304 $ret->{VAMPIRE_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1305 $ret->{VAMPIRE_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1307 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1308 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1309 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1310 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1311 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1312 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1313 $ret->{DC_REALM} = $dcvars->{DC_REALM};
1315 return $ret;
1318 sub provision_subdom_dc($$$)
1320 my ($self, $prefix, $dcvars) = @_;
1321 print "PROVISIONING SUBDOMAIN DC...\n";
1323 # We do this so that we don't run the provision. That's the job of 'net vampire'.
1324 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1325 "localsubdc",
1326 "SAMBASUBDOM",
1327 "sub.samba.example.com",
1328 "2008",
1329 $dcvars->{PASSWORD},
1330 undef);
1332 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1334 $ctx->{smb_conf_extra_options} = "
1335 max xmit = 32K
1336 server max protocol = SMB2
1338 [sysvol]
1339 path = $ctx->{statedir}/sysvol
1340 read only = yes
1342 [netlogon]
1343 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1344 read only = no
1348 my $ret = $self->provision_raw_step1($ctx);
1349 unless ($ret) {
1350 return undef;
1353 Samba::mk_krb5_conf($ctx);
1355 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1356 my $cmd = "";
1357 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1358 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1359 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1360 } else {
1361 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1363 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1364 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1365 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $ctx->{dnsname} subdomain ";
1366 $cmd .= "--parent-domain=$dcvars->{REALM} -U$dcvars->{DC_USERNAME}\@$dcvars->{REALM}\%$dcvars->{DC_PASSWORD}";
1367 $cmd .= " --machinepass=machine$ret->{PASSWORD} --use-ntvfs";
1368 $cmd .= " --adminpass=$ret->{PASSWORD}";
1370 unless (system($cmd) == 0) {
1371 warn("Join failed\n$cmd");
1372 return undef;
1375 $ret->{SUBDOM_DC_SERVER} = $ret->{SERVER};
1376 $ret->{SUBDOM_DC_SERVER_IP} = $ret->{SERVER_IP};
1377 $ret->{SUBDOM_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1378 $ret->{SUBDOM_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1380 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1381 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1382 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1383 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1384 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1385 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1387 return $ret;
1390 sub provision_ad_dc_ntvfs($$)
1392 my ($self, $prefix) = @_;
1394 # We keep the old 'winbind' name here in server services to
1395 # ensure upgrades which used that name still work with the now
1396 # alias.
1398 print "PROVISIONING AD DC (NTVFS)...\n";
1399 my $extra_conf_options = "netbios aliases = localDC1-a
1400 server services = +winbind -winbindd
1401 ldap server require strong auth = allow_sasl_over_tls
1403 my $ret = $self->provision($prefix,
1404 "domain controller",
1405 "localdc",
1406 "SAMBADOMAIN",
1407 "samba.example.com",
1408 "2008",
1409 "locDCpass1",
1410 undef,
1411 undef,
1412 $extra_conf_options,
1414 undef);
1415 unless ($ret) {
1416 return undef;
1419 unless($self->add_wins_config("$prefix/private")) {
1420 warn("Unable to add wins configuration");
1421 return undef;
1423 $ret->{NETBIOSALIAS} = "localdc1-a";
1424 $ret->{DC_SERVER} = $ret->{SERVER};
1425 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1426 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1427 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1428 $ret->{DC_USERNAME} = $ret->{USERNAME};
1429 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1430 $ret->{DC_REALM} = $ret->{REALM};
1432 return $ret;
1435 sub provision_fl2000dc($$)
1437 my ($self, $prefix) = @_;
1439 print "PROVISIONING DC WITH FOREST LEVEL 2000...\n";
1440 my $extra_conf_options = "
1441 spnego:simulate_w2k=yes
1442 ntlmssp_server:force_old_spnego=yes
1444 my $ret = $self->provision($prefix,
1445 "domain controller",
1446 "dc5",
1447 "SAMBA2000",
1448 "samba2000.example.com",
1449 "2000",
1450 "locDCpass5",
1451 undef,
1452 undef,
1453 $extra_conf_options,
1455 undef);
1456 unless ($ret) {
1457 return undef;
1460 unless($self->add_wins_config("$prefix/private")) {
1461 warn("Unable to add wins configuration");
1462 return undef;
1464 $ret->{DC_SERVER} = $ret->{SERVER};
1465 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1466 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1467 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1468 $ret->{DC_USERNAME} = $ret->{USERNAME};
1469 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1470 $ret->{DC_REALM} = $ret->{REALM};
1472 return $ret;
1475 sub provision_fl2003dc($$$)
1477 my ($self, $prefix, $dcvars) = @_;
1478 my $swiface1 = Samba::get_interface("fakednsforwarder1");
1479 my $swiface2 = Samba::get_interface("fakednsforwarder2");
1481 print "PROVISIONING DC WITH FOREST LEVEL 2003...\n";
1482 my $extra_conf_options = "allow dns updates = nonsecure and secure
1483 dns forwarder = 127.0.0.$swiface1 127.0.0.$swiface2";
1484 my $ret = $self->provision($prefix,
1485 "domain controller",
1486 "dc6",
1487 "SAMBA2003",
1488 "samba2003.example.com",
1489 "2003",
1490 "locDCpass6",
1491 undef,
1492 undef,
1493 $extra_conf_options,
1495 undef);
1496 unless (defined $ret) {
1497 return undef;
1500 $ret->{DC_SERVER} = $ret->{SERVER};
1501 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1502 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1503 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1504 $ret->{DC_USERNAME} = $ret->{USERNAME};
1505 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1506 $ret->{DNS_FORWARDER1} = "127.0.0.$swiface1";
1507 $ret->{DNS_FORWARDER2} = "127.0.0.$swiface2";
1509 my @samba_tool_options;
1510 push (@samba_tool_options, Samba::bindir_path($self, "samba-tool"));
1511 push (@samba_tool_options, "domain");
1512 push (@samba_tool_options, "passwordsettings");
1513 push (@samba_tool_options, "set");
1514 push (@samba_tool_options, "--configfile=$ret->{SERVERCONFFILE}");
1515 push (@samba_tool_options, "--min-pwd-age=0");
1516 push (@samba_tool_options, "--history-length=1");
1518 my $samba_tool_cmd = join(" ", @samba_tool_options);
1520 unless (system($samba_tool_cmd) == 0) {
1521 warn("Unable to set min password age to 0: \n$samba_tool_cmd\n");
1522 return undef;
1525 unless($self->add_wins_config("$prefix/private")) {
1526 warn("Unable to add wins configuration");
1527 return undef;
1530 return $ret;
1533 sub provision_fl2008r2dc($$$)
1535 my ($self, $prefix, $dcvars) = @_;
1537 print "PROVISIONING DC WITH FOREST LEVEL 2008r2...\n";
1538 my $extra_conf_options = "ldap server require strong auth = no";
1539 my $ret = $self->provision($prefix,
1540 "domain controller",
1541 "dc7",
1542 "SAMBA2008R2",
1543 "samba2008R2.example.com",
1544 "2008_R2",
1545 "locDCpass7",
1546 undef,
1547 undef,
1548 $extra_conf_options,
1550 undef);
1551 unless (defined $ret) {
1552 return undef;
1555 unless ($self->add_wins_config("$prefix/private")) {
1556 warn("Unable to add wins configuration");
1557 return undef;
1559 $ret->{DC_SERVER} = $ret->{SERVER};
1560 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1561 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1562 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1563 $ret->{DC_USERNAME} = $ret->{USERNAME};
1564 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1565 $ret->{DC_REALM} = $ret->{REALM};
1567 return $ret;
1571 sub provision_rodc($$$)
1573 my ($self, $prefix, $dcvars) = @_;
1574 print "PROVISIONING RODC...\n";
1576 # We do this so that we don't run the provision. That's the job of 'net join RODC'.
1577 my $ctx = $self->provision_raw_prepare($prefix, "domain controller",
1578 "rodc",
1579 "SAMBADOMAIN",
1580 "samba.example.com",
1581 "2008",
1582 $dcvars->{PASSWORD},
1583 $dcvars->{SERVER_IP},
1584 $dcvars->{SERVER_IPV6});
1585 unless ($ctx) {
1586 return undef;
1589 push (@{$ctx->{provision_options}}, "--use-ntvfs");
1591 $ctx->{share} = "$ctx->{prefix_abs}/share";
1592 push(@{$ctx->{directories}}, "$ctx->{share}");
1594 $ctx->{smb_conf_extra_options} = "
1595 max xmit = 32K
1596 server max protocol = SMB2
1598 [sysvol]
1599 path = $ctx->{statedir}/sysvol
1600 read only = yes
1602 [netlogon]
1603 path = $ctx->{statedir}/sysvol/$ctx->{dnsname}/scripts
1604 read only = yes
1606 [tmp]
1607 path = $ctx->{share}
1608 read only = no
1609 posix:sharedelay = 10000
1610 posix:oplocktimeout = 3
1611 posix:writetimeupdatedelay = 50000
1615 my $ret = $self->provision_raw_step1($ctx);
1616 unless ($ret) {
1617 return undef;
1620 my $samba_tool = Samba::bindir_path($self, "samba-tool");
1621 my $cmd = "";
1622 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$ret->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
1623 if (defined($ret->{RESOLV_WRAPPER_CONF})) {
1624 $cmd .= "RESOLV_WRAPPER_CONF=\"$ret->{RESOLV_WRAPPER_CONF}\" ";
1625 } else {
1626 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$ret->{RESOLV_WRAPPER_HOSTS}\" ";
1628 $cmd .= "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1629 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1630 $cmd .= "$samba_tool domain join $ret->{CONFIGURATION} $dcvars->{REALM} RODC";
1631 $cmd .= " -U$dcvars->{DC_USERNAME}\%$dcvars->{DC_PASSWORD}";
1632 $cmd .= " --server=$dcvars->{DC_SERVER} --use-ntvfs";
1634 unless (system($cmd) == 0) {
1635 warn("RODC join failed\n$cmd");
1636 return undef;
1639 # This ensures deterministic behaviour for tests that want to have the 'testallowed account'
1640 # user password verified on the RODC
1641 my $testallowed_account = "testallowed account";
1642 $cmd = "KRB5_CONFIG=\"$ret->{KRB5_CONFIG}\" ";
1643 $cmd .= "KRB5CCNAME=\"$ret->{KRB5_CCACHE}\" ";
1644 $cmd .= "$samba_tool rodc preload '$testallowed_account' $ret->{CONFIGURATION}";
1645 $cmd .= " --server=$dcvars->{DC_SERVER}";
1647 unless (system($cmd) == 0) {
1648 warn("RODC join failed\n$cmd");
1649 return undef;
1652 # we overwrite the kdc after the RODC join
1653 # so that use the RODC as kdc and test
1654 # the proxy code
1655 $ctx->{kdc_ipv4} = $ret->{SERVER_IP};
1656 $ctx->{kdc_ipv6} = $ret->{SERVER_IPV6};
1657 Samba::mk_krb5_conf($ctx);
1659 $ret->{RODC_DC_SERVER} = $ret->{SERVER};
1660 $ret->{RODC_DC_SERVER_IP} = $ret->{SERVER_IP};
1661 $ret->{RODC_DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1662 $ret->{RODC_DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1664 $ret->{DC_SERVER} = $dcvars->{DC_SERVER};
1665 $ret->{DC_SERVER_IP} = $dcvars->{DC_SERVER_IP};
1666 $ret->{DC_SERVER_IPV6} = $dcvars->{DC_SERVER_IPV6};
1667 $ret->{DC_NETBIOSNAME} = $dcvars->{DC_NETBIOSNAME};
1668 $ret->{DC_USERNAME} = $dcvars->{DC_USERNAME};
1669 $ret->{DC_PASSWORD} = $dcvars->{DC_PASSWORD};
1671 return $ret;
1674 sub read_config_h($)
1676 my ($name) = @_;
1677 my %ret = {};
1678 open(LF, "<$name") or die("unable to read $name: $!");
1679 while (<LF>) {
1680 chomp;
1681 next if not (/^#define /);
1682 if (/^#define (.*?)[ \t]+(.*?)$/) {
1683 $ret{$1} = $2;
1684 next;
1686 if (/^#define (.*?)[ \t]+$/) {
1687 $ret{$1} = 1;;
1688 next;
1691 close(LF);
1692 return \%ret;
1695 sub provision_ad_dc($$)
1697 my ($self, $prefix) = @_;
1699 my $prefix_abs = abs_path($prefix);
1701 my $bindir_abs = abs_path($self->{bindir});
1702 my $lockdir="$prefix_abs/lockdir";
1703 my $conffile="$prefix_abs/etc/smb.conf";
1705 my $require_mutexes = "dbwrap_tdb_require_mutexes:* = yes";
1706 $require_mutexes = "" if ($ENV{SELFTEST_DONT_REQUIRE_TDB_MUTEX_SUPPORT} eq "1");
1708 my $config_h = {};
1710 if (defined($ENV{CONFIG_H})) {
1711 $config_h = read_config_h($ENV{CONFIG_H});
1714 my $password_hash_gpg_key_ids = "password hash gpg key ids = 4952E40301FAB41A";
1715 $password_hash_gpg_key_ids = "" unless defined($config_h->{HAVE_GPGME});
1717 my $extra_smbconf_options = "
1718 server services = -smb +s3fs
1719 xattr_tdb:file = $prefix_abs/statedir/xattr.tdb
1721 dbwrap_tdb_mutexes:* = yes
1722 ${require_mutexes}
1724 ${password_hash_gpg_key_ids}
1726 kernel oplocks = no
1727 kernel change notify = no
1728 smb2 leases = no
1730 logging = file
1731 printing = bsd
1732 printcap name = /dev/null
1734 max protocol = SMB3
1735 read only = no
1737 smbd:sharedelay = 100000
1738 smbd:writetimeupdatedelay = 500000
1739 create mask = 755
1740 dos filemode = yes
1742 dcerpc endpoint servers = -winreg -srvsvc
1744 printcap name = /dev/null
1746 addprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -a -s $conffile --
1747 deleteprinter command = $ENV{SRCDIR_ABS}/source3/script/tests/printing/modprinter.pl -d -s $conffile --
1749 printing = vlp
1750 print command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb print %p %s
1751 lpq command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpq %p
1752 lp rm command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lprm %p %j
1753 lp pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lppause %p %j
1754 lp resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb lpresume %p %j
1755 queue pause command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queuepause %p
1756 queue resume command = $bindir_abs/vlp tdbfile=$lockdir/vlp.tdb queueresume %p
1757 lpq cache time = 0
1758 print notify backchannel = yes
1761 my $extra_smbconf_shares = "
1763 [tmpenc]
1764 copy = tmp
1765 smb encrypt = required
1767 [tmpcase]
1768 copy = tmp
1769 case sensitive = yes
1771 [tmpguest]
1772 copy = tmp
1773 guest ok = yes
1775 [hideunread]
1776 copy = tmp
1777 hide unreadable = yes
1779 [durable]
1780 copy = tmp
1781 kernel share modes = no
1782 kernel oplocks = no
1783 posix locking = no
1785 [print\$]
1786 copy = tmp
1788 [print1]
1789 copy = tmp
1790 printable = yes
1792 [print2]
1793 copy = print1
1794 [print3]
1795 copy = print1
1796 [lp]
1797 copy = print1
1800 print "PROVISIONING AD DC...\n";
1801 my $ret = $self->provision($prefix,
1802 "domain controller",
1803 "addc",
1804 "ADDOMAIN",
1805 "addom.samba.example.com",
1806 "2008",
1807 "locDCpass1",
1808 undef,
1809 undef,
1810 $extra_smbconf_options,
1811 $extra_smbconf_shares,
1812 undef);
1813 unless (defined $ret) {
1814 return undef;
1817 unless($self->add_wins_config("$prefix/private")) {
1818 warn("Unable to add wins configuration");
1819 return undef;
1822 $ret->{DC_SERVER} = $ret->{SERVER};
1823 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1824 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1825 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1826 $ret->{DC_USERNAME} = $ret->{USERNAME};
1827 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1829 return $ret;
1832 sub provision_chgdcpass($$)
1834 my ($self, $prefix) = @_;
1836 print "PROVISIONING CHGDCPASS...\n";
1837 my $extra_provision_options = undef;
1838 # This environment disallows the use of this password
1839 # (and also removes the default AD complexity checks)
1840 my $unacceptable_password = "widk3Dsle32jxdBdskldsk55klASKQ";
1841 push (@{$extra_provision_options}, "--dns-backend=BIND9_DLZ");
1842 my $ret = $self->provision($prefix,
1843 "domain controller",
1844 "chgdcpass",
1845 "CHDCDOMAIN",
1846 "chgdcpassword.samba.example.com",
1847 "2008",
1848 "chgDCpass1",
1849 undef,
1850 undef,
1851 "check password script = sed -e '/$unacceptable_password/{;q1}; /$unacceptable_password/!{q0}'\n",
1853 $extra_provision_options);
1854 unless (defined $ret) {
1855 return undef;
1858 unless($self->add_wins_config("$prefix/private")) {
1859 warn("Unable to add wins configuration");
1860 return undef;
1863 # Remove secrets.tdb from this environment to test that we
1864 # still start up on systems without the new matching
1865 # secrets.tdb records.
1866 unless (unlink("$ret->{PRIVATEDIR}/secrets.tdb") || unlink("$ret->{PRIVATEDIR}/secrets.ntdb")) {
1867 warn("Unable to remove $ret->{PRIVATEDIR}/secrets.tdb added during provision");
1868 return undef;
1871 $ret->{DC_SERVER} = $ret->{SERVER};
1872 $ret->{DC_SERVER_IP} = $ret->{SERVER_IP};
1873 $ret->{DC_SERVER_IPV6} = $ret->{SERVER_IPV6};
1874 $ret->{DC_NETBIOSNAME} = $ret->{NETBIOSNAME};
1875 $ret->{DC_USERNAME} = $ret->{USERNAME};
1876 $ret->{DC_PASSWORD} = $ret->{PASSWORD};
1877 $ret->{UNACCEPTABLE_PASSWORD} = $unacceptable_password;
1879 return $ret;
1882 sub teardown_env($$)
1884 my ($self, $envvars) = @_;
1885 my $pid;
1887 # This should cause samba to terminate gracefully
1888 close($envvars->{STDIN_PIPE});
1890 $pid = $envvars->{SAMBA_PID};
1891 my $count = 0;
1892 my $childpid;
1894 # This should give it time to write out the gcov data
1895 until ($count > 30) {
1896 if (Samba::cleanup_child($pid, "samba") == -1) {
1897 last;
1899 sleep(1);
1900 $count++;
1903 if ($count > 30 || kill(0, $pid)) {
1904 kill "TERM", $pid;
1906 until ($count > 40) {
1907 if (Samba::cleanup_child($pid, "samba") == -1) {
1908 last;
1910 sleep(1);
1911 $count++;
1913 # If it is still around, kill it
1914 warn "server process $pid took more than $count seconds to exit, killing\n";
1915 kill 9, $pid;
1918 $self->slapd_stop($envvars) if ($self->{ldap});
1920 print $self->getlog_env($envvars);
1922 return;
1925 sub getlog_env($$)
1927 my ($self, $envvars) = @_;
1928 my $title = "SAMBA LOG of: $envvars->{NETBIOSNAME} pid $envvars->{SAMBA_PID}\n";
1929 my $out = $title;
1931 open(LOG, "<$envvars->{SAMBA_TEST_LOG}");
1933 seek(LOG, $envvars->{SAMBA_TEST_LOG_POS}, SEEK_SET);
1934 while (<LOG>) {
1935 $out .= $_;
1937 $envvars->{SAMBA_TEST_LOG_POS} = tell(LOG);
1938 close(LOG);
1940 return "" if $out eq $title;
1942 return $out;
1945 sub check_env($$)
1947 my ($self, $envvars) = @_;
1948 my $samba_pid = $envvars->{SAMBA_PID};
1950 if (not defined($samba_pid)) {
1951 return 0;
1952 } elsif ($samba_pid > 0) {
1953 my $childpid = Samba::cleanup_child($samba_pid, "samba");
1955 if ($childpid == 0) {
1956 return 1;
1958 return 0;
1959 } else {
1960 return 1;
1965 sub setup_env($$$)
1967 my ($self, $envname, $path) = @_;
1968 my $target3 = $self->{target3};
1970 $ENV{ENVNAME} = $envname;
1972 if (defined($self->{vars}->{$envname})) {
1973 return $self->{vars}->{$envname};
1976 if ($envname eq "ad_dc_ntvfs") {
1977 return $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
1978 } elsif ($envname eq "fl2000dc") {
1979 return $self->setup_fl2000dc("$path/fl2000dc");
1980 } elsif ($envname eq "fl2003dc") {
1981 if (not defined($self->{vars}->{ad_dc})) {
1982 $self->setup_ad_dc("$path/ad_dc");
1984 return $self->setup_fl2003dc("$path/fl2003dc", $self->{vars}->{ad_dc});
1985 } elsif ($envname eq "fl2008r2dc") {
1986 if (not defined($self->{vars}->{ad_dc})) {
1987 $self->setup_ad_dc("$path/ad_dc");
1989 return $self->setup_fl2008r2dc("$path/fl2008r2dc", $self->{vars}->{ad_dc});
1990 } elsif ($envname eq "rpc_proxy") {
1991 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
1992 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
1994 return $self->setup_rpc_proxy("$path/rpc_proxy", $self->{vars}->{ad_dc_ntvfs});
1995 } elsif ($envname eq "vampire_dc") {
1996 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
1997 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
1999 return $self->setup_vampire_dc("$path/vampire_dc", $self->{vars}->{ad_dc_ntvfs});
2000 } elsif ($envname eq "promoted_dc") {
2001 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2002 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2004 return $self->setup_promoted_dc("$path/promoted_dc", $self->{vars}->{ad_dc_ntvfs});
2005 } elsif ($envname eq "subdom_dc") {
2006 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2007 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2009 return $self->setup_subdom_dc("$path/subdom_dc", $self->{vars}->{ad_dc_ntvfs});
2010 } elsif ($envname eq "s4member_dflt_domain") {
2011 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2012 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2014 return $self->setup_s4member_dflt_domain("$path/s4member_dflt_domain", $self->{vars}->{ad_dc_ntvfs});
2015 } elsif ($envname eq "s4member") {
2016 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2017 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2019 return $self->setup_s4member("$path/s4member", $self->{vars}->{ad_dc_ntvfs});
2020 } elsif ($envname eq "rodc") {
2021 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2022 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2024 return $self->setup_rodc("$path/rodc", $self->{vars}->{ad_dc_ntvfs});
2025 } elsif ($envname eq "chgdcpass") {
2026 return $self->setup_chgdcpass("$path/chgdcpass", $self->{vars}->{chgdcpass});
2027 } elsif ($envname eq "ad_member") {
2028 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2029 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2031 return $target3->setup_admember("$path/ad_member", $self->{vars}->{ad_dc_ntvfs}, 29);
2032 } elsif ($envname eq "ad_dc") {
2033 return $self->setup_ad_dc("$path/ad_dc");
2034 } elsif ($envname eq "ad_dc_no_nss") {
2035 return $self->setup_ad_dc("$path/ad_dc_no_nss", "no_nss");
2036 } elsif ($envname eq "ad_member_rfc2307") {
2037 if (not defined($self->{vars}->{ad_dc_ntvfs})) {
2038 $self->setup_ad_dc_ntvfs("$path/ad_dc_ntvfs");
2040 return $target3->setup_admember_rfc2307("$path/ad_member_rfc2307",
2041 $self->{vars}->{ad_dc_ntvfs}, 34);
2042 } elsif ($envname eq "none") {
2043 return $self->setup_none("$path/none");
2044 } else {
2045 return "UNKNOWN";
2049 sub setup_s4member($$$)
2051 my ($self, $path, $dc_vars) = @_;
2053 my $env = $self->provision_s4member($path, $dc_vars, "s4member");
2055 if (defined $env) {
2056 if (not defined($self->check_or_start($env, "standard"))) {
2057 return undef;
2060 $self->{vars}->{s4member} = $env;
2063 return $env;
2066 sub setup_s4member_dflt_domain($$$)
2068 my ($self, $path, $dc_vars) = @_;
2070 my $env = $self->provision_s4member($path, $dc_vars, "s4member_dflt",
2071 "winbind use default domain = yes");
2073 if (defined $env) {
2074 if (not defined($self->check_or_start($env, "standard"))) {
2075 return undef;
2078 $self->{vars}->{s4member_dflt_domain} = $env;
2081 return $env;
2084 sub setup_rpc_proxy($$$)
2086 my ($self, $path, $dc_vars) = @_;
2088 my $env = $self->provision_rpc_proxy($path, $dc_vars);
2090 if (defined $env) {
2091 if (not defined($self->check_or_start($env, "standard"))) {
2092 return undef;
2095 $self->{vars}->{rpc_proxy} = $env;
2097 return $env;
2100 sub setup_ad_dc_ntvfs($$)
2102 my ($self, $path) = @_;
2104 my $env = $self->provision_ad_dc_ntvfs($path);
2105 if (defined $env) {
2106 if (not defined($self->check_or_start($env, "standard"))) {
2107 warn("Failed to start ad_dc_ntvfs");
2108 return undef;
2111 $self->{vars}->{ad_dc_ntvfs} = $env;
2113 return $env;
2116 sub setup_chgdcpass($$)
2118 my ($self, $path) = @_;
2120 my $env = $self->provision_chgdcpass($path);
2121 if (defined $env) {
2122 if (not defined($self->check_or_start($env, "standard"))) {
2123 return undef;
2126 $self->{vars}->{chgdcpass} = $env;
2128 return $env;
2131 sub setup_fl2000dc($$)
2133 my ($self, $path) = @_;
2135 my $env = $self->provision_fl2000dc($path);
2136 if (defined $env) {
2137 if (not defined($self->check_or_start($env, "standard"))) {
2138 return undef;
2141 $self->{vars}->{fl2000dc} = $env;
2144 return $env;
2147 sub setup_fl2003dc($$$)
2149 my ($self, $path, $dc_vars) = @_;
2151 my $env = $self->provision_fl2003dc($path);
2153 if (defined $env) {
2154 if (not defined($self->check_or_start($env, "standard"))) {
2155 return undef;
2158 $env = $self->setup_trust($env, $dc_vars, "external", "--no-aes-keys");
2160 $self->{vars}->{fl2003dc} = $env;
2162 return $env;
2165 sub setup_fl2008r2dc($$$)
2167 my ($self, $path, $dc_vars) = @_;
2169 my $env = $self->provision_fl2008r2dc($path);
2171 if (defined $env) {
2172 if (not defined($self->check_or_start($env, "standard"))) {
2173 return undef;
2176 my $upn_array = ["$env->{REALM}.upn"];
2177 my $spn_array = ["$env->{REALM}.spn"];
2179 $self->setup_namespaces($env, $upn_array, $spn_array);
2181 $env = $self->setup_trust($env, $dc_vars, "forest", "");
2183 $self->{vars}->{fl2008r2dc} = $env;
2186 return $env;
2189 sub setup_vampire_dc($$$)
2191 my ($self, $path, $dc_vars) = @_;
2193 my $env = $self->provision_vampire_dc($path, $dc_vars);
2195 if (defined $env) {
2196 if (not defined($self->check_or_start($env, "single"))) {
2197 return undef;
2200 $self->{vars}->{vampire_dc} = $env;
2202 # force replicated DC to update repsTo/repsFrom
2203 # for vampired partitions
2204 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2205 my $cmd = "";
2206 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2207 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2208 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2209 } else {
2210 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2212 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2213 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2214 $cmd .= " $samba_tool drs kcc -k no $env->{DC_SERVER}";
2215 $cmd .= " $env->{CONFIGURATION}";
2216 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2217 unless (system($cmd) == 0) {
2218 warn("Failed to exec kcc on remote DC\n$cmd");
2219 return undef;
2222 # as 'vampired' dc may add data in its local replica
2223 # we need to synchronize data between DCs
2224 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2225 $cmd = "";
2226 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\" ";
2227 if (defined($env->{RESOLV_WRAPPER_CONF})) {
2228 $cmd .= "RESOLV_WRAPPER_CONF=\"$env->{RESOLV_WRAPPER_CONF}\" ";
2229 } else {
2230 $cmd .= "RESOLV_WRAPPER_HOSTS=\"$env->{RESOLV_WRAPPER_HOSTS}\" ";
2232 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2233 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2234 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2235 $cmd .= " $dc_vars->{CONFIGURATION}";
2236 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2237 # replicate Configuration NC
2238 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2239 unless(system($cmd_repl) == 0) {
2240 warn("Failed to replicate\n$cmd_repl");
2241 return undef;
2243 # replicate Default NC
2244 $cmd_repl = "$cmd \"$base_dn\"";
2245 unless(system($cmd_repl) == 0) {
2246 warn("Failed to replicate\n$cmd_repl");
2247 return undef;
2251 return $env;
2254 sub setup_promoted_dc($$$)
2256 my ($self, $path, $dc_vars) = @_;
2258 my $env = $self->provision_promoted_dc($path, $dc_vars);
2260 if (defined $env) {
2261 if (not defined($self->check_or_start($env, "single"))) {
2262 return undef;
2265 $self->{vars}->{promoted_dc} = $env;
2267 # force source and replicated DC to update repsTo/repsFrom
2268 # for vampired partitions
2269 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2270 my $cmd = "";
2271 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2272 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2273 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2274 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
2275 $cmd .= " $env->{CONFIGURATION}";
2276 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2277 unless (system($cmd) == 0) {
2278 warn("Failed to exec kcc on remote DC\n$cmd");
2279 return undef;
2282 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2283 my $cmd = "";
2284 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2285 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2286 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2287 $cmd .= " $samba_tool drs kcc $env->{SERVER}";
2288 $cmd .= " $env->{CONFIGURATION}";
2289 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2290 unless (system($cmd) == 0) {
2291 warn("Failed to exec kcc on promoted DC\n$cmd");
2292 return undef;
2295 # as 'vampired' dc may add data in its local replica
2296 # we need to synchronize data between DCs
2297 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2298 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2299 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2300 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2301 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SERVER}";
2302 $cmd .= " $dc_vars->{CONFIGURATION}";
2303 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2304 # replicate Configuration NC
2305 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2306 unless(system($cmd_repl) == 0) {
2307 warn("Failed to replicate\n$cmd_repl");
2308 return undef;
2310 # replicate Default NC
2311 $cmd_repl = "$cmd \"$base_dn\"";
2312 unless(system($cmd_repl) == 0) {
2313 warn("Failed to replicate\n$cmd_repl");
2314 return undef;
2318 return $env;
2321 sub setup_subdom_dc($$$)
2323 my ($self, $path, $dc_vars) = @_;
2325 my $env = $self->provision_subdom_dc($path, $dc_vars);
2327 if (defined $env) {
2328 if (not defined($self->check_or_start($env, "single"))) {
2329 return undef;
2332 $self->{vars}->{subdom_dc} = $env;
2334 # force replicated DC to update repsTo/repsFrom
2335 # for primary domain partitions
2336 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2337 my $cmd = "";
2338 $cmd .= "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2339 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2340 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2341 $cmd .= " $samba_tool drs kcc $env->{DC_SERVER}";
2342 $cmd .= " $env->{CONFIGURATION}";
2343 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2344 unless (system($cmd) == 0) {
2345 warn("Failed to exec kcc on remote DC\n$cmd");
2346 return undef;
2349 # as 'subdomain' dc may add data in its local replica
2350 # we need to synchronize data between DCs
2351 my $base_dn = "DC=".join(",DC=", split(/\./, $env->{REALM}));
2352 my $config_dn = "CN=Configuration,DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2353 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2354 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2355 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2356 $cmd .= " $samba_tool drs replicate $env->{DC_SERVER} $env->{SUBDOM_DC_SERVER}";
2357 $cmd .= " $dc_vars->{CONFIGURATION}";
2358 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD} --realm=$dc_vars->{DC_REALM}";
2359 # replicate Configuration NC
2360 my $cmd_repl = "$cmd \"$config_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_rodc($$$)
2378 my ($self, $path, $dc_vars) = @_;
2380 my $env = $self->provision_rodc($path, $dc_vars);
2382 unless ($env) {
2383 return undef;
2386 if (not defined($self->check_or_start($env, "single"))) {
2387 return undef;
2390 my $samba_tool = Samba::bindir_path($self, "samba-tool");
2391 my $cmd = "";
2393 my $base_dn = "DC=".join(",DC=", split(/\./, $dc_vars->{REALM}));
2394 $cmd = "SOCKET_WRAPPER_DEFAULT_IFACE=\"$env->{SOCKET_WRAPPER_DEFAULT_IFACE}\"";
2395 $cmd .= " KRB5_CONFIG=\"$env->{KRB5_CONFIG}\"";
2396 $cmd .= "KRB5CCNAME=\"$env->{KRB5_CCACHE}\" ";
2397 $cmd .= " $samba_tool drs replicate $env->{SERVER} $env->{DC_SERVER}";
2398 $cmd .= " $dc_vars->{CONFIGURATION}";
2399 $cmd .= " -U$dc_vars->{DC_USERNAME}\%$dc_vars->{DC_PASSWORD}";
2400 # replicate Configuration NC
2401 my $cmd_repl = "$cmd \"CN=Configuration,$base_dn\"";
2402 unless(system($cmd_repl) == 0) {
2403 warn("Failed to replicate\n$cmd_repl");
2404 return undef;
2406 # replicate Default NC
2407 $cmd_repl = "$cmd \"$base_dn\"";
2408 unless(system($cmd_repl) == 0) {
2409 warn("Failed to replicate\n$cmd_repl");
2410 return undef;
2413 $self->{vars}->{rodc} = $env;
2415 return $env;
2418 sub setup_ad_dc($$)
2420 my ($self, $path, $no_nss) = @_;
2422 # If we didn't build with ADS, pretend this env was never available
2423 if (not $self->{target3}->have_ads()) {
2424 return "UNKNOWN";
2427 my $env = $self->provision_ad_dc($path);
2428 unless ($env) {
2429 return undef;
2432 if (defined($no_nss) and $no_nss) {
2433 $env->{NSS_WRAPPER_MODULE_SO_PATH} = undef;
2434 $env->{NSS_WRAPPER_MODULE_FN_PREFIX} = undef;
2437 if (not defined($self->check_or_start($env, "single"))) {
2438 return undef;
2441 my $upn_array = ["$env->{REALM}.upn"];
2442 my $spn_array = ["$env->{REALM}.spn"];
2444 $self->setup_namespaces($env, $upn_array, $spn_array);
2446 $self->{vars}->{ad_dc} = $env;
2447 return $env;
2450 sub setup_none($$)
2452 my ($self, $path) = @_;
2454 my $ret = {
2455 KRB5_CONFIG => abs_path($path) . "/no_krb5.conf",
2456 SAMBA_PID => -1,