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("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
123 child.expect("The command completed successfully")
125 child.sendline("shutdown /r -t 0")
127 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
128 child.sendline("ipconfig /registerdns")
129 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")
132 def test_winjoin(t, vm):
133 t.info("Checking the windows join is OK")
135 t.port_wait("${WIN_IP}", 139)
136 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
137 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
138 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
139 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
140 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
141 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
142 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
143 child.expect("The command completed successfully")
144 t.vm_poweroff("${WIN_VM}")
147 def run_dcpromo(t, vm):
148 '''run a dcpromo on windows'''
151 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
152 t.vm_poweroff("${WIN_VM}", checkfail=False)
153 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
154 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True, set_noexpire=True)
155 child.sendline("copy /Y con answers.txt")
159 RebootOnCompletion=Yes
160 ReplicaOrNewDomain=Replica
161 ReplicaDomainDNSName=${LCREALM}
162 SiteName=Default-First-Site-Name
165 CreateDNSDelegation=No
166 UserDomain=${LCREALM}
167 UserName=${LCREALM}\\administrator
168 Password=${PASSWORD1}
169 DatabasePath="C:\Windows\NTDS"
170 LogPath="C:\Windows\NTDS"
171 SYSVOLPath="C:\Windows\SYSVOL"
172 SafeModeAdminPassword=${PASSWORD1}
175 child.expect("copied.")
178 child.sendline("dcpromo /answer:answers.txt")
179 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
181 raise Exception("dcpromo failed")
185 def test_dcpromo(t, vm):
186 '''test that dcpromo worked'''
187 t.info("Checking the dcpromo join is OK")
189 t.port_wait("${WIN_IP}", 139)
190 t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
191 ['${WIN_HOSTNAME}.${LCREALM} has address'],
192 retries=30, delay=10, casefold=True)
193 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
194 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
195 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
197 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
198 t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
200 t.kinit("administrator@${REALM}", "${PASSWORD1}")
202 # the first replication will transfer the dnsHostname attribute
203 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
205 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
206 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
207 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
209 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
210 [ "INBOUND NEIGHBORS",
212 "Last attempt .* was successful",
213 "CN=Configuration,${BASEDN}",
214 "Last attempt .* was successful",
215 "CN=Configuration,${BASEDN}", # cope with either order
216 "Last attempt .* was successful",
217 "OUTBOUND NEIGHBORS",
220 "CN=Configuration,${BASEDN}",
222 "CN=Configuration,${BASEDN}",
227 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
228 [ "INBOUND NEIGHBORS",
230 "Last attempt .* was successful",
231 "CN=Configuration,${BASEDN}",
232 "Last attempt .* was successful",
233 "CN=Configuration,${BASEDN}",
234 "Last attempt .* was successful",
235 "OUTBOUND NEIGHBORS",
238 "CN=Configuration,${BASEDN}",
240 "CN=Configuration,${BASEDN}",
245 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
246 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
249 i = child.expect(["The command completed successfully", "The network path was not found"])
250 while i == 1 and retries > 0:
253 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
254 i = child.expect(["The command completed successfully", "The network path was not found"])
257 t.run_net_time(child)
259 t.info("Checking if showrepl is happy")
260 child.sendline("repadmin /showrepl")
261 child.expect("${BASEDN}")
262 child.expect("was successful")
263 child.expect("CN=Configuration,${BASEDN}")
264 child.expect("was successful")
265 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
266 child.expect("was successful")
268 t.info("Checking if new users propogate to windows")
269 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
270 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
271 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
273 t.info("Checking if new users on windows propogate to samba")
274 child.sendline("net user test3 ${PASSWORD3} /add")
276 i = child.expect(["The command completed successfully",
277 "The directory service was unable to allocate a relative identifier"])
282 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
283 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
285 t.info("Checking propogation of user deletion")
286 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
287 child.sendline("net user test3 /del")
288 child.expect("The command completed successfully")
290 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
291 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
292 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
293 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
294 t.vm_poweroff("${WIN_VM}")
297 def run_dcpromo_rodc(t, vm):
298 '''run a RODC dcpromo to join a windows DC to the samba domain'''
300 t.info("Joining a w2k8 box to the domain as a RODC")
301 t.vm_poweroff("${WIN_VM}", checkfail=False)
302 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
303 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
304 child.sendline("copy /Y con answers.txt")
307 ReplicaOrNewDomain=ReadOnlyReplica
308 ReplicaDomainDNSName=${LCREALM}
309 PasswordReplicationDenied="BUILTIN\Administrators"
310 PasswordReplicationDenied="BUILTIN\Server Operators"
311 PasswordReplicationDenied="BUILTIN\Backup Operators"
312 PasswordReplicationDenied="BUILTIN\Account Operators"
313 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
314 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
315 DelegatedAdmin="${DOMAIN}\\Administrator"
316 SiteName=Default-First-Site-Name
319 CreateDNSDelegation=No
320 UserDomain=${LCREALM}
321 UserName=${LCREALM}\\administrator
322 Password=${PASSWORD1}
323 DatabasePath="C:\Windows\NTDS"
324 LogPath="C:\Windows\NTDS"
325 SYSVOLPath="C:\Windows\SYSVOL"
326 SafeModeAdminPassword=${PASSWORD1}
327 RebootOnCompletion=No
330 child.expect("copied.")
331 child.sendline("dcpromo /answer:answers.txt")
332 i = child.expect(["You must restart this computer", "failed"], timeout=120)
334 raise Exception("dcpromo failed")
335 child.sendline("shutdown -r -t 0")
340 def test_dcpromo_rodc(t, vm):
341 '''test the RODC dcpromo worked'''
342 t.info("Checking the w2k8 RODC join is OK")
344 t.port_wait("${WIN_IP}", 139)
345 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
346 child.sendline("ipconfig /registerdns")
347 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
348 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
349 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
350 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
351 child.expect("The command completed successfully")
353 t.info("Checking if showrepl is happy")
354 child.sendline("repadmin /showrepl")
355 child.expect("${BASEDN}")
356 child.expect("was successful")
357 child.expect("CN=Configuration,${BASEDN}")
358 child.expect("was successful")
359 child.expect("CN=Configuration,${BASEDN}")
360 child.expect("was successful")
362 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
363 t.cmd_contains("bin/samba-tool drs replicate --add-ref ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s" % nc, ["was successful"])
365 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
366 [ "INBOUND NEIGHBORS",
367 "OUTBOUND NEIGHBORS",
369 "Last attempt.*was successful",
370 "CN=Configuration,${BASEDN}",
371 "Last attempt.*was successful",
372 "CN=Configuration,${BASEDN}",
373 "Last attempt.*was successful" ],
377 t.info("Checking if new users are available on windows")
378 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
379 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
380 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN}", ["was successful"])
381 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
382 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
383 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
384 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
385 t.vm_poweroff("${WIN_VM}")
388 def prep_join_as_dc(t, vm):
389 '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
391 t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
393 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
394 t.vm_poweroff("${WIN_VM}", checkfail=False)
395 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
397 t.run_cmd("rm -rf etc/smb.conf private")
398 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
399 t.get_ipconfig(child)
401 def join_as_dc(t, vm):
402 '''join a windows domain as a DC'''
404 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
405 t.port_wait("${WIN_IP}", 389)
406 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
408 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
409 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
410 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
413 def test_join_as_dc(t, vm):
414 '''test the join of a windows domain as a DC'''
415 t.info("Checking the DC join is OK")
417 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
418 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
419 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
421 t.info("Forcing kcc runs, and replication")
422 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
423 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
425 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
426 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
427 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
428 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
432 while i == 1 and retries > 0:
433 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
434 i = child.expect(["The command completed successfully", "The network path was not found"])
440 t.info("Checking if showrepl is happy")
441 child.sendline("repadmin /showrepl")
442 child.expect("${WIN_BASEDN}")
443 child.expect("was successful")
444 child.expect("CN=Configuration,${WIN_BASEDN}")
445 child.expect("was successful")
446 child.expect("CN=Configuration,${WIN_BASEDN}")
447 child.expect("was successful")
449 t.info("Checking if new users propogate to windows")
450 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
451 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
452 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
454 t.info("Checking if new users on windows propogate to samba")
455 child.sendline("net user test3 ${PASSWORD3} /add")
456 child.expect("The command completed successfully")
457 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
458 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
460 t.info("Checking propogation of user deletion")
461 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
462 child.sendline("net user test3 /del")
463 child.expect("The command completed successfully")
465 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
466 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
467 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
468 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
469 t.vm_poweroff("${WIN_VM}")
472 def join_as_rodc(t, vm):
473 '''join a windows domain as a RODC'''
475 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
476 t.port_wait("${WIN_IP}", 389)
477 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
478 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
479 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
480 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
483 def test_join_as_rodc(t, vm):
484 '''test a windows domain RODC join'''
485 t.info("Checking the RODC join is OK")
487 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
488 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
489 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
491 t.info("Forcing kcc runs, and replication")
492 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
493 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
495 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
496 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
497 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
501 while i == 1 and retries > 0:
502 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
503 i = child.expect(["The command completed successfully", "The network path was not found"])
509 t.info("Checking if showrepl is happy")
510 child.sendline("repadmin /showrepl")
511 child.expect("DSA invocationID")
513 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
514 [ "INBOUND NEIGHBORS",
515 "OUTBOUND NEIGHBORS",
517 "Last attempt .* was successful",
518 "CN=Configuration,${WIN_BASEDN}",
519 "Last attempt .* was successful",
520 "CN=Configuration,${WIN_BASEDN}",
521 "Last attempt .* was successful" ],
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}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
529 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
532 t.info("Checking if new users propogate to windows")
533 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
535 t.info("Checking propogation of user deletion")
536 child.sendline("net user test3 /del")
537 child.expect("The command completed successfully")
539 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
540 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
541 t.vm_poweroff("${WIN_VM}")
545 '''test the Samba4 howto'''
547 t.check_prerequesites()
549 # we don't need fsync safety in these tests
550 t.putenv('TDB_NO_FSYNC', '1')
552 if not t.skip("configure_bind"):
553 t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
554 if not t.skip("stop_bind"):
556 if not t.skip("stop_vms"):
559 if not t.skip("build"):
562 if not t.skip("provision"):
565 if not t.skip("create-shares"):
568 if not t.skip("starts4"):
570 if not t.skip("smbclient"):
572 if not t.skip("configure_bind2"):
573 t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
574 if not t.skip("start_bind"):
576 if not t.skip("dns"):
578 if not t.skip("kerberos"):
580 if not t.skip("dyndns"):
583 if t.have_vm('WINDOWS7') and not t.skip("windows7"):
584 run_winjoin(t, "WINDOWS7")
585 test_winjoin(t, "WINDOWS7")
587 if t.have_vm('WINXP') and not t.skip("winxp"):
588 run_winjoin(t, "WINXP")
589 test_winjoin(t, "WINXP")
591 if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
592 t.info("Testing w2k8r2 RODC dcpromo")
593 run_dcpromo_rodc(t, "W2K8R2C")
594 test_dcpromo_rodc(t, "W2K8R2C")
596 if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
597 t.info("Testing w2k8r2 dcpromo")
598 run_dcpromo(t, "W2K8R2B")
599 test_dcpromo(t, "W2K8R2B")
601 if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
602 t.info("Testing w2k8 dcpromo")
603 run_dcpromo(t, "W2K8B")
604 test_dcpromo(t, "W2K8B")
606 if t.have_vm('W2K3B') and not t.skip("dcpromo_w2k3"):
607 t.info("Testing w2k3 dcpromo")
608 t.info("Changing to 2003 functional level")
609 provision_s4(t, func_level='2003')
613 t.restart_bind(kerberos_support=True, include='{PREFIX}/private/named.conf')
617 run_dcpromo(t, "W2K3B")
618 test_dcpromo(t, "W2K3B")
620 if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
621 prep_join_as_dc(t, "W2K8R2A")
622 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
623 join_as_dc(t, "W2K8R2A")
627 test_join_as_dc(t, "W2K8R2A")
629 if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
630 prep_join_as_dc(t, "W2K8R2A")
631 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
632 join_as_rodc(t, "W2K8R2A")
636 test_join_as_rodc(t, "W2K8R2A")
638 if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
639 prep_join_as_dc(t, "W2K3A")
640 t.run_dcpromo_as_first_dc("W2K3A", func_level='2003')
641 join_as_dc(t, "W2K3A")
645 test_join_as_dc(t, "W2K3A")
647 t.info("Howto test: All OK")
651 '''cleanup after tests'''
652 t.info("Cleaning up ...")
653 t.restore_resolv_conf()
654 if getattr(t, 'bind_child', False):
658 if __name__ == '__main__':
659 t = wintest.wintest()
661 t.setup("test-s4-howto.py", "source4")
666 if not t.opts.nocleanup:
670 if not t.opts.nocleanup:
672 t.info("S4 howto test: All OK")