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')
23 t.chdir('${SOURCETREE}/source4')
24 t.putenv('CC', 'ccache gcc')
25 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
27 t.run_cmd('rm -rf ${PREFIX}')
28 t.run_cmd('make -j install')
31 def provision_s4(t, func_level="2008"):
32 '''provision s4 as a DC'''
33 t.info('Provisioning s4')
35 t.del_files(["var", "private"])
36 t.run_cmd("rm -f etc/smb.conf")
37 provision=['sbin/provision',
40 '--adminpass=${PASSWORD1}',
41 '--server-role=domain controller',
42 '--function-level=%s' % func_level,
44 '--option=interfaces=${INTERFACE}',
45 '--host-ip=${INTERFACE_IP}',
46 '--option=bind interfaces only=yes',
47 '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
48 if t.getvar('INTERFACE_IPV6'):
49 provision.append('--host-ip6=${INTERFACE_IPV6}')
51 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
52 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
53 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
58 t.info('Starting Samba4')
60 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
61 t.run_cmd(['sbin/samba',
62 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
63 t.port_wait("${INTERFACE_IP}", 139)
66 '''Shut down any existing alive VMs, so they do not collide with what we are doing'''
67 t.info('Shutting down any of our VMs already running')
70 t.vm_poweroff(v, checkfail=False)
72 def test_smbclient(t):
74 t.info('Testing smbclient')
76 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
77 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
78 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
81 child.expect("blocks available")
82 child.sendline("mkdir testdir")
84 child.sendline("cd testdir")
85 child.expect('testdir')
86 child.sendline("cd ..")
87 child.sendline("rmdir testdir")
91 '''create some test shares'''
92 t.info("Adding test shares")
94 t.write_file("etc/smb.conf", '''
99 path = ${PREFIX}/var/profiles
103 t.run_cmd("mkdir -p test")
104 t.run_cmd("mkdir -p var/profiles")
107 def set_nameserver(t, nameserver):
108 '''set the nameserver in resolv.conf'''
109 t.write_file("/etc/resolv.conf.wintest", '''
110 # Generated by wintest, the Samba v Windows automated testing system
113 # your original resolv.conf appears below:
114 ''' % t.substitute(nameserver))
115 child = t.pexpect_spawn("cat /etc/resolv.conf", crlf=False)
116 i = child.expect(['your original resolv.conf appears below:', pexpect.EOF])
118 child.expect(pexpect.EOF)
119 contents = child.before.lstrip().replace('\r', '')
120 t.write_file('/etc/resolv.conf.wintest', contents, mode='a')
121 t.write_file('/etc/resolv.conf.wintest-bak', contents)
122 t.run_cmd("mv -f /etc/resolv.conf.wintest /etc/resolv.conf")
123 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
126 def restore_resolv_conf(t):
127 '''restore the /etc/resolv.conf after testing is complete'''
128 if getattr(t, 'resolv_conf_backup', False):
129 t.info("restoring /etc/resolv.conf")
130 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)
137 def configure_bind(t):
140 nameserver = t.get_nameserver()
141 if nameserver == t.getvar('INTERFACE_IP'):
142 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
143 t.setvar('DNSSERVER', nameserver)
145 if t.getvar('INTERFACE_IPV6'):
146 ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
149 t.setvar('BIND_LISTEN_IPV6', ipv6_listen)
151 t.write_file("etc/named.conf", '''
153 listen-on port 53 { ${INTERFACE_IP}; };
155 directory "${PREFIX}/var/named";
156 dump-file "${PREFIX}/var/named/data/cache_dump.db";
157 pid-file "${PREFIX}/var/named/named.pid";
158 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
159 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
160 allow-query { any; };
162 tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
163 tkey-domain "${REALM}";
176 secret "lA/cTrno03mt5Ju17ybEYw==";
180 inet ${INTERFACE_IP} port 953
181 allow { any; } keys { "rndc-key"; };
184 include "${PREFIX}/private/named.conf";
187 # add forwarding for the windows domains
188 domains = t.get_domains()
190 t.write_file('etc/named.conf',
199 ''' % (d, domains[d]),
203 t.write_file("etc/rndc.conf", '''
207 secret "lA/cTrno03mt5Ju17ybEYw==";
211 default-key "rndc-key";
212 default-server ${INTERFACE_IP};
217 set_nameserver(t, t.getvar('INTERFACE_IP'))
221 '''Stop our private BIND from listening and operating'''
222 rndc_cmd(t, "stop", checkfail=False)
223 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
225 t.run_cmd("rm -rf var/named")
229 '''restart the test environment version of bind'''
230 t.info("Restarting bind9")
231 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
232 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
235 set_nameserver(t, t.getvar('INTERFACE_IP'))
237 t.run_cmd("mkdir -p var/named/data")
238 t.run_cmd("chown -R ${BIND_USER} var/named")
240 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
242 t.port_wait("${INTERFACE_IP}", 53)
251 '''test that DNS is OK'''
252 t.info("Testing DNS")
253 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
254 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
255 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
256 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
257 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
258 ['${HOSTNAME}.${LCREALM} has address'])
260 def test_kerberos(t):
261 '''test that kerberos is OK'''
262 t.info("Testing kerberos")
263 t.run_cmd("kdestroy")
264 t.kinit("administrator@${REALM}", "${PASSWORD1}")
265 # this copes with the differences between MIT and Heimdal klist
266 t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
270 '''test that dynamic DNS is working'''
272 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
276 def run_winjoin(t, vm):
277 '''join a windows box to our domain'''
280 t.info("Joining a windows box to the domain")
281 t.vm_poweroff("${WIN_VM}", checkfail=False)
282 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
283 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
284 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
285 child.expect("The command completed successfully")
287 child.sendline("shutdown /r -t 0")
289 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
290 child.sendline("ipconfig /registerdns")
291 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")
294 def test_winjoin(t, vm):
295 t.info("Checking the windows join is OK")
297 t.port_wait("${WIN_IP}", 139)
298 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
299 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
300 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
301 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
302 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
303 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
304 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
305 child.expect("The command completed successfully")
306 t.vm_poweroff("${WIN_VM}")
309 def run_dcpromo(t, vm):
310 '''run a dcpromo on windows'''
313 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
314 t.vm_poweroff("${WIN_VM}", checkfail=False)
315 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
316 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
317 child.sendline("copy /Y con answers.txt")
321 RebootOnCompletion=Yes
322 ReplicaOrNewDomain=Replica
323 ReplicaDomainDNSName=${LCREALM}
324 SiteName=Default-First-Site-Name
327 CreateDNSDelegation=No
328 UserDomain=${LCREALM}
329 UserName=${LCREALM}\\administrator
330 Password=${PASSWORD1}
331 DatabasePath="C:\Windows\NTDS"
332 LogPath="C:\Windows\NTDS"
333 SYSVOLPath="C:\Windows\SYSVOL"
334 SafeModeAdminPassword=${PASSWORD1}
337 child.expect("copied.")
340 child.sendline("dcpromo /answer:answers.txt")
341 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
343 raise Exception("dcpromo failed")
347 def test_dcpromo(t, vm):
348 '''test that dcpromo worked'''
349 t.info("Checking the dcpromo join is OK")
351 t.port_wait("${WIN_IP}", 139)
352 t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
353 ['${WIN_HOSTNAME}.${LCREALM} has address'],
354 retries=30, delay=10, casefold=True)
355 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
356 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
357 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
359 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
360 t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
362 t.kinit("administrator@${REALM}", "${PASSWORD1}")
364 # the first replication will transfer the dnsHostname attribute
365 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
367 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
368 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
369 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
371 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
372 [ "INBOUND NEIGHBORS",
374 "Last attempt .* was successful",
375 "CN=Configuration,${BASEDN}",
376 "Last attempt .* was successful",
377 "CN=Configuration,${BASEDN}", # cope with either order
378 "Last attempt .* was successful",
379 "OUTBOUND NEIGHBORS",
382 "CN=Configuration,${BASEDN}",
384 "CN=Configuration,${BASEDN}",
389 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
390 [ "INBOUND NEIGHBORS",
392 "Last attempt .* was successful",
393 "CN=Configuration,${BASEDN}",
394 "Last attempt .* was successful",
395 "CN=Configuration,${BASEDN}",
396 "Last attempt .* was successful",
397 "OUTBOUND NEIGHBORS",
400 "CN=Configuration,${BASEDN}",
402 "CN=Configuration,${BASEDN}",
407 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
408 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
411 i = child.expect(["The command completed successfully", "The network path was not found"])
412 while i == 1 and retries > 0:
415 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
416 i = child.expect(["The command completed successfully", "The network path was not found"])
419 t.run_net_time(child)
421 t.info("Checking if showrepl is happy")
422 child.sendline("repadmin /showrepl")
423 child.expect("${BASEDN}")
424 child.expect("was successful")
425 child.expect("CN=Configuration,${BASEDN}")
426 child.expect("was successful")
427 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
428 child.expect("was successful")
430 t.info("Checking if new users propogate to windows")
431 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
432 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
433 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
435 t.info("Checking if new users on windows propogate to samba")
436 child.sendline("net user test3 ${PASSWORD3} /add")
438 i = child.expect(["The command completed successfully",
439 "The directory service was unable to allocate a relative identifier"])
444 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
445 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
447 t.info("Checking propogation of user deletion")
448 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
449 child.sendline("net user test3 /del")
450 child.expect("The command completed successfully")
452 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
453 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
454 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
455 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
456 t.vm_poweroff("${WIN_VM}")
459 def run_dcpromo_rodc(t, vm):
460 '''run a RODC dcpromo to join a windows DC to the samba domain'''
462 t.info("Joining a w2k8 box to the domain as a RODC")
463 t.vm_poweroff("${WIN_VM}", checkfail=False)
464 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
465 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
466 child.sendline("copy /Y con answers.txt")
469 ReplicaOrNewDomain=ReadOnlyReplica
470 ReplicaDomainDNSName=${LCREALM}
471 PasswordReplicationDenied="BUILTIN\Administrators"
472 PasswordReplicationDenied="BUILTIN\Server Operators"
473 PasswordReplicationDenied="BUILTIN\Backup Operators"
474 PasswordReplicationDenied="BUILTIN\Account Operators"
475 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
476 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
477 DelegatedAdmin="${DOMAIN}\\Administrator"
478 SiteName=Default-First-Site-Name
481 CreateDNSDelegation=No
482 UserDomain=${LCREALM}
483 UserName=${LCREALM}\\administrator
484 Password=${PASSWORD1}
485 DatabasePath="C:\Windows\NTDS"
486 LogPath="C:\Windows\NTDS"
487 SYSVOLPath="C:\Windows\SYSVOL"
488 SafeModeAdminPassword=${PASSWORD1}
489 RebootOnCompletion=No
492 child.expect("copied.")
493 child.sendline("dcpromo /answer:answers.txt")
494 i = child.expect(["You must restart this computer", "failed"], timeout=120)
496 raise Exception("dcpromo failed")
497 child.sendline("shutdown -r -t 0")
502 def test_dcpromo_rodc(t, vm):
503 '''test the RODC dcpromo worked'''
504 t.info("Checking the w2k8 RODC join is OK")
506 t.port_wait("${WIN_IP}", 139)
507 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
508 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
509 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
510 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
511 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
512 child.expect("The command completed successfully")
514 t.info("Checking if showrepl is happy")
515 child.sendline("repadmin /showrepl")
516 child.expect("${BASEDN}")
517 child.expect("was successful")
518 child.expect("CN=Configuration,${BASEDN}")
519 child.expect("was successful")
520 child.expect("CN=Configuration,${BASEDN}")
521 child.expect("was successful")
523 t.info("Checking if new users are available on windows")
524 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
525 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
526 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
527 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN} -k yes", ["was successful"])
528 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
529 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
530 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
531 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
532 t.vm_poweroff("${WIN_VM}")
535 def prep_join_as_dc(t, vm):
536 '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
538 t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
540 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
541 t.vm_poweroff("${WIN_VM}", checkfail=False)
542 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
544 t.run_cmd("rm -rf etc/smb.conf private")
545 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
546 t.get_ipconfig(child)
548 def join_as_dc(t, vm):
549 '''join a windows domain as a DC'''
551 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
552 t.port_wait("${WIN_IP}", 389)
553 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
555 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
556 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
557 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
560 def test_join_as_dc(t, vm):
561 '''test the join of a windows domain as a DC'''
562 t.info("Checking the DC join is OK")
564 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
565 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
566 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
568 t.info("Forcing kcc runs, and replication")
569 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
570 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
572 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
573 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
574 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
575 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
579 while i == 1 and retries > 0:
580 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
581 i = child.expect(["The command completed successfully", "The network path was not found"])
587 t.info("Checking if showrepl is happy")
588 child.sendline("repadmin /showrepl")
589 child.expect("${WIN_BASEDN}")
590 child.expect("was successful")
591 child.expect("CN=Configuration,${WIN_BASEDN}")
592 child.expect("was successful")
593 child.expect("CN=Configuration,${WIN_BASEDN}")
594 child.expect("was successful")
596 t.info("Checking if new users propogate to windows")
597 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
598 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
599 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
601 t.info("Checking if new users on windows propogate to samba")
602 child.sendline("net user test3 ${PASSWORD3} /add")
603 child.expect("The command completed successfully")
604 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
605 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
607 t.info("Checking propogation of user deletion")
608 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
609 child.sendline("net user test3 /del")
610 child.expect("The command completed successfully")
612 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
613 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
614 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
615 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
616 t.vm_poweroff("${WIN_VM}")
619 def join_as_rodc(t, vm):
620 '''join a windows domain as a RODC'''
622 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
623 t.port_wait("${WIN_IP}", 389)
624 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
625 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
626 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
627 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
630 def test_join_as_rodc(t, vm):
631 '''test a windows domain RODC join'''
632 t.info("Checking the RODC join is OK")
634 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
635 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
636 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
638 t.info("Forcing kcc runs, and replication")
639 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
640 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
642 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
643 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
644 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
648 while i == 1 and retries > 0:
649 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
650 i = child.expect(["The command completed successfully", "The network path was not found"])
656 t.info("Checking if showrepl is happy")
657 child.sendline("repadmin /showrepl")
658 child.expect("DSA invocationID")
660 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
661 [ "INBOUND NEIGHBORS",
662 "OUTBOUND NEIGHBORS",
664 "Last attempt .* was successful",
665 "CN=Configuration,${WIN_BASEDN}",
666 "Last attempt .* was successful",
667 "CN=Configuration,${WIN_BASEDN}",
668 "Last attempt .* was successful" ],
672 t.info("Checking if new users on windows propogate to samba")
673 child.sendline("net user test3 ${PASSWORD3} /add")
674 child.expect("The command completed successfully")
675 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
676 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
679 t.info("Checking if new users propogate to windows")
680 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
682 t.info("Checking propogation of user deletion")
683 child.sendline("net user test3 /del")
684 child.expect("The command completed successfully")
686 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
687 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
688 t.vm_poweroff("${WIN_VM}")
691 def run_dcpromo_as_first_dc(t, vm, func_level=None):
693 t.info("Configuring a windows VM ${WIN_VM} at the first DC in the domain using dcpromo")
694 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
695 if t.get_is_dc(child):
698 if func_level == '2008r2':
699 t.setvar("FUNCTION_LEVEL_INT", str(4))
700 elif func_level == '2003':
701 t.setvar("FUNCTION_LEVEL_INT", str(1))
703 t.setvar("FUNCTION_LEVEL_INT", str(0))
705 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
707 """This server must therefore not yet be a directory server, so we must promote it"""
708 child.sendline("copy /Y con answers.txt")
711 ; New forest promotion
712 ReplicaOrNewDomain=Domain
714 NewDomainDNSName=${WIN_REALM}
715 ForestLevel=${FUNCTION_LEVEL_INT}
716 DomainNetbiosName=${WIN_DOMAIN}
717 DomainLevel=${FUNCTION_LEVEL_INT}
720 CreateDNSDelegation=No
721 DatabasePath="C:\Windows\NTDS"
722 LogPath="C:\Windows\NTDS"
723 SYSVOLPath="C:\Windows\SYSVOL"
724 ; Set SafeModeAdminPassword to the correct value prior to using the unattend file
725 SafeModeAdminPassword=${WIN_PASS}
726 ; Run-time flags (optional)
727 RebootOnCompletion=No
730 child.expect("copied.")
733 child.sendline("dcpromo /answer:answers.txt")
734 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
736 raise Exception("dcpromo failed")
737 child.sendline("shutdown -r -t 0")
738 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
739 t.port_wait("${WIN_IP}", 139)
742 '''test the Samba4 howto'''
744 check_prerequesites(t)
746 # we don't need fsync safety in these tests
747 t.putenv('TDB_NO_FSYNC', '1')
749 if not t.skip("configure_bind"):
751 if not t.skip("stop_bind"):
753 if not t.skip("stop_vms"):
756 if not t.skip("build"):
759 if not t.skip("provision"):
762 if not t.skip("create-shares"):
765 if not t.skip("starts4"):
767 if not t.skip("smbclient"):
769 if not t.skip("configure_bind2"):
771 if not t.skip("start_bind"):
773 if not t.skip("dns"):
775 if not t.skip("kerberos"):
777 if not t.skip("dyndns"):
780 if t.have_vm('WINDOWS7') and not t.skip("windows7"):
781 run_winjoin(t, "WINDOWS7")
782 test_winjoin(t, "WINDOWS7")
784 if t.have_vm('WINXP') and not t.skip("winxp"):
785 run_winjoin(t, "WINXP")
786 test_winjoin(t, "WINXP")
788 if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
789 t.info("Testing w2k8r2 RODC dcpromo")
790 run_dcpromo_rodc(t, "W2K8R2C")
791 test_dcpromo_rodc(t, "W2K8R2C")
793 if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
794 t.info("Testing w2k8r2 dcpromo")
795 run_dcpromo(t, "W2K8R2B")
796 test_dcpromo(t, "W2K8R2B")
798 if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
799 t.info("Testing w2k8 dcpromo")
800 run_dcpromo(t, "W2K8B")
801 test_dcpromo(t, "W2K8B")
803 if t.have_vm('W2K3B') and not t.skip("dcpromo_w2k3"):
804 t.info("Testing w2k3 dcpromo")
805 t.info("Changing to 2003 functional level")
806 provision_s4(t, func_level='2003')
814 run_dcpromo(t, "W2K3B")
815 test_dcpromo(t, "W2K3B")
817 if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
818 prep_join_as_dc(t, "W2K8R2A")
819 run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
820 join_as_dc(t, "W2K8R2A")
824 test_join_as_dc(t, "W2K8R2A")
826 if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
827 prep_join_as_dc(t, "W2K8R2A")
828 run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
829 join_as_rodc(t, "W2K8R2A")
833 test_join_as_rodc(t, "W2K8R2A")
835 if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
836 prep_join_as_dc(t, "W2K3A")
837 run_dcpromo_as_first_dc(t, "W2K3A", func_level='2003')
838 join_as_dc(t, "W2K3A")
842 test_join_as_dc(t, "W2K3A")
844 t.info("Howto test: All OK")
848 '''cleanup after tests'''
849 t.info("Cleaning up ...")
850 restore_resolv_conf(t)
851 if getattr(t, 'bind_child', False):
855 if __name__ == '__main__':
856 parser = optparse.OptionParser("test-howto.py")
857 parser.add_option("--conf", type='string', default='', help='config file')
858 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
859 parser.add_option("--vms", type='string', default=None, help='list of VMs to use (comma separated)')
860 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
861 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
862 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
863 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
864 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
865 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
867 opts, args = parser.parse_args()
870 print("Please specify a config file with --conf")
873 t = wintest.wintest()
874 t.load_config(opts.conf)
876 t.set_skip(opts.skip)
883 t.setvar('PREFIX', opts.prefix)
886 t.setvar('SOURCETREE', opts.sourcetree)
890 t.chdir('${SOURCETREE}')
891 t.run_cmd('git pull --rebase')
895 t.chdir('${SOURCETREE}/source4')
896 t.run_cmd('rm -rf bin')
901 if not opts.nocleanup:
905 if not opts.nocleanup:
907 t.info("S4 howto test: All OK")