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_IP} up')
20 t.chdir('${SOURCETREE}/source4')
21 t.putenv('CC', 'ccache gcc')
22 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
24 t.run_cmd('rm -rf ${PREFIX}')
25 t.run_cmd('make -j install')
27 def provision_s4(t, func_level="2008", interface=None):
28 '''provision s4 as a DC'''
29 t.info('Provisioning s4')
31 t.del_files(["var", "etc", "private"])
32 options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
34 options += ' --option=interfaces=%s' % interface
35 options += ' --host-ip=%s' % interface
36 t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
37 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
38 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
39 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
41 def start_s4(t, interface=None):
42 t.info('Starting Samba4')
44 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
45 t.run_cmd(['sbin/samba',
46 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"',
47 '--option', 'interfaces=%s' % interface])
48 t.port_wait("localhost", 139)
50 def test_smbclient(t):
51 t.info('Testing smbclient')
53 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
54 t.retry_cmd('bin/smbclient -L localhost -U%', ["netlogon", "sysvol", "IPC Service"])
55 child = t.pexpect_spawn('bin/smbclient //localhost/netlogon -Uadministrator%${PASSWORD1}')
58 child.expect("blocks available")
59 child.sendline("mkdir testdir")
61 child.sendline("cd testdir")
62 child.expect('testdir')
63 child.sendline("cd ..")
64 child.sendline("rmdir testdir")
67 t.info("Adding test shares")
69 t.write_file("etc/smb.conf", '''
74 path = ${PREFIX}/var/profiles
78 t.run_cmd("mkdir -p test")
79 t.run_cmd("mkdir -p var/profiles")
83 t.info("Restarting bind9")
84 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
85 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
87 t.run_cmd("mkdir -p var/named/data")
88 t.run_cmd("chown -R ${BIND_USER} var/named")
90 nameserver = t.get_nameserver()
91 if nameserver == t.vars['INTERFACE_IP']:
92 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration")
93 t.setvar('DNSSERVER', nameserver)
95 t.write_file("etc/named.conf", '''
97 listen-on port 53 { ${INTERFACE_IP}; };
98 directory "${PREFIX}/var/named";
99 dump-file "${PREFIX}/var/named/data/cache_dump.db";
100 pid-file "${PREFIX}/var/named/named.pid";
101 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
102 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
103 allow-query { ${INTERFACE_NET}; 127.0.0.0/8; };
105 tkey-gssapi-credential "DNS/${LCREALM}";
106 tkey-domain "${REALM}";
117 secret "lA/cTrno03mt5Ju17ybEYw==";
122 allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
125 include "${PREFIX}/private/named.conf";
128 t.write_file("etc/rndc.conf", '''
132 secret "lA/cTrno03mt5Ju17ybEYw==";
136 default-key "rndc-key";
137 default-server ${INTERFACE_IP};
142 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf stop", checkfail=False)
143 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
144 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -c ${PREFIX}/etc/named.conf -g")
146 t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
147 t.write_file("/etc/resolv.conf", '''
148 # Generated by wintest, the Samba v Windows automated testing system
150 nameserver ${INTERFACE_IP}
152 # your original resolv.conf appears below:
156 t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
158 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
160 t.port_wait("${INTERFACE_IP}", 53)
161 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
162 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf freeze")
163 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf thaw")
165 def restore_resolv_conf(t):
166 if getattr(t, 'resolv_conf_backup', False):
167 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
170 t.info("Testing DNS")
171 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
172 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
173 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
174 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
175 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
176 ['${HOSTNAME}.${LCREALM} has address'])
178 def test_kerberos(t):
179 t.info("Testing kerberos")
180 t.run_cmd("kdestroy")
181 t.kinit("administrator@${REALM}", "${PASSWORD1}")
182 t.cmd_contains("klist -e", ["Ticket cache", "Default principal", "Valid starting"])
187 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
188 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf flush")
191 def run_winjoin(t, vm):
194 t.info("Joining a windows box to the domain")
195 t.vm_poweroff("${WIN_VM}", checkfail=False)
196 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
197 t.ping_wait("${WIN_HOSTNAME}")
198 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
199 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
200 child.expect("The command completed successfully")
202 child.sendline("shutdown /r -t 0")
203 t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
204 t.port_wait("${WIN_HOSTNAME}", 139)
205 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
206 child.sendline("ipconfig /registerdns")
207 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")
210 def test_winjoin(t, vm):
212 t.info("Checking the windows join is OK")
214 t.port_wait("${WIN_HOSTNAME}", 139)
215 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
216 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
217 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
218 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
219 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
220 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
221 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
222 child.expect("The command completed successfully")
223 t.vm_poweroff("${WIN_VM}")
226 def run_dcpromo(t, vm):
227 '''run a dcpromo on windows'''
230 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
231 t.vm_poweroff("${WIN_VM}", checkfail=False)
232 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
233 t.ping_wait("${WIN_HOSTNAME}")
234 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
235 child.sendline("copy /Y con answers.txt")
239 RebootOnCompletion=Yes
240 ReplicaOrNewDomain=Replica
241 ReplicaDomainDNSName=${LCREALM}
242 SiteName=Default-First-Site-Name
245 CreateDNSDelegation=No
246 UserDomain=${LCREALM}
247 UserName=${LCREALM}\\administrator
248 Password=${PASSWORD1}
249 DatabasePath="C:\Windows\NTDS"
250 LogPath="C:\Windows\NTDS"
251 SYSVOLPath="C:\Windows\SYSVOL"
252 SafeModeAdminPassword=${PASSWORD1}
255 child.expect("copied.")
258 child.sendline("dcpromo /answer:answers.txt")
259 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
261 raise Exception("dcpromo failed")
262 t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
263 t.port_wait("${WIN_HOSTNAME}", 139)
266 def test_dcpromo(t, vm):
268 t.info("Checking the dcpromo join is OK")
270 t.port_wait("${WIN_HOSTNAME}", 139)
271 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
272 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
273 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
275 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
276 t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
278 t.kinit("administrator@${REALM}", "${PASSWORD1}")
279 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
280 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
281 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
283 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME} -k yes",
284 [ "INBOUND NEIGHBORS",
286 "Last attempt .* was successful",
287 "CN=Configuration,${BASEDN}",
288 "Last attempt .* was successful",
289 "CN=Configuration,${BASEDN}", # cope with either order
290 "Last attempt .* was successful",
291 "OUTBOUND NEIGHBORS",
294 "CN=Configuration,${BASEDN}",
296 "CN=Configuration,${BASEDN}",
301 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -k yes",
302 [ "INBOUND NEIGHBORS",
304 "Last attempt .* was successful",
305 "CN=Configuration,${BASEDN}",
306 "Last attempt .* was successful",
307 "CN=Configuration,${BASEDN}",
308 "Last attempt .* was successful",
309 "OUTBOUND NEIGHBORS",
312 "CN=Configuration,${BASEDN}",
314 "CN=Configuration,${BASEDN}",
319 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
320 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
321 child.expect("The command completed successfully")
323 t.run_net_time(child)
325 t.info("Checking if showrepl is happy")
326 child.sendline("repadmin /showrepl")
327 child.expect("${BASEDN}")
328 child.expect("was successful")
329 child.expect("CN=Configuration,${BASEDN}")
330 child.expect("was successful")
331 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
332 child.expect("was successful")
334 t.info("Checking if new users propogate to windows")
335 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
336 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
337 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
339 t.info("Checking if new users on windows propogate to samba")
340 child.sendline("net user test3 ${PASSWORD3} /add")
342 i = child.expect(["The command completed successfully",
343 "The directory service was unable to allocate a relative identifier"])
348 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
349 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
351 t.info("Checking propogation of user deletion")
352 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
353 child.sendline("net user test3 /del")
354 child.expect("The command completed successfully")
356 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
357 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
358 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
359 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
360 t.vm_poweroff("${WIN_VM}")
363 def run_dcpromo_rodc(t, vm):
365 t.info("Joining a w2k8 box to the domain as a RODC")
366 t.vm_poweroff("${WIN_VM}", checkfail=False)
367 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
368 t.ping_wait("${WIN_HOSTNAME}")
369 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
370 child.sendline("copy /Y con answers.txt")
373 ReplicaOrNewDomain=ReadOnlyReplica
374 ReplicaDomainDNSName=${LCREALM}
375 PasswordReplicationDenied="BUILTIN\Administrators"
376 PasswordReplicationDenied="BUILTIN\Server Operators"
377 PasswordReplicationDenied="BUILTIN\Backup Operators"
378 PasswordReplicationDenied="BUILTIN\Account Operators"
379 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
380 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
381 DelegatedAdmin="${DOMAIN}\\Administrator"
382 SiteName=Default-First-Site-Name
385 CreateDNSDelegation=No
386 UserDomain=${LCREALM}
387 UserName=${LCREALM}\\administrator
388 Password=${PASSWORD1}
389 DatabasePath="C:\Windows\NTDS"
390 LogPath="C:\Windows\NTDS"
391 SYSVOLPath="C:\Windows\SYSVOL"
392 SafeModeAdminPassword=${PASSWORD1}
393 RebootOnCompletion=No
396 child.expect("copied.")
397 child.sendline("dcpromo /answer:answers.txt")
398 i = child.expect(["You must restart this computer", "failed"], timeout=120)
400 raise Exception("dcpromo failed")
401 child.sendline("shutdown -r -t 0")
402 t.port_wait("${WIN_HOSTNAME}", 139, wait_for_fail=True)
403 t.port_wait("${WIN_HOSTNAME}", 139)
407 def test_dcpromo_rodc(t, vm):
409 t.info("Checking the w2k8 RODC join is OK")
411 t.port_wait("${WIN_HOSTNAME}", 139)
412 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
413 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
414 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
415 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
416 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
417 child.expect("The command completed successfully")
419 t.info("Checking if showrepl is happy")
420 child.sendline("repadmin /showrepl")
421 child.expect("${BASEDN}")
422 child.expect("was successful")
423 child.expect("CN=Configuration,${BASEDN}")
424 child.expect("was successful")
425 child.expect("CN=Configuration,${BASEDN}")
426 child.expect("was successful")
428 t.info("Checking if new users are available on windows")
429 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
430 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
431 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
432 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
433 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2}", ['LOGON_FAILURE'])
434 t.vm_poweroff("${WIN_VM}")
437 def join_as_dc(t, vm):
439 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
441 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
442 t.vm_poweroff("${WIN_VM}", checkfail=False)
443 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
444 t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
445 t.run_cmd("rm -rf etc private")
446 t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
447 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
448 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
449 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
452 def test_join_as_dc(t, vm):
454 t.info("Checking the DC join is OK")
456 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
457 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
458 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
460 t.info("Forcing kcc runs, and replication")
461 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
462 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
464 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
465 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
466 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
467 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
469 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
470 child.expect("The command completed successfully")
472 t.info("Checking if showrepl is happy")
473 child.sendline("repadmin /showrepl")
474 child.expect("${WIN_BASEDN}")
475 child.expect("was successful")
476 child.expect("CN=Configuration,${WIN_BASEDN}")
477 child.expect("was successful")
478 child.expect("CN=Configuration,${WIN_BASEDN}")
479 child.expect("was successful")
481 t.info("Checking if new users propogate to windows")
482 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
483 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
484 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
486 t.info("Checking if new users on windows propogate to samba")
487 child.sendline("net user test3 ${PASSWORD3} /add")
488 child.expect("The command completed successfully")
489 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
490 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
492 t.info("Checking propogation of user deletion")
493 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
494 child.sendline("net user test3 /del")
495 child.expect("The command completed successfully")
497 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
498 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
499 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
500 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
501 t.vm_poweroff("${WIN_VM}")
504 def join_as_rodc(t, vm):
506 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
508 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
509 t.vm_poweroff("${WIN_VM}", checkfail=False)
510 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
511 t.run_cmd('${RNDC} -c ${PREFIX}/etc/rndc.conf flush')
512 t.run_cmd("rm -rf etc private")
513 t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True, set_ip=True)
514 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
515 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL}')
516 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
519 def test_join_as_rodc(t, vm):
521 t.info("Checking the RODC join is OK")
523 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
524 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
525 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
527 t.info("Forcing kcc runs, and replication")
528 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
529 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
531 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
532 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
533 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME} %s -k yes" % nc, ["was successful"])
535 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
536 child.expect("The command completed successfully")
538 t.info("Checking if showrepl is happy")
539 child.sendline("repadmin /showrepl")
540 child.expect("DSA invocationID")
542 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
543 [ "INBOUND NEIGHBORS",
544 "OUTBOUND NEIGHBORS",
546 "Last attempt .* was successful",
547 "CN=Configuration,${WIN_BASEDN}",
548 "Last attempt .* was successful",
549 "CN=Configuration,${WIN_BASEDN}",
550 "Last attempt .* was successful" ],
554 t.info("Checking if new users on windows propogate to samba")
555 child.sendline("net user test3 ${PASSWORD3} /add")
556 child.expect("The command completed successfully")
557 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
558 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
561 t.info("Checking if new users propogate to windows")
562 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
564 t.info("Checking propogation of user deletion")
565 child.sendline("net user test3 /del")
566 child.expect("The command completed successfully")
568 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
569 t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
570 t.vm_poweroff("${WIN_VM}")
574 '''test the Samba4 howto'''
576 check_prerequesites(t)
578 # we don't need fsync safety in these tests
579 t.putenv('TDB_NO_FSYNC', '1')
581 if not t.skip("build"):
584 if not t.skip("provision"):
585 provision_s4(t, interface='${INTERFACE_IP}')
587 if not t.skip("create-shares"):
590 if not t.skip("starts4"):
591 start_s4(t, interface='${INTERFACE_IP}')
592 if not t.skip("smbclient"):
594 if not t.skip("startbind"):
596 if not t.skip("dns"):
598 if not t.skip("kerberos"):
600 if not t.skip("dyndns"):
603 if t.have_var('WINDOWS7_VM') and not t.skip("windows7"):
604 run_winjoin(t, "WINDOWS7")
605 test_winjoin(t, "WINDOWS7")
607 if t.have_var('WINXP_VM') and not t.skip("winxp"):
608 run_winjoin(t, "WINXP")
609 test_winjoin(t, "WINXP")
611 if t.have_var('W2K8R2C_VM') and not t.skip("dcpromo_rodc"):
612 t.info("Testing w2k8r2 RODC dcpromo")
613 run_dcpromo_rodc(t, "W2K8R2C")
614 test_dcpromo_rodc(t, "W2K8R2C")
616 if t.have_var('W2K8R2B_VM') and not t.skip("dcpromo_w2k8r2"):
617 t.info("Testing w2k8r2 dcpromo")
618 run_dcpromo(t, "W2K8R2B")
619 test_dcpromo(t, "W2K8R2B")
621 if t.have_var('W2K8B_VM') and not t.skip("dcpromo_w2k8"):
622 t.info("Testing w2k8 dcpromo")
623 run_dcpromo(t, "W2K8B")
624 test_dcpromo(t, "W2K8B")
626 if t.have_var('W2K3B_VM') and not t.skip("dcpromo_w2k3"):
627 t.info("Testing w2k3 dcpromo")
628 t.info("Changing to 2003 functional level")
629 provision_s4(t, func_level='2003', interfaces='${INTERFACES}')
631 start_s4(t, interfaces='${INTERFACES}')
637 run_dcpromo(t, "W2K3B")
638 test_dcpromo(t, "W2K3B")
640 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
641 join_as_dc(t, "W2K8R2A")
643 start_s4(t, interfaces='${INTERFACES}')
645 test_join_as_dc(t, "W2K8R2A")
647 if t.have_var('W2K8R2A_VM') and not t.skip("join_rodc"):
648 join_as_rodc(t, "W2K8R2A")
650 start_s4(t, interfaces='${INTERFACES}')
652 test_join_as_rodc(t, "W2K8R2A")
654 if t.have_var('W2K3A_VM') and not t.skip("join_w2k3"):
655 join_as_dc(t, "W2K3A")
657 start_s4(t, interfaces='${INTERFACES}')
659 test_join_as_dc(t, "W2K3A")
661 t.info("Howto test: All OK")
664 if __name__ == '__main__':
665 parser = optparse.OptionParser("test-howto.py")
666 parser.add_option("--conf", type='string', default='', help='config file')
667 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
668 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
669 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
670 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
671 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
672 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
674 opts, args = parser.parse_args()
677 print("Please specify a config file with --conf")
680 t = wintest.wintest()
681 t.load_config(opts.conf)
682 t.set_skip(opts.skip)
688 t.setvar('PREFIX', opts.prefix)
691 t.setvar('SOURCETREE', opts.sourcetree)
695 t.chdir('${SOURCETREE}')
696 t.run_cmd('git pull --rebase')
700 t.chdir('${SOURCETREE}/source4')
701 t.run_cmd('rm -rf bin')
705 except Exception, str:
706 restore_resolv_conf(t)
707 if getattr(t, 'bind_child', False):