s4-python: Only set BASETYPE flag if subclassing is supported.
[Samba.git] / wintest / test-s4-howto.py
blobcb9862b8b92bc303a8224a9715035c6a37d4daf0
1 #!/usr/bin/env python
3 '''automated testing of the steps of the Samba4 HOWTO'''
5 import sys, os
6 import wintest, pexpect, time, subprocess
8 def set_krb5_conf(t):
9 t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
11 def build_s4(t):
12 '''build samba4'''
13 t.info('Building s4')
14 t.chdir('${SOURCETREE}/source4')
15 t.putenv('CC', 'ccache gcc')
16 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
17 t.run_cmd('make -j')
18 t.run_cmd('rm -rf ${PREFIX}')
19 t.run_cmd('make -j install')
22 def provision_s4(t, func_level="2008"):
23 '''provision s4 as a DC'''
24 t.info('Provisioning s4')
25 t.chdir('${PREFIX}')
26 t.del_files(["var", "private"])
27 t.run_cmd("rm -f etc/smb.conf")
28 provision=['sbin/provision',
29 '--realm=${LCREALM}',
30 '--domain=${DOMAIN}',
31 '--adminpass=${PASSWORD1}',
32 '--server-role=domain controller',
33 '--function-level=%s' % func_level,
34 '-d${DEBUGLEVEL}',
35 '--option=interfaces=${INTERFACE}',
36 '--host-ip=${INTERFACE_IP}',
37 '--option=bind interfaces only=yes',
38 '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
39 if t.getvar('INTERFACE_IPV6'):
40 provision.append('--host-ip6=${INTERFACE_IPV6}')
41 t.run_cmd(provision)
42 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
43 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
44 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
47 def start_s4(t):
48 '''startup samba4'''
49 t.info('Starting Samba4')
50 t.chdir("${PREFIX}")
51 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
52 t.run_cmd(['sbin/samba',
53 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
54 t.port_wait("${INTERFACE_IP}", 139)
56 def test_smbclient(t):
57 '''test smbclient against localhost'''
58 t.info('Testing smbclient')
59 t.chdir('${PREFIX}')
60 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
61 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
62 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
63 child.expect("smb:")
64 child.sendline("dir")
65 child.expect("blocks available")
66 child.sendline("mkdir testdir")
67 child.expect("smb:")
68 child.sendline("cd testdir")
69 child.expect('testdir')
70 child.sendline("cd ..")
71 child.sendline("rmdir testdir")
74 def create_shares(t):
75 '''create some test shares'''
76 t.info("Adding test shares")
77 t.chdir('${PREFIX}')
78 t.write_file("etc/smb.conf", '''
79 [test]
80 path = ${PREFIX}/test
81 read only = no
82 [profiles]
83 path = ${PREFIX}/var/profiles
84 read only = no
85 ''',
86 mode='a')
87 t.run_cmd("mkdir -p test")
88 t.run_cmd("mkdir -p var/profiles")
91 def test_dns(t):
92 '''test that DNS is OK'''
93 t.info("Testing DNS")
94 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
95 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
96 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
97 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
98 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
99 ['${HOSTNAME}.${LCREALM} has address'])
101 def test_kerberos(t):
102 '''test that kerberos is OK'''
103 t.info("Testing kerberos")
104 t.run_cmd("kdestroy")
105 t.kinit("administrator@${REALM}", "${PASSWORD1}")
106 # this copes with the differences between MIT and Heimdal klist
107 t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
110 def test_dyndns(t):
111 '''test that dynamic DNS is working'''
112 t.chdir('${PREFIX}')
113 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
114 t.rndc_cmd("flush")
117 def run_winjoin(t, vm):
118 '''join a windows box to our domain'''
119 t.setwinvars(vm)
121 t.run_winjoin(t, "${LCREALM}")
123 def test_winjoin(t, vm):
124 t.info("Checking the windows join is OK")
125 t.chdir('${PREFIX}')
126 t.port_wait("${WIN_IP}", 139)
127 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
128 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
129 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
130 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
131 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
132 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
133 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
134 child.expect("The command completed successfully")
137 def run_dcpromo(t, vm):
138 '''run a dcpromo on windows'''
139 t.setwinvars(vm)
141 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
142 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True, set_noexpire=True)
143 child.sendline("copy /Y con answers.txt")
144 child.sendline('''
145 [DCINSTALL]
146 RebootOnSuccess=Yes
147 RebootOnCompletion=Yes
148 ReplicaOrNewDomain=Replica
149 ReplicaDomainDNSName=${LCREALM}
150 SiteName=Default-First-Site-Name
151 InstallDNS=No
152 ConfirmGc=Yes
153 CreateDNSDelegation=No
154 UserDomain=${LCREALM}
155 UserName=${LCREALM}\\administrator
156 Password=${PASSWORD1}
157 DatabasePath="C:\Windows\NTDS"
158 LogPath="C:\Windows\NTDS"
159 SYSVOLPath="C:\Windows\SYSVOL"
160 SafeModeAdminPassword=${PASSWORD1}
161 \x1a
162 ''')
163 child.expect("copied.")
164 child.expect("C:")
165 child.expect("C:")
166 child.sendline("dcpromo /answer:answers.txt")
167 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
168 if i == 1 or i == 2:
169 raise Exception("dcpromo failed")
170 t.wait_reboot()
173 def test_dcpromo(t, vm):
174 '''test that dcpromo worked'''
175 t.info("Checking the dcpromo join is OK")
176 t.chdir('${PREFIX}')
177 t.port_wait("${WIN_IP}", 139)
178 t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
179 ['${WIN_HOSTNAME}.${LCREALM} has address'],
180 retries=30, delay=10, casefold=True)
181 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
182 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
183 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
185 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
186 t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
188 t.kinit("administrator@${REALM}", "${PASSWORD1}")
190 # the first replication will transfer the dnsHostname attribute
191 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
193 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
194 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
195 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
197 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
198 [ "INBOUND NEIGHBORS",
199 "${BASEDN}",
200 "Last attempt .* was successful",
201 "CN=Configuration,${BASEDN}",
202 "Last attempt .* was successful",
203 "CN=Configuration,${BASEDN}", # cope with either order
204 "Last attempt .* was successful",
205 "OUTBOUND NEIGHBORS",
206 "${BASEDN}",
207 "Last success",
208 "CN=Configuration,${BASEDN}",
209 "Last success",
210 "CN=Configuration,${BASEDN}",
211 "Last success"],
212 ordered=True,
213 regex=True)
215 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
216 [ "INBOUND NEIGHBORS",
217 "${BASEDN}",
218 "Last attempt .* was successful",
219 "CN=Configuration,${BASEDN}",
220 "Last attempt .* was successful",
221 "CN=Configuration,${BASEDN}",
222 "Last attempt .* was successful",
223 "OUTBOUND NEIGHBORS",
224 "${BASEDN}",
225 "Last success",
226 "CN=Configuration,${BASEDN}",
227 "Last success",
228 "CN=Configuration,${BASEDN}",
229 "Last success" ],
230 ordered=True,
231 regex=True)
233 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
234 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
236 retries = 10
237 i = child.expect(["The command completed successfully", "The network path was not found"])
238 while i == 1 and retries > 0:
239 child.expect("C:")
240 time.sleep(2)
241 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
242 i = child.expect(["The command completed successfully", "The network path was not found"])
243 retries -=1
245 t.run_net_time(child)
247 t.info("Checking if showrepl is happy")
248 child.sendline("repadmin /showrepl")
249 child.expect("${BASEDN}")
250 child.expect("was successful")
251 child.expect("CN=Configuration,${BASEDN}")
252 child.expect("was successful")
253 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
254 child.expect("was successful")
256 t.info("Checking if new users propogate to windows")
257 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
258 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
259 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
261 t.info("Checking if new users on windows propogate to samba")
262 child.sendline("net user test3 ${PASSWORD3} /add")
263 while True:
264 i = child.expect(["The command completed successfully",
265 "The directory service was unable to allocate a relative identifier"])
266 if i == 0:
267 break
268 time.sleep(2)
270 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
271 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
273 t.info("Checking propogation of user deletion")
274 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
275 child.sendline("net user test3 /del")
276 child.expect("The command completed successfully")
278 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
279 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
280 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
281 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
282 t.vm_poweroff("${WIN_VM}")
285 def run_dcpromo_rodc(t, vm):
286 '''run a RODC dcpromo to join a windows DC to the samba domain'''
287 t.setwinvars(vm)
288 t.info("Joining a w2k8 box to the domain as a RODC")
289 t.vm_poweroff("${WIN_VM}", checkfail=False)
290 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
291 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
292 child.sendline("copy /Y con answers.txt")
293 child.sendline('''
294 [DCInstall]
295 ReplicaOrNewDomain=ReadOnlyReplica
296 ReplicaDomainDNSName=${LCREALM}
297 PasswordReplicationDenied="BUILTIN\Administrators"
298 PasswordReplicationDenied="BUILTIN\Server Operators"
299 PasswordReplicationDenied="BUILTIN\Backup Operators"
300 PasswordReplicationDenied="BUILTIN\Account Operators"
301 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
302 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
303 DelegatedAdmin="${DOMAIN}\\Administrator"
304 SiteName=Default-First-Site-Name
305 InstallDNS=No
306 ConfirmGc=Yes
307 CreateDNSDelegation=No
308 UserDomain=${LCREALM}
309 UserName=${LCREALM}\\administrator
310 Password=${PASSWORD1}
311 DatabasePath="C:\Windows\NTDS"
312 LogPath="C:\Windows\NTDS"
313 SYSVOLPath="C:\Windows\SYSVOL"
314 SafeModeAdminPassword=${PASSWORD1}
315 RebootOnCompletion=No
316 \x1a
317 ''')
318 child.expect("copied.")
319 child.sendline("dcpromo /answer:answers.txt")
320 i = child.expect(["You must restart this computer", "failed"], timeout=120)
321 if i != 0:
322 raise Exception("dcpromo failed")
323 child.sendline("shutdown -r -t 0")
324 t.wait_reboot()
328 def test_dcpromo_rodc(t, vm):
329 '''test the RODC dcpromo worked'''
330 t.info("Checking the w2k8 RODC join is OK")
331 t.chdir('${PREFIX}')
332 t.port_wait("${WIN_IP}", 139)
333 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
334 child.sendline("ipconfig /registerdns")
335 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
336 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
337 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
338 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
339 child.expect("The command completed successfully")
341 t.info("Checking if showrepl is happy")
342 child.sendline("repadmin /showrepl")
343 child.expect("${BASEDN}")
344 child.expect("was successful")
345 child.expect("CN=Configuration,${BASEDN}")
346 child.expect("was successful")
347 child.expect("CN=Configuration,${BASEDN}")
348 child.expect("was successful")
350 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
351 t.cmd_contains("bin/samba-tool drs replicate --add-ref ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s" % nc, ["was successful"])
353 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
354 [ "INBOUND NEIGHBORS",
355 "OUTBOUND NEIGHBORS",
356 "${BASEDN}",
357 "Last attempt.*was successful",
358 "CN=Configuration,${BASEDN}",
359 "Last attempt.*was successful",
360 "CN=Configuration,${BASEDN}",
361 "Last attempt.*was successful" ],
362 ordered=True,
363 regex=True)
365 t.info("Checking if new users are available on windows")
366 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
367 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
368 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN}", ["was successful"])
369 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
370 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
371 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
372 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
373 t.vm_poweroff("${WIN_VM}")
376 def prep_join_as_dc(t, vm):
377 '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
378 t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
379 t.chdir('${PREFIX}')
380 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
381 t.rndc_cmd('flush')
382 t.run_cmd("rm -rf etc/smb.conf private")
383 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
384 t.get_ipconfig(child)
386 def join_as_dc(t, vm):
387 '''join a windows domain as a DC'''
388 t.setwinvars(vm)
389 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
390 t.port_wait("${WIN_IP}", 389)
391 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
393 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
394 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
395 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
398 def test_join_as_dc(t, vm):
399 '''test the join of a windows domain as a DC'''
400 t.info("Checking the DC join is OK")
401 t.chdir('${PREFIX}')
402 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
403 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
404 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
406 t.info("Forcing kcc runs, and replication")
407 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
408 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
410 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
411 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
412 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
413 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
415 retries = 10
416 i = 1
417 while i == 1 and retries > 0:
418 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
419 i = child.expect(["The command completed successfully", "The network path was not found"])
420 child.expect("C:")
421 if i == 1:
422 time.sleep(2)
423 retries -=1
425 t.info("Checking if showrepl is happy")
426 child.sendline("repadmin /showrepl")
427 child.expect("${WIN_BASEDN}")
428 child.expect("was successful")
429 child.expect("CN=Configuration,${WIN_BASEDN}")
430 child.expect("was successful")
431 child.expect("CN=Configuration,${WIN_BASEDN}")
432 child.expect("was successful")
434 t.info("Checking if new users propogate to windows")
435 t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
436 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
437 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
439 t.info("Checking if new users on windows propogate to samba")
440 child.sendline("net user test3 ${PASSWORD3} /add")
441 child.expect("The command completed successfully")
442 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
443 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
445 t.info("Checking propogation of user deletion")
446 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
447 child.sendline("net user test3 /del")
448 child.expect("The command completed successfully")
450 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
451 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
452 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
453 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
454 t.vm_poweroff("${WIN_VM}")
457 def join_as_rodc(t, vm):
458 '''join a windows domain as a RODC'''
459 t.setwinvars(vm)
460 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
461 t.port_wait("${WIN_IP}", 389)
462 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
463 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
464 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
465 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
468 def test_join_as_rodc(t, vm):
469 '''test a windows domain RODC join'''
470 t.info("Checking the RODC join is OK")
471 t.chdir('${PREFIX}')
472 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
473 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
474 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
476 t.info("Forcing kcc runs, and replication")
477 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
478 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
480 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
481 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
482 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
484 retries = 10
485 i = 1
486 while i == 1 and retries > 0:
487 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
488 i = child.expect(["The command completed successfully", "The network path was not found"])
489 child.expect("C:")
490 if i == 1:
491 time.sleep(2)
492 retries -=1
494 t.info("Checking if showrepl is happy")
495 child.sendline("repadmin /showrepl")
496 child.expect("DSA invocationID")
498 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
499 [ "INBOUND NEIGHBORS",
500 "OUTBOUND NEIGHBORS",
501 "${WIN_BASEDN}",
502 "Last attempt .* was successful",
503 "CN=Configuration,${WIN_BASEDN}",
504 "Last attempt .* was successful",
505 "CN=Configuration,${WIN_BASEDN}",
506 "Last attempt .* was successful" ],
507 ordered=True,
508 regex=True)
510 t.info("Checking if new users on windows propogate to samba")
511 child.sendline("net user test3 ${PASSWORD3} /add")
512 child.expect("The command completed successfully")
513 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
514 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
516 # should this work?
517 t.info("Checking if new users propogate to windows")
518 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
520 t.info("Checking propogation of user deletion")
521 child.sendline("net user test3 /del")
522 child.expect("The command completed successfully")
524 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
525 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
526 t.vm_poweroff("${WIN_VM}")
529 def test_howto(t):
530 '''test the Samba4 howto'''
532 t.setvar("SAMBA_VERSION", "Version 4")
533 t.check_prerequesites()
535 # we don't need fsync safety in these tests
536 t.putenv('TDB_NO_FSYNC', '1')
538 if not t.skip("configure_bind"):
539 t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
540 if not t.skip("stop_bind"):
541 t.stop_bind()
542 if not t.skip("stop_vms"):
543 t.stop_vms()
545 if not t.skip("build"):
546 build_s4(t)
548 if not t.skip("provision"):
549 provision_s4(t)
551 set_krb5_conf(t)
553 if not t.skip("create-shares"):
554 create_shares(t)
556 if not t.skip("starts4"):
557 start_s4(t)
558 if not t.skip("smbclient"):
559 test_smbclient(t)
560 if not t.skip("configure_bind2"):
561 t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
562 if not t.skip("start_bind"):
563 t.start_bind()
564 if not t.skip("dns"):
565 test_dns(t)
566 if not t.skip("kerberos"):
567 test_kerberos(t)
568 if not t.skip("dyndns"):
569 test_dyndns(t)
571 if t.have_vm('WINDOWS7') and not t.skip("windows7"):
572 t.start_winvm("WINDOWS7")
573 t.test_remote_smbclient("WINDOWS7")
574 run_winjoin(t, "WINDOWS7")
575 test_winjoin(t, "WINDOWS7")
576 t.vm_poweroff("${WIN_VM}")
578 if t.have_vm('WINXP') and not t.skip("winxp"):
579 t.start_winvm("WINXP")
580 run_winjoin(t, "WINXP")
581 test_winjoin(t, "WINXP")
582 t.test_remote_smbclient("WINXP", "administrator", "${PASSWORD1}")
583 t.vm_poweroff("${WIN_VM}")
585 if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
586 t.info("Testing w2k8r2 RODC dcpromo")
587 t.start_winvm("W2K8R2C")
588 t.test_remote_smbclient('W2K8R2C')
589 run_dcpromo_rodc(t, "W2K8R2C")
590 test_dcpromo_rodc(t, "W2K8R2C")
592 if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
593 t.info("Testing w2k8r2 dcpromo")
594 t.start_winvm("W2K8R2B")
595 t.test_remote_smbclient('W2K8R2B')
596 run_dcpromo(t, "W2K8R2B")
597 test_dcpromo(t, "W2K8R2B")
599 if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
600 t.info("Testing w2k8 dcpromo")
601 t.start_winvm("W2K8B")
602 t.test_remote_smbclient('W2K8B')
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')
610 create_shares(t)
611 start_s4(t)
612 test_smbclient(t)
613 t.restart_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
614 test_dns(t)
615 test_kerberos(t)
616 test_dyndns(t)
617 t.start_winvm("W2K3B")
618 t.test_remote_smbclient('W2K3B')
619 run_dcpromo(t, "W2K3B")
620 test_dcpromo(t, "W2K3B")
622 if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
623 t.start_winvm("W2K8R2A")
624 prep_join_as_dc(t, "W2K8R2A")
625 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
626 join_as_dc(t, "W2K8R2A")
627 create_shares(t)
628 start_s4(t)
629 test_dyndns(t)
630 test_join_as_dc(t, "W2K8R2A")
632 if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
633 t.start_winvm("W2K8R2A")
634 prep_join_as_dc(t, "W2K8R2A")
635 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
636 join_as_rodc(t, "W2K8R2A")
637 create_shares(t)
638 start_s4(t)
639 test_dyndns(t)
640 test_join_as_rodc(t, "W2K8R2A")
642 if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
643 prep_join_as_dc(t, "W2K3A")
644 t.run_dcpromo_as_first_dc("W2K3A", func_level='2003')
645 join_as_dc(t, "W2K3A")
646 create_shares(t)
647 start_s4(t)
648 test_dyndns(t)
649 test_join_as_dc(t, "W2K3A")
651 t.info("Howto test: All OK")
654 def test_cleanup(t):
655 '''cleanup after tests'''
656 t.info("Cleaning up ...")
657 t.restore_resolv_conf()
658 if getattr(t, 'bind_child', False):
659 t.bind_child.kill()
662 if __name__ == '__main__':
663 t = wintest.wintest()
665 t.setup("test-s4-howto.py", "source4")
667 try:
668 test_howto(t)
669 except:
670 if not t.opts.nocleanup:
671 test_cleanup(t)
672 raise
674 if not t.opts.nocleanup:
675 test_cleanup(t)
676 t.info("S4 howto test: All OK")