3 '''automated testing of the steps of the Samba4 HOWTO'''
6 import wintest, pexpect, time, subprocess
11 t.chdir('${SOURCETREE}/source4')
12 t.putenv('CC', 'ccache gcc')
13 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
15 t.run_cmd('rm -rf ${PREFIX}')
16 t.run_cmd('make -j install')
19 def provision_s4(t, func_level="2008"):
20 '''provision s4 as a DC'''
21 t.info('Provisioning s4')
23 t.del_files(["var", "private"])
24 t.run_cmd("rm -f etc/smb.conf")
25 provision=['sbin/provision',
28 '--adminpass=${PASSWORD1}',
29 '--server-role=domain controller',
30 '--function-level=%s' % func_level,
32 '--option=interfaces=${INTERFACE}',
33 '--host-ip=${INTERFACE_IP}',
34 '--option=bind interfaces only=yes',
35 '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
36 if t.getvar('INTERFACE_IPV6'):
37 provision.append('--host-ip6=${INTERFACE_IPV6}')
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("${INTERFACE_IP}", 139)
53 def test_smbclient(t):
55 t.info('Testing smbclient')
57 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
58 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
59 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
62 child.expect("blocks available")
63 child.sendline("mkdir testdir")
65 child.sendline("cd testdir")
66 child.expect('testdir')
67 child.sendline("cd ..")
68 child.sendline("rmdir testdir")
72 '''create some test shares'''
73 t.info("Adding test shares")
75 t.write_file("etc/smb.conf", '''
80 path = ${PREFIX}/var/profiles
84 t.run_cmd("mkdir -p test")
85 t.run_cmd("mkdir -p var/profiles")
89 '''test that DNS is OK'''
91 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
92 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
93 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
94 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
95 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
96 ['${HOSTNAME}.${LCREALM} has address'])
99 '''test that kerberos is OK'''
100 t.info("Testing kerberos")
101 t.run_cmd("kdestroy")
102 t.kinit("administrator@${REALM}", "${PASSWORD1}")
103 # this copes with the differences between MIT and Heimdal klist
104 t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
108 '''test that dynamic DNS is working'''
110 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
114 def run_winjoin(t, vm):
115 '''join a windows box to our domain'''
118 t.info("Joining a windows box to the domain")
119 t.vm_poweroff("${WIN_VM}", checkfail=False)
120 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
121 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True, set_noexpire=True)
122 child.sendline("ipconfig /flushdns")
124 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
125 child.expect("The command completed successfully")
127 child.sendline("shutdown /r -t 0")
129 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
130 child.sendline("ipconfig /registerdns")
131 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")
134 def test_winjoin(t, vm):
135 t.info("Checking the windows join is OK")
137 t.port_wait("${WIN_IP}", 139)
138 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
139 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
140 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
141 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
142 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
143 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
144 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
145 child.expect("The command completed successfully")
146 t.vm_poweroff("${WIN_VM}")
149 def run_dcpromo(t, vm):
150 '''run a dcpromo on windows'''
153 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
154 t.vm_poweroff("${WIN_VM}", checkfail=False)
155 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
156 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True, set_noexpire=True)
157 child.sendline("copy /Y con answers.txt")
161 RebootOnCompletion=Yes
162 ReplicaOrNewDomain=Replica
163 ReplicaDomainDNSName=${LCREALM}
164 SiteName=Default-First-Site-Name
167 CreateDNSDelegation=No
168 UserDomain=${LCREALM}
169 UserName=${LCREALM}\\administrator
170 Password=${PASSWORD1}
171 DatabasePath="C:\Windows\NTDS"
172 LogPath="C:\Windows\NTDS"
173 SYSVOLPath="C:\Windows\SYSVOL"
174 SafeModeAdminPassword=${PASSWORD1}
177 child.expect("copied.")
180 child.sendline("dcpromo /answer:answers.txt")
181 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
183 raise Exception("dcpromo failed")
187 def test_dcpromo(t, vm):
188 '''test that dcpromo worked'''
189 t.info("Checking the dcpromo join is OK")
191 t.port_wait("${WIN_IP}", 139)
192 t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
193 ['${WIN_HOSTNAME}.${LCREALM} has address'],
194 retries=30, delay=10, casefold=True)
195 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
196 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
197 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
199 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
200 t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
202 t.kinit("administrator@${REALM}", "${PASSWORD1}")
204 # the first replication will transfer the dnsHostname attribute
205 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
207 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
208 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
209 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
211 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
212 [ "INBOUND NEIGHBORS",
214 "Last attempt .* was successful",
215 "CN=Configuration,${BASEDN}",
216 "Last attempt .* was successful",
217 "CN=Configuration,${BASEDN}", # cope with either order
218 "Last attempt .* was successful",
219 "OUTBOUND NEIGHBORS",
222 "CN=Configuration,${BASEDN}",
224 "CN=Configuration,${BASEDN}",
229 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
230 [ "INBOUND NEIGHBORS",
232 "Last attempt .* was successful",
233 "CN=Configuration,${BASEDN}",
234 "Last attempt .* was successful",
235 "CN=Configuration,${BASEDN}",
236 "Last attempt .* was successful",
237 "OUTBOUND NEIGHBORS",
240 "CN=Configuration,${BASEDN}",
242 "CN=Configuration,${BASEDN}",
247 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
248 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
251 i = child.expect(["The command completed successfully", "The network path was not found"])
252 while i == 1 and retries > 0:
255 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
256 i = child.expect(["The command completed successfully", "The network path was not found"])
259 t.run_net_time(child)
261 t.info("Checking if showrepl is happy")
262 child.sendline("repadmin /showrepl")
263 child.expect("${BASEDN}")
264 child.expect("was successful")
265 child.expect("CN=Configuration,${BASEDN}")
266 child.expect("was successful")
267 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
268 child.expect("was successful")
270 t.info("Checking if new users propogate to windows")
271 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
272 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
273 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
275 t.info("Checking if new users on windows propogate to samba")
276 child.sendline("net user test3 ${PASSWORD3} /add")
278 i = child.expect(["The command completed successfully",
279 "The directory service was unable to allocate a relative identifier"])
284 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
285 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
287 t.info("Checking propogation of user deletion")
288 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
289 child.sendline("net user test3 /del")
290 child.expect("The command completed successfully")
292 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
293 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
294 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
295 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
296 t.vm_poweroff("${WIN_VM}")
299 def run_dcpromo_rodc(t, vm):
300 '''run a RODC dcpromo to join a windows DC to the samba domain'''
302 t.info("Joining a w2k8 box to the domain as a RODC")
303 t.vm_poweroff("${WIN_VM}", checkfail=False)
304 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
305 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
306 child.sendline("copy /Y con answers.txt")
309 ReplicaOrNewDomain=ReadOnlyReplica
310 ReplicaDomainDNSName=${LCREALM}
311 PasswordReplicationDenied="BUILTIN\Administrators"
312 PasswordReplicationDenied="BUILTIN\Server Operators"
313 PasswordReplicationDenied="BUILTIN\Backup Operators"
314 PasswordReplicationDenied="BUILTIN\Account Operators"
315 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
316 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
317 DelegatedAdmin="${DOMAIN}\\Administrator"
318 SiteName=Default-First-Site-Name
321 CreateDNSDelegation=No
322 UserDomain=${LCREALM}
323 UserName=${LCREALM}\\administrator
324 Password=${PASSWORD1}
325 DatabasePath="C:\Windows\NTDS"
326 LogPath="C:\Windows\NTDS"
327 SYSVOLPath="C:\Windows\SYSVOL"
328 SafeModeAdminPassword=${PASSWORD1}
329 RebootOnCompletion=No
332 child.expect("copied.")
333 child.sendline("dcpromo /answer:answers.txt")
334 i = child.expect(["You must restart this computer", "failed"], timeout=120)
336 raise Exception("dcpromo failed")
337 child.sendline("shutdown -r -t 0")
342 def test_dcpromo_rodc(t, vm):
343 '''test the RODC dcpromo worked'''
344 t.info("Checking the w2k8 RODC join is OK")
346 t.port_wait("${WIN_IP}", 139)
347 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
348 child.sendline("ipconfig /registerdns")
349 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
350 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
351 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
352 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
353 child.expect("The command completed successfully")
355 t.info("Checking if showrepl is happy")
356 child.sendline("repadmin /showrepl")
357 child.expect("${BASEDN}")
358 child.expect("was successful")
359 child.expect("CN=Configuration,${BASEDN}")
360 child.expect("was successful")
361 child.expect("CN=Configuration,${BASEDN}")
362 child.expect("was successful")
364 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
365 t.cmd_contains("bin/samba-tool drs replicate --add-ref ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s" % nc, ["was successful"])
367 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
368 [ "INBOUND NEIGHBORS",
369 "OUTBOUND NEIGHBORS",
371 "Last attempt.*was successful",
372 "CN=Configuration,${BASEDN}",
373 "Last attempt.*was successful",
374 "CN=Configuration,${BASEDN}",
375 "Last attempt.*was successful" ],
379 t.info("Checking if new users are available on windows")
380 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
381 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
382 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN}", ["was successful"])
383 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
384 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
385 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
386 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
387 t.vm_poweroff("${WIN_VM}")
390 def prep_join_as_dc(t, vm):
391 '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
393 t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
395 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
396 t.vm_poweroff("${WIN_VM}", checkfail=False)
397 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
399 t.run_cmd("rm -rf etc/smb.conf private")
400 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
401 t.get_ipconfig(child)
403 def join_as_dc(t, vm):
404 '''join a windows domain as a DC'''
406 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
407 t.port_wait("${WIN_IP}", 389)
408 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
410 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
411 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
412 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
415 def test_join_as_dc(t, vm):
416 '''test the join of a windows domain as a DC'''
417 t.info("Checking the DC join is OK")
419 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
420 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
421 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
423 t.info("Forcing kcc runs, and replication")
424 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
425 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
427 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
428 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
429 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
430 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
434 while i == 1 and retries > 0:
435 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
436 i = child.expect(["The command completed successfully", "The network path was not found"])
442 t.info("Checking if showrepl is happy")
443 child.sendline("repadmin /showrepl")
444 child.expect("${WIN_BASEDN}")
445 child.expect("was successful")
446 child.expect("CN=Configuration,${WIN_BASEDN}")
447 child.expect("was successful")
448 child.expect("CN=Configuration,${WIN_BASEDN}")
449 child.expect("was successful")
451 t.info("Checking if new users propogate to windows")
452 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
453 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
454 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
456 t.info("Checking if new users on windows propogate to samba")
457 child.sendline("net user test3 ${PASSWORD3} /add")
458 child.expect("The command completed successfully")
459 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
460 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
462 t.info("Checking propogation of user deletion")
463 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
464 child.sendline("net user test3 /del")
465 child.expect("The command completed successfully")
467 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
468 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
469 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
470 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
471 t.vm_poweroff("${WIN_VM}")
474 def join_as_rodc(t, vm):
475 '''join a windows domain as a RODC'''
477 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
478 t.port_wait("${WIN_IP}", 389)
479 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
480 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
481 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
482 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
485 def test_join_as_rodc(t, vm):
486 '''test a windows domain RODC join'''
487 t.info("Checking the RODC join is OK")
489 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
490 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
491 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
493 t.info("Forcing kcc runs, and replication")
494 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
495 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
497 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
498 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
499 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
503 while i == 1 and retries > 0:
504 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
505 i = child.expect(["The command completed successfully", "The network path was not found"])
511 t.info("Checking if showrepl is happy")
512 child.sendline("repadmin /showrepl")
513 child.expect("DSA invocationID")
515 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
516 [ "INBOUND NEIGHBORS",
517 "OUTBOUND NEIGHBORS",
519 "Last attempt .* was successful",
520 "CN=Configuration,${WIN_BASEDN}",
521 "Last attempt .* was successful",
522 "CN=Configuration,${WIN_BASEDN}",
523 "Last attempt .* was successful" ],
527 t.info("Checking if new users on windows propogate to samba")
528 child.sendline("net user test3 ${PASSWORD3} /add")
529 child.expect("The command completed successfully")
530 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
531 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
534 t.info("Checking if new users propogate to windows")
535 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
537 t.info("Checking propogation of user deletion")
538 child.sendline("net user test3 /del")
539 child.expect("The command completed successfully")
541 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
542 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
543 t.vm_poweroff("${WIN_VM}")
547 '''test the Samba4 howto'''
549 t.check_prerequesites()
551 # we don't need fsync safety in these tests
552 t.putenv('TDB_NO_FSYNC', '1')
554 if not t.skip("configure_bind"):
555 t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
556 if not t.skip("stop_bind"):
558 if not t.skip("stop_vms"):
561 if not t.skip("build"):
564 if not t.skip("provision"):
567 if not t.skip("create-shares"):
570 if not t.skip("starts4"):
572 if not t.skip("smbclient"):
574 if not t.skip("configure_bind2"):
575 t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
576 if not t.skip("start_bind"):
578 if not t.skip("dns"):
580 if not t.skip("kerberos"):
582 if not t.skip("dyndns"):
585 if t.have_vm('WINDOWS7') and not t.skip("windows7"):
586 run_winjoin(t, "WINDOWS7")
587 test_winjoin(t, "WINDOWS7")
589 if t.have_vm('WINXP') and not t.skip("winxp"):
590 run_winjoin(t, "WINXP")
591 test_winjoin(t, "WINXP")
593 if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
594 t.info("Testing w2k8r2 RODC dcpromo")
595 run_dcpromo_rodc(t, "W2K8R2C")
596 test_dcpromo_rodc(t, "W2K8R2C")
598 if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
599 t.info("Testing w2k8r2 dcpromo")
600 run_dcpromo(t, "W2K8R2B")
601 test_dcpromo(t, "W2K8R2B")
603 if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
604 t.info("Testing w2k8 dcpromo")
605 run_dcpromo(t, "W2K8B")
606 test_dcpromo(t, "W2K8B")
608 if t.have_vm('W2K3B') and not t.skip("dcpromo_w2k3"):
609 t.info("Testing w2k3 dcpromo")
610 t.info("Changing to 2003 functional level")
611 provision_s4(t, func_level='2003')
615 t.restart_bind(kerberos_support=True, include='{PREFIX}/private/named.conf')
619 run_dcpromo(t, "W2K3B")
620 test_dcpromo(t, "W2K3B")
622 if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
623 prep_join_as_dc(t, "W2K8R2A")
624 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
625 join_as_dc(t, "W2K8R2A")
629 test_join_as_dc(t, "W2K8R2A")
631 if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
632 prep_join_as_dc(t, "W2K8R2A")
633 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
634 join_as_rodc(t, "W2K8R2A")
638 test_join_as_rodc(t, "W2K8R2A")
640 if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
641 prep_join_as_dc(t, "W2K3A")
642 t.run_dcpromo_as_first_dc("W2K3A", func_level='2003')
643 join_as_dc(t, "W2K3A")
647 test_join_as_dc(t, "W2K3A")
649 t.info("Howto test: All OK")
653 '''cleanup after tests'''
654 t.info("Cleaning up ...")
655 t.restore_resolv_conf()
656 if getattr(t, 'bind_child', False):
660 if __name__ == '__main__':
661 t = wintest.wintest()
663 t.setup("test-s4-howto.py", "source4")
668 if not t.opts.nocleanup:
672 if not t.opts.nocleanup:
674 t.info("S4 howto test: All OK")