3 '''automated testing of the steps of the Samba4 HOWTO'''
7 import wintest, pexpect
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)
66 def test_smbclient(t):
68 t.info('Testing smbclient')
70 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
71 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
72 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
75 child.expect("blocks available")
76 child.sendline("mkdir testdir")
78 child.sendline("cd testdir")
79 child.expect('testdir')
80 child.sendline("cd ..")
81 child.sendline("rmdir testdir")
85 '''create some test shares'''
86 t.info("Adding test shares")
88 t.write_file("etc/smb.conf", '''
93 path = ${PREFIX}/var/profiles
97 t.run_cmd("mkdir -p test")
98 t.run_cmd("mkdir -p var/profiles")
101 def set_nameserver(t, nameserver):
102 '''set the nameserver in resolv.conf'''
103 t.write_file("/etc/resolv.conf.wintest", '''
104 # Generated by wintest, the Samba v Windows automated testing system
107 # your original resolv.conf appears below:
109 ''' % t.substitute(nameserver))
110 child = t.pexpect_spawn("cat /etc/resolv.conf", crlf=False)
111 i = child.expect(['your original resolv.conf appears below:', pexpect.EOF])
113 child.expect(pexpect.EOF)
114 contents = child.before.replace('\r', '')
115 t.write_file('/etc/resolv.conf.wintest', contents, mode='a')
116 t.write_file('/etc/resolv.conf.wintest-bak', contents)
117 t.run_cmd("mv -f /etc/resolv.conf.wintest /etc/resolv.conf")
118 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
121 def restore_resolv_conf(t):
122 '''restore the /etc/resolv.conf after testing is complete'''
123 if getattr(t, 'resolv_conf_backup', False):
124 t.info("restoring /etc/resolv.conf")
125 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
127 def rndc_cmd(t, cmd, checkfail=True):
128 '''run a rndc command'''
129 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
133 '''restart the test environment version of bind'''
134 t.info("Restarting bind9")
135 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
136 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
138 t.run_cmd("mkdir -p var/named/data")
139 t.run_cmd("chown -R ${BIND_USER} var/named")
141 nameserver = t.get_nameserver()
142 if nameserver == t.getvar('INTERFACE_IP'):
143 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
144 t.setvar('DNSSERVER', nameserver)
146 if t.getvar('INTERFACE_IPV6'):
147 ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
150 t.setvar('BIND_LISTEN_IPV6', ipv6_listen)
152 t.write_file("etc/named.conf", '''
154 listen-on port 53 { ${INTERFACE_IP}; };
156 directory "${PREFIX}/var/named";
157 dump-file "${PREFIX}/var/named/data/cache_dump.db";
158 pid-file "${PREFIX}/var/named/named.pid";
159 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
160 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
161 allow-query { any; };
163 tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
164 tkey-domain "${REALM}";
177 secret "lA/cTrno03mt5Ju17ybEYw==";
181 inet ${INTERFACE_IP} port 953
182 allow { any; } keys { "rndc-key"; };
185 include "${PREFIX}/private/named.conf";
188 # add forwarding for the windows domains
189 domains = t.get_domains()
191 t.write_file('etc/named.conf',
200 ''' % (d, domains[d]),
204 t.write_file("etc/rndc.conf", '''
208 secret "lA/cTrno03mt5Ju17ybEYw==";
212 default-key "rndc-key";
213 default-server ${INTERFACE_IP};
218 set_nameserver(t, t.getvar('INTERFACE_IP'))
220 rndc_cmd(t, "stop", checkfail=False)
221 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
222 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
224 t.port_wait("${INTERFACE_IP}", 53)
229 '''test that DNS is OK'''
230 t.info("Testing DNS")
231 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
232 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
233 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
234 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
235 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
236 ['${HOSTNAME}.${LCREALM} has address'])
238 def test_kerberos(t):
239 '''test that kerberos is OK'''
240 t.info("Testing kerberos")
241 t.run_cmd("kdestroy")
242 t.kinit("administrator@${REALM}", "${PASSWORD1}")
243 t.cmd_contains("klist -e", ["Ticket cache", "Default principal", "Valid starting"])
247 '''test that dynamic DNS is working'''
249 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
253 def run_winjoin(t, vm):
254 '''join a windows box to our domain'''
257 t.info("Joining a windows box to the domain")
258 t.vm_poweroff("${WIN_VM}", checkfail=False)
259 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
260 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
261 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
262 child.expect("The command completed successfully")
264 child.sendline("shutdown /r -t 0")
265 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
266 t.port_wait("${WIN_IP}", 139)
267 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
268 child.sendline("ipconfig /registerdns")
269 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")
272 def test_winjoin(t, vm):
273 t.info("Checking the windows join is OK")
275 t.port_wait("${WIN_IP}", 139)
276 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
277 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
278 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
279 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
280 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
281 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
282 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
283 child.expect("The command completed successfully")
284 t.vm_poweroff("${WIN_VM}")
287 def run_dcpromo(t, vm):
288 '''run a dcpromo on windows'''
291 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
292 t.vm_poweroff("${WIN_VM}", checkfail=False)
293 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
294 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
295 child.sendline("copy /Y con answers.txt")
299 RebootOnCompletion=Yes
300 ReplicaOrNewDomain=Replica
301 ReplicaDomainDNSName=${LCREALM}
302 SiteName=Default-First-Site-Name
305 CreateDNSDelegation=No
306 UserDomain=${LCREALM}
307 UserName=${LCREALM}\\administrator
308 Password=${PASSWORD1}
309 DatabasePath="C:\Windows\NTDS"
310 LogPath="C:\Windows\NTDS"
311 SYSVOLPath="C:\Windows\SYSVOL"
312 SafeModeAdminPassword=${PASSWORD1}
315 child.expect("copied.")
318 child.sendline("dcpromo /answer:answers.txt")
319 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
321 raise Exception("dcpromo failed")
322 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
323 t.port_wait("${WIN_IP}", 139)
326 def test_dcpromo(t, vm):
327 '''test that dcpromo worked'''
328 t.info("Checking the dcpromo join is OK")
330 t.port_wait("${WIN_IP}", 139)
331 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
332 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
333 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
335 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
336 t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
338 t.kinit("administrator@${REALM}", "${PASSWORD1}")
339 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
340 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
341 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
343 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
344 [ "INBOUND NEIGHBORS",
346 "Last attempt .* was successful",
347 "CN=Configuration,${BASEDN}",
348 "Last attempt .* was successful",
349 "CN=Configuration,${BASEDN}", # cope with either order
350 "Last attempt .* was successful",
351 "OUTBOUND NEIGHBORS",
354 "CN=Configuration,${BASEDN}",
356 "CN=Configuration,${BASEDN}",
361 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
362 [ "INBOUND NEIGHBORS",
364 "Last attempt .* was successful",
365 "CN=Configuration,${BASEDN}",
366 "Last attempt .* was successful",
367 "CN=Configuration,${BASEDN}",
368 "Last attempt .* was successful",
369 "OUTBOUND NEIGHBORS",
372 "CN=Configuration,${BASEDN}",
374 "CN=Configuration,${BASEDN}",
379 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
380 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
381 child.expect("The command completed successfully")
383 t.run_net_time(child)
385 t.info("Checking if showrepl is happy")
386 child.sendline("repadmin /showrepl")
387 child.expect("${BASEDN}")
388 child.expect("was successful")
389 child.expect("CN=Configuration,${BASEDN}")
390 child.expect("was successful")
391 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
392 child.expect("was successful")
394 t.info("Checking if new users propogate to windows")
395 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
396 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
397 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
399 t.info("Checking if new users on windows propogate to samba")
400 child.sendline("net user test3 ${PASSWORD3} /add")
402 i = child.expect(["The command completed successfully",
403 "The directory service was unable to allocate a relative identifier"])
408 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
409 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
411 t.info("Checking propogation of user deletion")
412 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
413 child.sendline("net user test3 /del")
414 child.expect("The command completed successfully")
416 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
417 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
418 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
419 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
420 t.vm_poweroff("${WIN_VM}")
423 def run_dcpromo_rodc(t, vm):
424 '''run a RODC dcpromo to join a windows DC to the samba domain'''
426 t.info("Joining a w2k8 box to the domain as a RODC")
427 t.vm_poweroff("${WIN_VM}", checkfail=False)
428 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
429 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
430 child.sendline("copy /Y con answers.txt")
433 ReplicaOrNewDomain=ReadOnlyReplica
434 ReplicaDomainDNSName=${LCREALM}
435 PasswordReplicationDenied="BUILTIN\Administrators"
436 PasswordReplicationDenied="BUILTIN\Server Operators"
437 PasswordReplicationDenied="BUILTIN\Backup Operators"
438 PasswordReplicationDenied="BUILTIN\Account Operators"
439 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
440 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
441 DelegatedAdmin="${DOMAIN}\\Administrator"
442 SiteName=Default-First-Site-Name
445 CreateDNSDelegation=No
446 UserDomain=${LCREALM}
447 UserName=${LCREALM}\\administrator
448 Password=${PASSWORD1}
449 DatabasePath="C:\Windows\NTDS"
450 LogPath="C:\Windows\NTDS"
451 SYSVOLPath="C:\Windows\SYSVOL"
452 SafeModeAdminPassword=${PASSWORD1}
453 RebootOnCompletion=No
456 child.expect("copied.")
457 child.sendline("dcpromo /answer:answers.txt")
458 i = child.expect(["You must restart this computer", "failed"], timeout=120)
460 raise Exception("dcpromo failed")
461 child.sendline("shutdown -r -t 0")
462 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
463 t.port_wait("${WIN_IP}", 139)
467 def test_dcpromo_rodc(t, vm):
468 '''test the RODC dcpromo worked'''
469 t.info("Checking the w2k8 RODC join is OK")
471 t.port_wait("${WIN_IP}", 139)
472 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
473 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
474 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
475 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
476 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
477 child.expect("The command completed successfully")
479 t.info("Checking if showrepl is happy")
480 child.sendline("repadmin /showrepl")
481 child.expect("${BASEDN}")
482 child.expect("was successful")
483 child.expect("CN=Configuration,${BASEDN}")
484 child.expect("was successful")
485 child.expect("CN=Configuration,${BASEDN}")
486 child.expect("was successful")
488 t.info("Checking if new users are available on windows")
489 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
490 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
491 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
492 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN} -k yes", ["was successful"])
493 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
494 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
495 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
496 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
497 t.vm_poweroff("${WIN_VM}")
500 def join_as_dc(t, vm):
501 '''join a windows domain as a DC'''
503 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
505 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
506 t.vm_poweroff("${WIN_VM}", checkfail=False)
507 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
509 t.run_cmd("rm -rf etc/smb.conf private")
510 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
511 t.get_ipconfig(child)
512 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
513 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
514 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
517 def test_join_as_dc(t, vm):
518 '''test the join of a windows domain as a DC'''
519 t.info("Checking the DC join is OK")
521 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
522 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
523 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
525 t.info("Forcing kcc runs, and replication")
526 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
527 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
529 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
530 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
531 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
532 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
534 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
535 child.expect("The command completed successfully")
537 t.info("Checking if showrepl is happy")
538 child.sendline("repadmin /showrepl")
539 child.expect("${WIN_BASEDN}")
540 child.expect("was successful")
541 child.expect("CN=Configuration,${WIN_BASEDN}")
542 child.expect("was successful")
543 child.expect("CN=Configuration,${WIN_BASEDN}")
544 child.expect("was successful")
546 t.info("Checking if new users propogate to windows")
547 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
548 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
549 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
551 t.info("Checking if new users on windows propogate to samba")
552 child.sendline("net user test3 ${PASSWORD3} /add")
553 child.expect("The command completed successfully")
554 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
555 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
557 t.info("Checking propogation of user deletion")
558 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
559 child.sendline("net user test3 /del")
560 child.expect("The command completed successfully")
562 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
563 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
564 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
565 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
566 t.vm_poweroff("${WIN_VM}")
569 def join_as_rodc(t, vm):
570 '''join a windows domain as a RODC'''
572 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
574 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
575 t.vm_poweroff("${WIN_VM}", checkfail=False)
576 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
578 t.run_cmd("rm -rf etc/smb.conf private")
579 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
580 t.get_ipconfig(child)
581 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
582 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
583 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
586 def test_join_as_rodc(t, vm):
587 '''test a windows domain RODC join'''
588 t.info("Checking the RODC join is OK")
590 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
591 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
592 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
594 t.info("Forcing kcc runs, and replication")
595 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
596 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
598 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
599 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
600 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
602 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
603 child.expect("The command completed successfully")
605 t.info("Checking if showrepl is happy")
606 child.sendline("repadmin /showrepl")
607 child.expect("DSA invocationID")
609 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
610 [ "INBOUND NEIGHBORS",
611 "OUTBOUND NEIGHBORS",
613 "Last attempt .* was successful",
614 "CN=Configuration,${WIN_BASEDN}",
615 "Last attempt .* was successful",
616 "CN=Configuration,${WIN_BASEDN}",
617 "Last attempt .* was successful" ],
621 t.info("Checking if new users on windows propogate to samba")
622 child.sendline("net user test3 ${PASSWORD3} /add")
623 child.expect("The command completed successfully")
624 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
625 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
628 t.info("Checking if new users propogate to windows")
629 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
631 t.info("Checking propogation of user deletion")
632 child.sendline("net user test3 /del")
633 child.expect("The command completed successfully")
635 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
636 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
637 t.vm_poweroff("${WIN_VM}")
641 '''test the Samba4 howto'''
643 check_prerequesites(t)
645 # we don't need fsync safety in these tests
646 t.putenv('TDB_NO_FSYNC', '1')
648 if not t.skip("build"):
651 if not t.skip("provision"):
654 if not t.skip("create-shares"):
657 if not t.skip("starts4"):
659 if not t.skip("smbclient"):
661 if not t.skip("startbind"):
663 if not t.skip("dns"):
665 if not t.skip("kerberos"):
667 if not t.skip("dyndns"):
670 if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
671 run_winjoin(t, "WINDOWS7")
672 test_winjoin(t, "WINDOWS7")
674 if t.have_var('WINXP_VM') and not t.skip("winxp"):
675 run_winjoin(t, "WINXP")
676 test_winjoin(t, "WINXP")
678 if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
679 t.info("Testing w2k8r2 RODC dcpromo")
680 run_dcpromo_rodc(t, "W2K8R2C")
681 test_dcpromo_rodc(t, "W2K8R2C")
683 if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
684 t.info("Testing w2k8r2 dcpromo")
685 run_dcpromo(t, "W2K8R2B")
686 test_dcpromo(t, "W2K8R2B")
688 if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
689 t.info("Testing w2k8 dcpromo")
690 run_dcpromo(t, "W2K8B")
691 test_dcpromo(t, "W2K8B")
693 if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
694 t.info("Testing w2k3 dcpromo")
695 t.info("Changing to 2003 functional level")
696 provision_s4(t, func_level='2003')
704 run_dcpromo(t, "W2K3B")
705 test_dcpromo(t, "W2K3B")
707 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
708 join_as_dc(t, "W2K8R2A")
712 test_join_as_dc(t, "W2K8R2A")
714 if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
715 join_as_rodc(t, "W2K8R2A")
719 test_join_as_rodc(t, "W2K8R2A")
721 if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
722 join_as_dc(t, "W2K3A")
726 test_join_as_dc(t, "W2K3A")
728 t.info("Howto test: All OK")
732 '''cleanup after tests'''
733 t.info("Cleaning up ...")
734 restore_resolv_conf(t)
735 if getattr(t, 'bind_child', False):
739 if __name__ == '__main__':
740 parser = optparse.OptionParser("test-howto.py")
741 parser.add_option("--conf", type='string', default='', help='config file')
742 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
743 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
744 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
745 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
746 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
747 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
748 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
750 opts, args = parser.parse_args()
753 print("Please specify a config file with --conf")
756 t = wintest.wintest()
757 t.load_config(opts.conf)
758 t.set_skip(opts.skip)
764 t.setvar('PREFIX', opts.prefix)
767 t.setvar('SOURCETREE', opts.sourcetree)
771 t.chdir('${SOURCETREE}')
772 t.run_cmd('git pull --rebase')
776 t.chdir('${SOURCETREE}/source4')
777 t.run_cmd('rm -rf bin')
782 if not opts.nocleanup:
786 if not opts.nocleanup:
788 t.info("S4 howto test: All OK")