3 '''automated testing of the steps of the Samba4 HOWTO'''
7 import wintest, pexpect, time
9 def check_prerequesites(t):
10 t.info("Checking prerequesites")
11 t.setvar('HOSTNAME', t.cmd_output("hostname -s").strip())
13 raise Exception("You must run this script as root")
14 t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
15 t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_NET} up')
16 if t.getvar('INTERFACE_IPV6'):
17 t.run_cmd('ifconfig ${INTERFACE} inet6 del ${INTERFACE_IPV6}/64', checkfail=False)
18 t.run_cmd('ifconfig ${INTERFACE} inet6 add ${INTERFACE_IPV6}/64 up')
24 t.chdir('${SOURCETREE}/source4')
25 t.putenv('CC', 'ccache gcc')
26 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
28 t.run_cmd('rm -rf ${PREFIX}')
29 t.run_cmd('make -j install')
32 def provision_s4(t, func_level="2008"):
33 '''provision s4 as a DC'''
34 t.info('Provisioning s4')
36 t.del_files(["var", "private"])
37 t.run_cmd("rm -f etc/smb.conf")
38 provision=['sbin/provision',
41 '--adminpass=${PASSWORD1}',
42 '--server-role=domain controller',
43 '--function-level=%s' % func_level,
45 '--option=interfaces=${INTERFACE}',
46 '--host-ip=${INTERFACE_IP}',
47 '--option=bind interfaces only=yes',
48 '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
49 if t.getvar('INTERFACE_IPV6'):
50 provision.append('--host-ip6=${INTERFACE_IPV6}')
52 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
53 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
54 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
59 t.info('Starting Samba4')
61 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
62 t.run_cmd(['sbin/samba',
63 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
64 t.port_wait("${INTERFACE_IP}", 139)
67 '''Shut down any existing alive VMs, so they do not collide with what we are doing'''
68 t.info('Shutting down any of our VMs already running')
71 t.vm_poweroff(v, checkfail=False)
73 def test_smbclient(t):
75 t.info('Testing smbclient')
77 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
78 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
79 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
82 child.expect("blocks available")
83 child.sendline("mkdir testdir")
85 child.sendline("cd testdir")
86 child.expect('testdir')
87 child.sendline("cd ..")
88 child.sendline("rmdir testdir")
92 '''create some test shares'''
93 t.info("Adding test shares")
95 t.write_file("etc/smb.conf", '''
100 path = ${PREFIX}/var/profiles
104 t.run_cmd("mkdir -p test")
105 t.run_cmd("mkdir -p var/profiles")
108 def set_nameserver(t, nameserver):
109 '''set the nameserver in resolv.conf'''
110 t.write_file("/etc/resolv.conf.wintest", '''
111 # Generated by wintest, the Samba v Windows automated testing system
114 # your original resolv.conf appears below:
115 ''' % t.substitute(nameserver))
116 child = t.pexpect_spawn("cat /etc/resolv.conf", crlf=False)
117 i = child.expect(['your original resolv.conf appears below:', pexpect.EOF])
119 child.expect(pexpect.EOF)
120 contents = child.before.lstrip().replace('\r', '')
121 t.write_file('/etc/resolv.conf.wintest', contents, mode='a')
122 t.write_file('/etc/resolv.conf.wintest-bak', contents)
123 t.run_cmd("mv -f /etc/resolv.conf.wintest /etc/resolv.conf")
124 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
127 def restore_resolv_conf(t):
128 '''restore the /etc/resolv.conf after testing is complete'''
129 if getattr(t, 'resolv_conf_backup', False):
130 t.info("restoring /etc/resolv.conf")
131 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
133 def rndc_cmd(t, cmd, checkfail=True):
134 '''run a rndc command'''
135 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
139 '''restart the test environment version of bind'''
140 t.info("Restarting bind9")
141 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
142 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
145 nameserver = t.get_nameserver()
146 if nameserver == t.getvar('INTERFACE_IP'):
147 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
148 t.setvar('DNSSERVER', nameserver)
150 if t.getvar('INTERFACE_IPV6'):
151 ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
154 t.setvar('BIND_LISTEN_IPV6', ipv6_listen)
156 t.write_file("etc/named.conf", '''
158 listen-on port 53 { ${INTERFACE_IP}; };
160 directory "${PREFIX}/var/named";
161 dump-file "${PREFIX}/var/named/data/cache_dump.db";
162 pid-file "${PREFIX}/var/named/named.pid";
163 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
164 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
165 allow-query { any; };
167 tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
168 tkey-domain "${REALM}";
181 secret "lA/cTrno03mt5Ju17ybEYw==";
185 inet ${INTERFACE_IP} port 953
186 allow { any; } keys { "rndc-key"; };
189 include "${PREFIX}/private/named.conf";
192 # add forwarding for the windows domains
193 domains = t.get_domains()
195 t.write_file('etc/named.conf',
204 ''' % (d, domains[d]),
208 t.write_file("etc/rndc.conf", '''
212 secret "lA/cTrno03mt5Ju17ybEYw==";
216 default-key "rndc-key";
217 default-server ${INTERFACE_IP};
222 set_nameserver(t, t.getvar('INTERFACE_IP'))
224 rndc_cmd(t, "stop", checkfail=False)
225 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
227 t.run_cmd("rm -rf var/named")
228 t.run_cmd("mkdir -p var/named/data")
229 t.run_cmd("chown -R ${BIND_USER} var/named")
231 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
233 t.port_wait("${INTERFACE_IP}", 53)
238 '''test that DNS is OK'''
239 t.info("Testing DNS")
240 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
241 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
242 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
243 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
244 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
245 ['${HOSTNAME}.${LCREALM} has address'])
247 def test_kerberos(t):
248 '''test that kerberos is OK'''
249 t.info("Testing kerberos")
250 t.run_cmd("kdestroy")
251 t.kinit("administrator@${REALM}", "${PASSWORD1}")
252 # this copes with the differences between MIT and Heimdal klist
253 t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
257 '''test that dynamic DNS is working'''
259 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
263 def run_winjoin(t, vm):
264 '''join a windows box to our domain'''
267 t.info("Joining a windows box to the domain")
268 t.vm_poweroff("${WIN_VM}", checkfail=False)
269 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
270 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
271 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
272 child.expect("The command completed successfully")
274 child.sendline("shutdown /r -t 0")
276 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
277 child.sendline("ipconfig /registerdns")
278 child.expect("Registration of the DNS resource records for all adapters of this computer has been initiated. Any errors will be reported in the Event Viewer")
281 def test_winjoin(t, vm):
282 t.info("Checking the windows join is OK")
284 t.port_wait("${WIN_IP}", 139)
285 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
286 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
287 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
288 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
289 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
290 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
291 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
292 child.expect("The command completed successfully")
293 t.vm_poweroff("${WIN_VM}")
296 def run_dcpromo(t, vm):
297 '''run a dcpromo on windows'''
300 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
301 t.vm_poweroff("${WIN_VM}", checkfail=False)
302 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
303 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
304 child.sendline("copy /Y con answers.txt")
308 RebootOnCompletion=Yes
309 ReplicaOrNewDomain=Replica
310 ReplicaDomainDNSName=${LCREALM}
311 SiteName=Default-First-Site-Name
314 CreateDNSDelegation=No
315 UserDomain=${LCREALM}
316 UserName=${LCREALM}\\administrator
317 Password=${PASSWORD1}
318 DatabasePath="C:\Windows\NTDS"
319 LogPath="C:\Windows\NTDS"
320 SYSVOLPath="C:\Windows\SYSVOL"
321 SafeModeAdminPassword=${PASSWORD1}
324 child.expect("copied.")
327 child.sendline("dcpromo /answer:answers.txt")
328 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
330 raise Exception("dcpromo failed")
334 def test_dcpromo(t, vm):
335 '''test that dcpromo worked'''
336 t.info("Checking the dcpromo join is OK")
338 t.port_wait("${WIN_IP}", 139)
339 t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
340 ['${WIN_HOSTNAME}.${LCREALM} has address'],
341 retries=30, delay=10, casefold=True)
342 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
343 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
344 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
346 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
347 t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
349 t.kinit("administrator@${REALM}", "${PASSWORD1}")
351 # the first replication will transfer the dnsHostname attribute
352 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
354 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
355 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
356 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
358 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
359 [ "INBOUND NEIGHBORS",
361 "Last attempt .* was successful",
362 "CN=Configuration,${BASEDN}",
363 "Last attempt .* was successful",
364 "CN=Configuration,${BASEDN}", # cope with either order
365 "Last attempt .* was successful",
366 "OUTBOUND NEIGHBORS",
369 "CN=Configuration,${BASEDN}",
371 "CN=Configuration,${BASEDN}",
376 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
377 [ "INBOUND NEIGHBORS",
379 "Last attempt .* was successful",
380 "CN=Configuration,${BASEDN}",
381 "Last attempt .* was successful",
382 "CN=Configuration,${BASEDN}",
383 "Last attempt .* was successful",
384 "OUTBOUND NEIGHBORS",
387 "CN=Configuration,${BASEDN}",
389 "CN=Configuration,${BASEDN}",
394 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
395 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
398 i = child.expect(["The command completed successfully", "The network path was not found"])
399 while i == 1 and retries > 0:
402 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
403 i = child.expect(["The command completed successfully", "The network path was not found"])
406 t.run_net_time(child)
408 t.info("Checking if showrepl is happy")
409 child.sendline("repadmin /showrepl")
410 child.expect("${BASEDN}")
411 child.expect("was successful")
412 child.expect("CN=Configuration,${BASEDN}")
413 child.expect("was successful")
414 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
415 child.expect("was successful")
417 t.info("Checking if new users propogate to windows")
418 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
419 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
420 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
422 t.info("Checking if new users on windows propogate to samba")
423 child.sendline("net user test3 ${PASSWORD3} /add")
425 i = child.expect(["The command completed successfully",
426 "The directory service was unable to allocate a relative identifier"])
431 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
432 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
434 t.info("Checking propogation of user deletion")
435 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
436 child.sendline("net user test3 /del")
437 child.expect("The command completed successfully")
439 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
440 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
441 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
442 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
443 t.vm_poweroff("${WIN_VM}")
446 def run_dcpromo_rodc(t, vm):
447 '''run a RODC dcpromo to join a windows DC to the samba domain'''
449 t.info("Joining a w2k8 box to the domain as a RODC")
450 t.vm_poweroff("${WIN_VM}", checkfail=False)
451 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
452 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
453 child.sendline("copy /Y con answers.txt")
456 ReplicaOrNewDomain=ReadOnlyReplica
457 ReplicaDomainDNSName=${LCREALM}
458 PasswordReplicationDenied="BUILTIN\Administrators"
459 PasswordReplicationDenied="BUILTIN\Server Operators"
460 PasswordReplicationDenied="BUILTIN\Backup Operators"
461 PasswordReplicationDenied="BUILTIN\Account Operators"
462 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
463 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
464 DelegatedAdmin="${DOMAIN}\\Administrator"
465 SiteName=Default-First-Site-Name
468 CreateDNSDelegation=No
469 UserDomain=${LCREALM}
470 UserName=${LCREALM}\\administrator
471 Password=${PASSWORD1}
472 DatabasePath="C:\Windows\NTDS"
473 LogPath="C:\Windows\NTDS"
474 SYSVOLPath="C:\Windows\SYSVOL"
475 SafeModeAdminPassword=${PASSWORD1}
476 RebootOnCompletion=No
479 child.expect("copied.")
480 child.sendline("dcpromo /answer:answers.txt")
481 i = child.expect(["You must restart this computer", "failed"], timeout=120)
483 raise Exception("dcpromo failed")
484 child.sendline("shutdown -r -t 0")
489 def test_dcpromo_rodc(t, vm):
490 '''test the RODC dcpromo worked'''
491 t.info("Checking the w2k8 RODC join is OK")
493 t.port_wait("${WIN_IP}", 139)
494 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
495 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
496 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
497 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
498 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
499 child.expect("The command completed successfully")
501 t.info("Checking if showrepl is happy")
502 child.sendline("repadmin /showrepl")
503 child.expect("${BASEDN}")
504 child.expect("was successful")
505 child.expect("CN=Configuration,${BASEDN}")
506 child.expect("was successful")
507 child.expect("CN=Configuration,${BASEDN}")
508 child.expect("was successful")
510 t.info("Checking if new users are available on windows")
511 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
512 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
513 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
514 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN} -k yes", ["was successful"])
515 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
516 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
517 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
518 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
519 t.vm_poweroff("${WIN_VM}")
522 def prep_join_as_dc(t, vm):
523 '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
525 t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
527 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
528 t.vm_poweroff("${WIN_VM}", checkfail=False)
529 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
531 t.run_cmd("rm -rf etc/smb.conf private")
532 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
533 t.get_ipconfig(child)
535 def join_as_dc(t, vm):
536 '''join a windows domain as a DC'''
538 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
539 t.port_wait("${WIN_IP}", 389)
540 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
542 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
543 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
544 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
547 def test_join_as_dc(t, vm):
548 '''test the join of a windows domain as a DC'''
549 t.info("Checking the DC join is OK")
551 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
552 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
553 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
555 t.info("Forcing kcc runs, and replication")
556 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
557 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
559 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
560 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
561 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
562 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
566 while i == 1 and retries > 0:
567 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
568 i = child.expect(["The command completed successfully", "The network path was not found"])
574 t.info("Checking if showrepl is happy")
575 child.sendline("repadmin /showrepl")
576 child.expect("${WIN_BASEDN}")
577 child.expect("was successful")
578 child.expect("CN=Configuration,${WIN_BASEDN}")
579 child.expect("was successful")
580 child.expect("CN=Configuration,${WIN_BASEDN}")
581 child.expect("was successful")
583 t.info("Checking if new users propogate to windows")
584 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
585 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
586 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
588 t.info("Checking if new users on windows propogate to samba")
589 child.sendline("net user test3 ${PASSWORD3} /add")
590 child.expect("The command completed successfully")
591 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
592 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
594 t.info("Checking propogation of user deletion")
595 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
596 child.sendline("net user test3 /del")
597 child.expect("The command completed successfully")
599 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
600 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
601 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
602 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
603 t.vm_poweroff("${WIN_VM}")
606 def join_as_rodc(t, vm):
607 '''join a windows domain as a RODC'''
609 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
610 t.port_wait("${WIN_IP}", 389)
611 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
612 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
613 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
614 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
617 def test_join_as_rodc(t, vm):
618 '''test a windows domain RODC join'''
619 t.info("Checking the RODC join is OK")
621 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
622 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
623 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
625 t.info("Forcing kcc runs, and replication")
626 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
627 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
629 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
630 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
631 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
635 while i == 1 and retries > 0:
636 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
637 i = child.expect(["The command completed successfully", "The network path was not found"])
643 t.info("Checking if showrepl is happy")
644 child.sendline("repadmin /showrepl")
645 child.expect("DSA invocationID")
647 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
648 [ "INBOUND NEIGHBORS",
649 "OUTBOUND NEIGHBORS",
651 "Last attempt .* was successful",
652 "CN=Configuration,${WIN_BASEDN}",
653 "Last attempt .* was successful",
654 "CN=Configuration,${WIN_BASEDN}",
655 "Last attempt .* was successful" ],
659 t.info("Checking if new users on windows propogate to samba")
660 child.sendline("net user test3 ${PASSWORD3} /add")
661 child.expect("The command completed successfully")
662 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
663 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
666 t.info("Checking if new users propogate to windows")
667 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
669 t.info("Checking propogation of user deletion")
670 child.sendline("net user test3 /del")
671 child.expect("The command completed successfully")
673 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
674 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
675 t.vm_poweroff("${WIN_VM}")
678 def run_dcpromo_as_first_dc(t, vm, func_level=None):
680 t.info("Configuring a windows VM ${WIN_VM} at the first DC in the domain using dcpromo")
681 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
682 child.sendline("dcdiag");
683 if t.get_is_dc(child):
686 if func_level == '2008r2':
687 t.setvar("FUNCTION_LEVEL_INT", str(4))
688 elif func_level == '2003':
689 t.setvar("FUNCTION_LEVEL_INT", str(1))
691 t.setvar("FUNCTION_LEVEL_INT", str(0))
693 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
694 child.sendline("dcdiag");
696 """This server must therefore not yet be a directory server, so we must promote it"""
697 child.sendline("copy /Y con answers.txt")
700 ; New forest promotion
701 ReplicaOrNewDomain=Domain
703 NewDomainDNSName=${WIN_REALM}
704 ForestLevel=${FUNCTION_LEVEL_INT}
705 DomainNetbiosName=${WIN_DOMAIN}
706 DomainLevel=${FUNCTION_LEVEL_INT}
709 CreateDNSDelegation=No
710 DatabasePath="C:\Windows\NTDS"
711 LogPath="C:\Windows\NTDS"
712 SYSVOLPath="C:\Windows\SYSVOL"
713 ; Set SafeModeAdminPassword to the correct value prior to using the unattend file
714 SafeModeAdminPassword=${WIN_PASS}
715 ; Run-time flags (optional)
716 RebootOnCompletion=No
719 child.expect("copied.")
722 child.sendline("dcpromo /answer:answers.txt")
723 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
725 raise Exception("dcpromo failed")
726 child.sendline("shutdown -r -t 0")
727 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
728 t.port_wait("${WIN_IP}", 139)
731 '''test the Samba4 howto'''
733 check_prerequesites(t)
735 # we don't need fsync safety in these tests
736 t.putenv('TDB_NO_FSYNC', '1')
738 if not t.skip("build"):
741 if not t.skip("provision"):
744 if not t.skip("create-shares"):
747 if not t.skip("starts4"):
749 if not t.skip("stop_vms"):
751 if not t.skip("smbclient"):
753 if not t.skip("startbind"):
755 if not t.skip("dns"):
757 if not t.skip("kerberos"):
759 if not t.skip("dyndns"):
762 if t.have_vm('WINDOWS7') and not t.skip("windows7"):
763 run_winjoin(t, "WINDOWS7")
764 test_winjoin(t, "WINDOWS7")
766 if t.have_vm('WINXP') and not t.skip("winxp"):
767 run_winjoin(t, "WINXP")
768 test_winjoin(t, "WINXP")
770 if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
771 t.info("Testing w2k8r2 RODC dcpromo")
772 run_dcpromo_rodc(t, "W2K8R2C")
773 test_dcpromo_rodc(t, "W2K8R2C")
775 if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
776 t.info("Testing w2k8r2 dcpromo")
777 run_dcpromo(t, "W2K8R2B")
778 test_dcpromo(t, "W2K8R2B")
780 if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
781 t.info("Testing w2k8 dcpromo")
782 run_dcpromo(t, "W2K8B")
783 test_dcpromo(t, "W2K8B")
785 if t.have_vm('W2K3B') and not t.skip("dcpromo_w2k3"):
786 t.info("Testing w2k3 dcpromo")
787 t.info("Changing to 2003 functional level")
788 provision_s4(t, func_level='2003')
796 run_dcpromo(t, "W2K3B")
797 test_dcpromo(t, "W2K3B")
799 if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
800 prep_join_as_dc(t, "W2K8R2A")
801 run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
802 join_as_dc(t, "W2K8R2A")
806 test_join_as_dc(t, "W2K8R2A")
808 if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
809 prep_join_as_dc(t, "W2K8R2A")
810 run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
811 join_as_rodc(t, "W2K8R2A")
815 test_join_as_rodc(t, "W2K8R2A")
817 if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
818 prep_join_as_dc(t, "W2K3A")
819 run_dcpromo_as_first_dc(t, "W2K3A", func_level='2003')
820 join_as_dc(t, "W2K3A")
824 test_join_as_dc(t, "W2K3A")
826 t.info("Howto test: All OK")
830 '''cleanup after tests'''
831 t.info("Cleaning up ...")
832 restore_resolv_conf(t)
833 if getattr(t, 'bind_child', False):
837 if __name__ == '__main__':
838 parser = optparse.OptionParser("test-howto.py")
839 parser.add_option("--conf", type='string', default='', help='config file')
840 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
841 parser.add_option("--vms", type='string', default=None, help='list of VMs to use (comma separated)')
842 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
843 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
844 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
845 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
846 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
847 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
849 opts, args = parser.parse_args()
852 print("Please specify a config file with --conf")
855 t = wintest.wintest()
856 t.load_config(opts.conf)
858 t.set_skip(opts.skip)
865 t.setvar('PREFIX', opts.prefix)
868 t.setvar('SOURCETREE', opts.sourcetree)
872 t.chdir('${SOURCETREE}')
873 t.run_cmd('git pull --rebase')
877 t.chdir('${SOURCETREE}/source4')
878 t.run_cmd('rm -rf bin')
883 if not opts.nocleanup:
887 if not opts.nocleanup:
889 t.info("S4 howto test: All OK")