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.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
109 def rndc_cmd(t, cmd, checkfail=True):
110 '''run a rndc command'''
111 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
115 '''restart the test environment version of bind'''
116 t.info("Restarting bind9")
117 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
118 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
120 t.run_cmd("mkdir -p var/named/data")
121 t.run_cmd("chown -R ${BIND_USER} var/named")
123 nameserver = t.get_nameserver()
124 if nameserver == t.getvar('INTERFACE_IP'):
125 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration")
126 t.setvar('DNSSERVER', nameserver)
128 t.write_file("etc/named.conf", '''
130 listen-on port 53 { ${INTERFACE_IP}; };
131 directory "${PREFIX}/var/named";
132 dump-file "${PREFIX}/var/named/data/cache_dump.db";
133 pid-file "${PREFIX}/var/named/named.pid";
134 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
135 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
136 allow-query { ${INTERFACE_NET}; 127.0.0.0/8; };
138 tkey-gssapi-credential "DNS/${LCREALM}";
139 tkey-domain "${REALM}";
150 secret "lA/cTrno03mt5Ju17ybEYw==";
154 inet ${INTERFACE_IP} port 953
155 allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
158 include "${PREFIX}/private/named.conf";
161 # add forwarding for the windows domains
162 domains = t.get_domains()
164 t.write_file('etc/named.conf',
173 ''' % (d, domains[d]),
177 t.write_file("etc/rndc.conf", '''
181 secret "lA/cTrno03mt5Ju17ybEYw==";
185 default-key "rndc-key";
186 default-server ${INTERFACE_IP};
191 set_nameserver(t, t.getvar('INTERFACE_IP'))
193 rndc_cmd(t, "stop", checkfail=False)
194 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
195 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
197 t.port_wait("${INTERFACE_IP}", 53)
202 '''test that DNS is OK'''
203 t.info("Testing DNS")
204 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
205 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
206 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
207 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
208 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
209 ['${HOSTNAME}.${LCREALM} has address'])
211 def test_kerberos(t):
212 '''test that kerberos is OK'''
213 t.info("Testing kerberos")
214 t.run_cmd("kdestroy")
215 t.kinit("administrator@${REALM}", "${PASSWORD1}")
216 t.cmd_contains("klist -e", ["Ticket cache", "Default principal", "Valid starting"])
220 '''test that dynamic DNS is working'''
222 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
226 def run_winjoin(t, vm):
227 '''join a windows box to our domain'''
230 t.info("Joining a windows box to the domain")
231 t.vm_poweroff("${WIN_VM}", checkfail=False)
232 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
233 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
234 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
235 child.expect("The command completed successfully")
237 child.sendline("shutdown /r -t 0")
238 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
239 t.port_wait("${WIN_IP}", 139)
240 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
241 child.sendline("ipconfig /registerdns")
242 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")
245 def test_winjoin(t, vm):
246 t.info("Checking the windows join is OK")
248 t.port_wait("${WIN_IP}", 139)
249 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
250 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
251 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
252 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
253 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
254 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
255 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
256 child.expect("The command completed successfully")
257 t.vm_poweroff("${WIN_VM}")
260 def run_dcpromo(t, vm):
261 '''run a dcpromo on windows'''
264 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
265 t.vm_poweroff("${WIN_VM}", checkfail=False)
266 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
267 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
268 child.sendline("copy /Y con answers.txt")
272 RebootOnCompletion=Yes
273 ReplicaOrNewDomain=Replica
274 ReplicaDomainDNSName=${LCREALM}
275 SiteName=Default-First-Site-Name
278 CreateDNSDelegation=No
279 UserDomain=${LCREALM}
280 UserName=${LCREALM}\\administrator
281 Password=${PASSWORD1}
282 DatabasePath="C:\Windows\NTDS"
283 LogPath="C:\Windows\NTDS"
284 SYSVOLPath="C:\Windows\SYSVOL"
285 SafeModeAdminPassword=${PASSWORD1}
288 child.expect("copied.")
291 child.sendline("dcpromo /answer:answers.txt")
292 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
294 raise Exception("dcpromo failed")
295 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
296 t.port_wait("${WIN_IP}", 139)
299 def test_dcpromo(t, vm):
300 '''test that dcpromo worked'''
301 t.info("Checking the dcpromo join is OK")
303 t.port_wait("${WIN_IP}", 139)
304 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
305 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
306 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
308 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
309 t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
311 t.kinit("administrator@${REALM}", "${PASSWORD1}")
312 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
313 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
314 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
316 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME} -k yes",
317 [ "INBOUND NEIGHBORS",
319 "Last attempt .* was successful",
320 "CN=Configuration,${BASEDN}",
321 "Last attempt .* was successful",
322 "CN=Configuration,${BASEDN}", # cope with either order
323 "Last attempt .* was successful",
324 "OUTBOUND NEIGHBORS",
327 "CN=Configuration,${BASEDN}",
329 "CN=Configuration,${BASEDN}",
334 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
335 [ "INBOUND NEIGHBORS",
337 "Last attempt .* was successful",
338 "CN=Configuration,${BASEDN}",
339 "Last attempt .* was successful",
340 "CN=Configuration,${BASEDN}",
341 "Last attempt .* was successful",
342 "OUTBOUND NEIGHBORS",
345 "CN=Configuration,${BASEDN}",
347 "CN=Configuration,${BASEDN}",
352 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
353 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
354 child.expect("The command completed successfully")
356 t.run_net_time(child)
358 t.info("Checking if showrepl is happy")
359 child.sendline("repadmin /showrepl")
360 child.expect("${BASEDN}")
361 child.expect("was successful")
362 child.expect("CN=Configuration,${BASEDN}")
363 child.expect("was successful")
364 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
365 child.expect("was successful")
367 t.info("Checking if new users propogate to windows")
368 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
369 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
370 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
372 t.info("Checking if new users on windows propogate to samba")
373 child.sendline("net user test3 ${PASSWORD3} /add")
375 i = child.expect(["The command completed successfully",
376 "The directory service was unable to allocate a relative identifier"])
381 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
382 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
384 t.info("Checking propogation of user deletion")
385 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
386 child.sendline("net user test3 /del")
387 child.expect("The command completed successfully")
389 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
390 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
391 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
392 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
393 t.vm_poweroff("${WIN_VM}")
396 def run_dcpromo_rodc(t, vm):
397 '''run a RODC dcpromo to join a windows DC to the samba domain'''
399 t.info("Joining a w2k8 box to the domain as a RODC")
400 t.vm_poweroff("${WIN_VM}", checkfail=False)
401 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
402 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
403 child.sendline("copy /Y con answers.txt")
406 ReplicaOrNewDomain=ReadOnlyReplica
407 ReplicaDomainDNSName=${LCREALM}
408 PasswordReplicationDenied="BUILTIN\Administrators"
409 PasswordReplicationDenied="BUILTIN\Server Operators"
410 PasswordReplicationDenied="BUILTIN\Backup Operators"
411 PasswordReplicationDenied="BUILTIN\Account Operators"
412 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
413 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
414 DelegatedAdmin="${DOMAIN}\\Administrator"
415 SiteName=Default-First-Site-Name
418 CreateDNSDelegation=No
419 UserDomain=${LCREALM}
420 UserName=${LCREALM}\\administrator
421 Password=${PASSWORD1}
422 DatabasePath="C:\Windows\NTDS"
423 LogPath="C:\Windows\NTDS"
424 SYSVOLPath="C:\Windows\SYSVOL"
425 SafeModeAdminPassword=${PASSWORD1}
426 RebootOnCompletion=No
429 child.expect("copied.")
430 child.sendline("dcpromo /answer:answers.txt")
431 i = child.expect(["You must restart this computer", "failed"], timeout=120)
433 raise Exception("dcpromo failed")
434 child.sendline("shutdown -r -t 0")
435 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
436 t.port_wait("${WIN_IP}", 139)
440 def test_dcpromo_rodc(t, vm):
441 '''test the RODC dcpromo worked'''
442 t.info("Checking the w2k8 RODC join is OK")
444 t.port_wait("${WIN_IP}", 139)
445 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
446 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
447 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
448 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
449 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
450 child.expect("The command completed successfully")
452 t.info("Checking if showrepl is happy")
453 child.sendline("repadmin /showrepl")
454 child.expect("${BASEDN}")
455 child.expect("was successful")
456 child.expect("CN=Configuration,${BASEDN}")
457 child.expect("was successful")
458 child.expect("CN=Configuration,${BASEDN}")
459 child.expect("was successful")
461 t.info("Checking if new users are available on windows")
462 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
463 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
464 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
465 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME} ${BASEDN} -k yes", ["was successful"])
466 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
467 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
468 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
469 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
470 t.vm_poweroff("${WIN_VM}")
473 def join_as_dc(t, vm):
474 '''join a windows domain as a DC'''
476 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
478 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
479 t.vm_poweroff("${WIN_VM}", checkfail=False)
480 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
482 t.run_cmd("rm -rf etc/smb.conf private")
483 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
484 t.get_ipconfig(child)
485 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
486 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
487 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
490 def test_join_as_dc(t, vm):
491 '''test the join of a windows domain as a DC'''
492 t.info("Checking the DC join is OK")
494 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
495 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
496 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
498 t.info("Forcing kcc runs, and replication")
499 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
500 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
502 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
503 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
504 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
505 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
507 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
508 child.expect("The command completed successfully")
510 t.info("Checking if showrepl is happy")
511 child.sendline("repadmin /showrepl")
512 child.expect("${WIN_BASEDN}")
513 child.expect("was successful")
514 child.expect("CN=Configuration,${WIN_BASEDN}")
515 child.expect("was successful")
516 child.expect("CN=Configuration,${WIN_BASEDN}")
517 child.expect("was successful")
519 t.info("Checking if new users propogate to windows")
520 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
521 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
522 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
524 t.info("Checking if new users on windows propogate to samba")
525 child.sendline("net user test3 ${PASSWORD3} /add")
526 child.expect("The command completed successfully")
527 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
528 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
530 t.info("Checking propogation of user deletion")
531 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
532 child.sendline("net user test3 /del")
533 child.expect("The command completed successfully")
535 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
536 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
537 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
538 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
539 t.vm_poweroff("${WIN_VM}")
542 def join_as_rodc(t, vm):
543 '''join a windows domain as a RODC'''
545 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
547 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
548 t.vm_poweroff("${WIN_VM}", checkfail=False)
549 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
551 t.run_cmd("rm -rf etc/smb.conf private")
552 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
553 t.get_ipconfig(child)
554 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
555 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
556 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
559 def test_join_as_rodc(t, vm):
560 '''test a windows domain RODC join'''
561 t.info("Checking the RODC join is OK")
563 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
564 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
565 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
567 t.info("Forcing kcc runs, and replication")
568 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
569 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
571 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
572 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
573 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
575 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
576 child.expect("The command completed successfully")
578 t.info("Checking if showrepl is happy")
579 child.sendline("repadmin /showrepl")
580 child.expect("DSA invocationID")
582 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
583 [ "INBOUND NEIGHBORS",
584 "OUTBOUND NEIGHBORS",
586 "Last attempt .* was successful",
587 "CN=Configuration,${WIN_BASEDN}",
588 "Last attempt .* was successful",
589 "CN=Configuration,${WIN_BASEDN}",
590 "Last attempt .* was successful" ],
594 t.info("Checking if new users on windows propogate to samba")
595 child.sendline("net user test3 ${PASSWORD3} /add")
596 child.expect("The command completed successfully")
597 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
598 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
601 t.info("Checking if new users propogate to windows")
602 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
604 t.info("Checking propogation of user deletion")
605 child.sendline("net user test3 /del")
606 child.expect("The command completed successfully")
608 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
609 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
610 t.vm_poweroff("${WIN_VM}")
614 '''test the Samba4 howto'''
616 check_prerequesites(t)
618 # we don't need fsync safety in these tests
619 t.putenv('TDB_NO_FSYNC', '1')
621 if not t.skip("build"):
624 if not t.skip("provision"):
627 if not t.skip("create-shares"):
630 if not t.skip("starts4"):
632 if not t.skip("smbclient"):
634 if not t.skip("startbind"):
636 if not t.skip("dns"):
638 if not t.skip("kerberos"):
640 if not t.skip("dyndns"):
643 if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
644 run_winjoin(t, "WINDOWS7")
645 test_winjoin(t, "WINDOWS7")
647 if t.have_var('WINXP_VM') and not t.skip("winxp"):
648 run_winjoin(t, "WINXP")
649 test_winjoin(t, "WINXP")
651 if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
652 t.info("Testing w2k8r2 RODC dcpromo")
653 run_dcpromo_rodc(t, "W2K8R2C")
654 test_dcpromo_rodc(t, "W2K8R2C")
656 if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
657 t.info("Testing w2k8r2 dcpromo")
658 run_dcpromo(t, "W2K8R2B")
659 test_dcpromo(t, "W2K8R2B")
661 if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
662 t.info("Testing w2k8 dcpromo")
663 run_dcpromo(t, "W2K8B")
664 test_dcpromo(t, "W2K8B")
666 if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
667 t.info("Testing w2k3 dcpromo")
668 t.info("Changing to 2003 functional level")
669 provision_s4(t, func_level='2003')
677 run_dcpromo(t, "W2K3B")
678 test_dcpromo(t, "W2K3B")
680 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
681 join_as_dc(t, "W2K8R2A")
685 test_join_as_dc(t, "W2K8R2A")
687 if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
688 join_as_rodc(t, "W2K8R2A")
692 test_join_as_rodc(t, "W2K8R2A")
694 if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
695 join_as_dc(t, "W2K3A")
699 test_join_as_dc(t, "W2K3A")
701 t.info("Howto test: All OK")
705 '''cleanup after tests'''
706 restore_resolv_conf(t)
707 if getattr(t, 'bind_child', False):
711 if __name__ == '__main__':
712 parser = optparse.OptionParser("test-howto.py")
713 parser.add_option("--conf", type='string', default='', help='config file')
714 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
715 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
716 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
717 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
718 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
719 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
720 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
722 opts, args = parser.parse_args()
725 print("Please specify a config file with --conf")
728 t = wintest.wintest()
729 t.load_config(opts.conf)
730 t.set_skip(opts.skip)
736 t.setvar('PREFIX', opts.prefix)
739 t.setvar('SOURCETREE', opts.sourcetree)
743 t.chdir('${SOURCETREE}')
744 t.run_cmd('git pull --rebase')
748 t.chdir('${SOURCETREE}/source4')
749 t.run_cmd('rm -rf bin')
753 except Exception, str:
754 if not opts.nocleanup:
758 if not opts.nocleanup:
760 t.info("S4 howto test: All OK")