3 '''automated testing of the steps of the Samba4 HOWTO'''
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')
21 t.chdir('${SOURCETREE}/source4')
22 t.putenv('CC', 'ccache gcc')
23 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
25 t.run_cmd('rm -rf ${PREFIX}')
26 t.run_cmd('make -j install')
29 def provision_s4(t, func_level="2008"):
30 '''provision s4 as a DC'''
31 t.info('Provisioning s4')
33 t.del_files(["var", "private"])
34 t.run_cmd("rm -f etc/smb.conf")
35 options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
36 options += ' --option=interfaces=${INTERFACE}'
37 options += ' --host-ip=${INTERFACE_IP} --host-ip6="::"'
38 t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
39 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
40 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
41 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
46 t.info('Starting Samba4')
48 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
49 t.run_cmd(['sbin/samba',
50 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
51 t.port_wait("localhost", 139)
54 def test_smbclient(t):
56 t.info('Testing smbclient')
58 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
59 t.retry_cmd('bin/smbclient -L localhost -U%', ["netlogon", "sysvol", "IPC Service"])
60 child = t.pexpect_spawn('bin/smbclient //localhost/netlogon -Uadministrator%${PASSWORD1}')
63 child.expect("blocks available")
64 child.sendline("mkdir testdir")
66 child.sendline("cd testdir")
67 child.expect('testdir')
68 child.sendline("cd ..")
69 child.sendline("rmdir testdir")
73 '''create some test shares'''
74 t.info("Adding test shares")
76 t.write_file("etc/smb.conf", '''
81 path = ${PREFIX}/var/profiles
85 t.run_cmd("mkdir -p test")
86 t.run_cmd("mkdir -p var/profiles")
89 def set_nameserver(t, nameserver):
90 '''set the nameserver in resolv.conf'''
91 if not getattr(t, 'resolv_conf_backup', False):
92 t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
93 t.write_file("/etc/resolv.conf", '''
94 # Generated by wintest, the Samba v Windows automated testing system
97 # your original resolv.conf appears below:
99 ''' % t.substitute(nameserver))
100 t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
101 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
104 def restore_resolv_conf(t):
105 '''restore the /etc/resolv.conf after testing is complete'''
106 if getattr(t, 'resolv_conf_backup', False):
107 t.info("restoring /etc/resolv.conf")
108 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
110 def rndc_cmd(t, cmd, checkfail=True):
111 '''run a rndc command'''
112 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
116 '''restart the test environment version of bind'''
117 t.info("Restarting bind9")
118 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
119 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
121 t.run_cmd("mkdir -p var/named/data")
122 t.run_cmd("chown -R ${BIND_USER} var/named")
124 nameserver = t.get_nameserver()
125 if nameserver == t.getvar('INTERFACE_IP'):
126 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration")
127 t.setvar('DNSSERVER', nameserver)
129 t.write_file("etc/named.conf", '''
131 listen-on port 53 { ${INTERFACE_IP}; };
132 directory "${PREFIX}/var/named";
133 dump-file "${PREFIX}/var/named/data/cache_dump.db";
134 pid-file "${PREFIX}/var/named/named.pid";
135 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
136 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
137 allow-query { ${INTERFACE_NET}; 127.0.0.0/8; };
139 tkey-gssapi-credential "DNS/${LCREALM}";
140 tkey-domain "${REALM}";
151 secret "lA/cTrno03mt5Ju17ybEYw==";
155 inet ${INTERFACE_IP} port 953
156 allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
159 include "${PREFIX}/private/named.conf";
162 # add forwarding for the windows domains
163 domains = t.get_domains()
165 t.write_file('etc/named.conf',
174 ''' % (d, domains[d]),
178 t.write_file("etc/rndc.conf", '''
182 secret "lA/cTrno03mt5Ju17ybEYw==";
186 default-key "rndc-key";
187 default-server ${INTERFACE_IP};
192 set_nameserver(t, t.getvar('INTERFACE_IP'))
194 rndc_cmd(t, "stop", checkfail=False)
195 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
196 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
198 t.port_wait("${INTERFACE_IP}", 53)
203 '''test that DNS is OK'''
204 t.info("Testing DNS")
205 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
206 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
207 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
208 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
209 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
210 ['${HOSTNAME}.${LCREALM} has address'])
212 def test_kerberos(t):
213 '''test that kerberos is OK'''
214 t.info("Testing kerberos")
215 t.run_cmd("kdestroy")
216 t.kinit("administrator@${REALM}", "${PASSWORD1}")
217 t.cmd_contains("klist -e", ["Ticket cache", "Default principal", "Valid starting"])
221 '''test that dynamic DNS is working'''
223 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
227 def run_winjoin(t, vm):
228 '''join a windows box to our domain'''
231 t.info("Joining a windows box to the domain")
232 t.vm_poweroff("${WIN_VM}", checkfail=False)
233 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
234 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
235 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
236 child.expect("The command completed successfully")
238 child.sendline("shutdown /r -t 0")
239 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
240 t.port_wait("${WIN_IP}", 139)
241 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
242 child.sendline("ipconfig /registerdns")
243 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")
246 def test_winjoin(t, vm):
247 t.info("Checking the windows join is OK")
249 t.port_wait("${WIN_IP}", 139)
250 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
251 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
252 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
253 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
254 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
255 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
256 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
257 child.expect("The command completed successfully")
258 t.vm_poweroff("${WIN_VM}")
261 def run_dcpromo(t, vm):
262 '''run a dcpromo on windows'''
265 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
266 t.vm_poweroff("${WIN_VM}", checkfail=False)
267 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
268 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
269 child.sendline("copy /Y con answers.txt")
273 RebootOnCompletion=Yes
274 ReplicaOrNewDomain=Replica
275 ReplicaDomainDNSName=${LCREALM}
276 SiteName=Default-First-Site-Name
279 CreateDNSDelegation=No
280 UserDomain=${LCREALM}
281 UserName=${LCREALM}\\administrator
282 Password=${PASSWORD1}
283 DatabasePath="C:\Windows\NTDS"
284 LogPath="C:\Windows\NTDS"
285 SYSVOLPath="C:\Windows\SYSVOL"
286 SafeModeAdminPassword=${PASSWORD1}
289 child.expect("copied.")
292 child.sendline("dcpromo /answer:answers.txt")
293 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
295 raise Exception("dcpromo failed")
296 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
297 t.port_wait("${WIN_IP}", 139)
300 def test_dcpromo(t, vm):
301 '''test that dcpromo worked'''
302 t.info("Checking the dcpromo join is OK")
304 t.port_wait("${WIN_IP}", 139)
305 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
306 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
307 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
309 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
310 t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
312 t.kinit("administrator@${REALM}", "${PASSWORD1}")
313 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
314 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
315 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
317 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME} -k yes",
318 [ "INBOUND NEIGHBORS",
320 "Last attempt .* was successful",
321 "CN=Configuration,${BASEDN}",
322 "Last attempt .* was successful",
323 "CN=Configuration,${BASEDN}", # cope with either order
324 "Last attempt .* was successful",
325 "OUTBOUND NEIGHBORS",
328 "CN=Configuration,${BASEDN}",
330 "CN=Configuration,${BASEDN}",
335 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
336 [ "INBOUND NEIGHBORS",
338 "Last attempt .* was successful",
339 "CN=Configuration,${BASEDN}",
340 "Last attempt .* was successful",
341 "CN=Configuration,${BASEDN}",
342 "Last attempt .* was successful",
343 "OUTBOUND NEIGHBORS",
346 "CN=Configuration,${BASEDN}",
348 "CN=Configuration,${BASEDN}",
353 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
354 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
355 child.expect("The command completed successfully")
357 t.run_net_time(child)
359 t.info("Checking if showrepl is happy")
360 child.sendline("repadmin /showrepl")
361 child.expect("${BASEDN}")
362 child.expect("was successful")
363 child.expect("CN=Configuration,${BASEDN}")
364 child.expect("was successful")
365 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
366 child.expect("was successful")
368 t.info("Checking if new users propogate to windows")
369 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
370 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
371 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
373 t.info("Checking if new users on windows propogate to samba")
374 child.sendline("net user test3 ${PASSWORD3} /add")
376 i = child.expect(["The command completed successfully",
377 "The directory service was unable to allocate a relative identifier"])
382 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
383 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
385 t.info("Checking propogation of user deletion")
386 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
387 child.sendline("net user test3 /del")
388 child.expect("The command completed successfully")
390 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
391 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
392 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
393 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
394 t.vm_poweroff("${WIN_VM}")
397 def run_dcpromo_rodc(t, vm):
398 '''run a RODC dcpromo to join a windows DC to the samba domain'''
400 t.info("Joining a w2k8 box to the domain as a RODC")
401 t.vm_poweroff("${WIN_VM}", checkfail=False)
402 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
403 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
404 child.sendline("copy /Y con answers.txt")
407 ReplicaOrNewDomain=ReadOnlyReplica
408 ReplicaDomainDNSName=${LCREALM}
409 PasswordReplicationDenied="BUILTIN\Administrators"
410 PasswordReplicationDenied="BUILTIN\Server Operators"
411 PasswordReplicationDenied="BUILTIN\Backup Operators"
412 PasswordReplicationDenied="BUILTIN\Account Operators"
413 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
414 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
415 DelegatedAdmin="${DOMAIN}\\Administrator"
416 SiteName=Default-First-Site-Name
419 CreateDNSDelegation=No
420 UserDomain=${LCREALM}
421 UserName=${LCREALM}\\administrator
422 Password=${PASSWORD1}
423 DatabasePath="C:\Windows\NTDS"
424 LogPath="C:\Windows\NTDS"
425 SYSVOLPath="C:\Windows\SYSVOL"
426 SafeModeAdminPassword=${PASSWORD1}
427 RebootOnCompletion=No
430 child.expect("copied.")
431 child.sendline("dcpromo /answer:answers.txt")
432 i = child.expect(["You must restart this computer", "failed"], timeout=120)
434 raise Exception("dcpromo failed")
435 child.sendline("shutdown -r -t 0")
436 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
437 t.port_wait("${WIN_IP}", 139)
441 def test_dcpromo_rodc(t, vm):
442 '''test the RODC dcpromo worked'''
443 t.info("Checking the w2k8 RODC join is OK")
445 t.port_wait("${WIN_IP}", 139)
446 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
447 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
448 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
449 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
450 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
451 child.expect("The command completed successfully")
453 t.info("Checking if showrepl is happy")
454 child.sendline("repadmin /showrepl")
455 child.expect("${BASEDN}")
456 child.expect("was successful")
457 child.expect("CN=Configuration,${BASEDN}")
458 child.expect("was successful")
459 child.expect("CN=Configuration,${BASEDN}")
460 child.expect("was successful")
462 t.info("Checking if new users are available on windows")
463 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
464 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
465 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
466 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME} ${BASEDN} -k yes", ["was successful"])
467 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
468 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
469 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
470 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
471 t.vm_poweroff("${WIN_VM}")
474 def join_as_dc(t, vm):
475 '''join a windows domain as a DC'''
477 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
479 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
480 t.vm_poweroff("${WIN_VM}", checkfail=False)
481 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
483 t.run_cmd("rm -rf etc/smb.conf private")
484 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
485 t.get_ipconfig(child)
486 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
487 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
488 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
491 def test_join_as_dc(t, vm):
492 '''test the join of a windows domain as a DC'''
493 t.info("Checking the DC join is OK")
495 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
496 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
497 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
499 t.info("Forcing kcc runs, and replication")
500 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
501 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
503 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
504 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
505 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
506 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
508 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
509 child.expect("The command completed successfully")
511 t.info("Checking if showrepl is happy")
512 child.sendline("repadmin /showrepl")
513 child.expect("${WIN_BASEDN}")
514 child.expect("was successful")
515 child.expect("CN=Configuration,${WIN_BASEDN}")
516 child.expect("was successful")
517 child.expect("CN=Configuration,${WIN_BASEDN}")
518 child.expect("was successful")
520 t.info("Checking if new users propogate to windows")
521 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
522 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
523 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
525 t.info("Checking if new users on windows propogate to samba")
526 child.sendline("net user test3 ${PASSWORD3} /add")
527 child.expect("The command completed successfully")
528 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
529 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
531 t.info("Checking propogation of user deletion")
532 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
533 child.sendline("net user test3 /del")
534 child.expect("The command completed successfully")
536 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
537 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
538 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
539 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
540 t.vm_poweroff("${WIN_VM}")
543 def join_as_rodc(t, vm):
544 '''join a windows domain as a RODC'''
546 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
548 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
549 t.vm_poweroff("${WIN_VM}", checkfail=False)
550 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
552 t.run_cmd("rm -rf etc/smb.conf private")
553 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
554 t.get_ipconfig(child)
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} RODC -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_rodc(t, vm):
561 '''test a windows domain RODC join'''
562 t.info("Checking the RODC 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 ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
570 t.run_cmd('bin/samba-tool drs kcc ${WIN_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_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
576 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
577 child.expect("The command completed successfully")
579 t.info("Checking if showrepl is happy")
580 child.sendline("repadmin /showrepl")
581 child.expect("DSA invocationID")
583 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
584 [ "INBOUND NEIGHBORS",
585 "OUTBOUND NEIGHBORS",
587 "Last attempt .* was successful",
588 "CN=Configuration,${WIN_BASEDN}",
589 "Last attempt .* was successful",
590 "CN=Configuration,${WIN_BASEDN}",
591 "Last attempt .* was successful" ],
595 t.info("Checking if new users on windows propogate to samba")
596 child.sendline("net user test3 ${PASSWORD3} /add")
597 child.expect("The command completed successfully")
598 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
599 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
602 t.info("Checking if new users propogate to windows")
603 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
605 t.info("Checking propogation of user deletion")
606 child.sendline("net user test3 /del")
607 child.expect("The command completed successfully")
609 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
610 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
611 t.vm_poweroff("${WIN_VM}")
615 '''test the Samba4 howto'''
617 check_prerequesites(t)
619 # we don't need fsync safety in these tests
620 t.putenv('TDB_NO_FSYNC', '1')
622 if not t.skip("build"):
625 if not t.skip("provision"):
628 if not t.skip("create-shares"):
631 if not t.skip("starts4"):
633 if not t.skip("smbclient"):
635 if not t.skip("startbind"):
637 if not t.skip("dns"):
639 if not t.skip("kerberos"):
641 if not t.skip("dyndns"):
644 if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
645 run_winjoin(t, "WINDOWS7")
646 test_winjoin(t, "WINDOWS7")
648 if t.have_var('WINXP_VM') and not t.skip("winxp"):
649 run_winjoin(t, "WINXP")
650 test_winjoin(t, "WINXP")
652 if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
653 t.info("Testing w2k8r2 RODC dcpromo")
654 run_dcpromo_rodc(t, "W2K8R2C")
655 test_dcpromo_rodc(t, "W2K8R2C")
657 if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
658 t.info("Testing w2k8r2 dcpromo")
659 run_dcpromo(t, "W2K8R2B")
660 test_dcpromo(t, "W2K8R2B")
662 if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
663 t.info("Testing w2k8 dcpromo")
664 run_dcpromo(t, "W2K8B")
665 test_dcpromo(t, "W2K8B")
667 if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
668 t.info("Testing w2k3 dcpromo")
669 t.info("Changing to 2003 functional level")
670 provision_s4(t, func_level='2003')
678 run_dcpromo(t, "W2K3B")
679 test_dcpromo(t, "W2K3B")
681 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
682 join_as_dc(t, "W2K8R2A")
686 test_join_as_dc(t, "W2K8R2A")
688 if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
689 join_as_rodc(t, "W2K8R2A")
693 test_join_as_rodc(t, "W2K8R2A")
695 if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
696 join_as_dc(t, "W2K3A")
700 test_join_as_dc(t, "W2K3A")
702 t.info("Howto test: All OK")
706 '''cleanup after tests'''
707 t.info("Cleaning up ...")
708 restore_resolv_conf(t)
709 if getattr(t, 'bind_child', False):
713 if __name__ == '__main__':
714 parser = optparse.OptionParser("test-howto.py")
715 parser.add_option("--conf", type='string', default='', help='config file')
716 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
717 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
718 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
719 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
720 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
721 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
722 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
724 opts, args = parser.parse_args()
727 print("Please specify a config file with --conf")
730 t = wintest.wintest()
731 t.load_config(opts.conf)
732 t.set_skip(opts.skip)
738 t.setvar('PREFIX', opts.prefix)
741 t.setvar('SOURCETREE', opts.sourcetree)
745 t.chdir('${SOURCETREE}')
746 t.run_cmd('git pull --rebase')
750 t.chdir('${SOURCETREE}/source4')
751 t.run_cmd('rm -rf bin')
756 if not opts.nocleanup:
760 if not opts.nocleanup:
762 t.info("S4 howto test: All OK")