63a27d251a56a22250285946c17ca4fca10ddadb
[samba.git] / wintest / test-s4-howto.py
1 #!/usr/bin/env python
2
3 '''automated testing of the steps of the Samba4 HOWTO'''
4
5 import sys, os
6 import wintest, pexpect, time, subprocess
7
8 def build_s4(t):
9     '''build samba4'''
10     t.info('Building s4')
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')
14     t.run_cmd('make -j')
15     t.run_cmd('rm -rf ${PREFIX}')
16     t.run_cmd('make -j install')
17
18
19 def provision_s4(t, func_level="2008"):
20     '''provision s4 as a DC'''
21     t.info('Provisioning s4')
22     t.chdir('${PREFIX}')
23     t.del_files(["var", "private"])
24     t.run_cmd("rm -f etc/smb.conf")
25     provision=['sbin/provision',
26                '--realm=${LCREALM}',
27                '--domain=${DOMAIN}',
28                '--adminpass=${PASSWORD1}',
29                '--server-role=domain controller',
30                '--function-level=%s' % func_level,
31                '-d${DEBUGLEVEL}',
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}')
38     t.run_cmd(provision)
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')
42
43
44 def start_s4(t):
45     '''startup samba4'''
46     t.info('Starting Samba4')
47     t.chdir("${PREFIX}")
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)
52
53 def test_smbclient(t):
54     '''test smbclient'''
55     t.info('Testing smbclient')
56     t.chdir('${PREFIX}')
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}')
60     child.expect("smb:")
61     child.sendline("dir")
62     child.expect("blocks available")
63     child.sendline("mkdir testdir")
64     child.expect("smb:")
65     child.sendline("cd testdir")
66     child.expect('testdir')
67     child.sendline("cd ..")
68     child.sendline("rmdir testdir")
69
70
71 def create_shares(t):
72     '''create some test shares'''
73     t.info("Adding test shares")
74     t.chdir('${PREFIX}')
75     t.write_file("etc/smb.conf", '''
76 [test]
77        path = ${PREFIX}/test
78        read only = no
79 [profiles]
80        path = ${PREFIX}/var/profiles
81        read only = no
82     ''',
83                  mode='a')
84     t.run_cmd("mkdir -p test")
85     t.run_cmd("mkdir -p var/profiles")
86
87
88 def test_dns(t):
89     '''test that DNS is OK'''
90     t.info("Testing DNS")
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'])
97
98 def test_kerberos(t):
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}"])
105
106
107 def test_dyndns(t):
108     '''test that dynamic DNS is working'''
109     t.chdir('${PREFIX}')
110     t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
111     t.rndc_cmd("flush")
112
113
114 def run_winjoin(t, vm):
115     '''join a windows box to our domain'''
116     t.setwinvars(vm)
117
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")
123     child.expect("C:")
124     child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
125     child.expect("The command completed successfully")
126     child.expect("C:")
127     child.sendline("shutdown /r -t 0")
128     t.wait_reboot()
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")
132     child.expect("C:")
133
134 def test_winjoin(t, vm):
135     t.info("Checking the windows join is OK")
136     t.chdir('${PREFIX}')
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}")
147
148
149 def run_dcpromo(t, vm):
150     '''run a dcpromo on windows'''
151     t.setwinvars(vm)
152
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")
158     child.sendline('''
159 [DCINSTALL]
160 RebootOnSuccess=Yes
161 RebootOnCompletion=Yes
162 ReplicaOrNewDomain=Replica
163 ReplicaDomainDNSName=${LCREALM}
164 SiteName=Default-First-Site-Name
165 InstallDNS=No
166 ConfirmGc=Yes
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}
175 \1a
176 ''')
177     child.expect("copied.")
178     child.expect("C:")
179     child.expect("C:")
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)
182     if i == 1 or i == 2:
183         raise Exception("dcpromo failed")
184     t.wait_reboot()
185
186
187 def test_dcpromo(t, vm):
188     '''test that dcpromo worked'''
189     t.info("Checking the dcpromo join is OK")
190     t.chdir('${PREFIX}')
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"])
198
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'])
201
202     t.kinit("administrator@${REALM}", "${PASSWORD1}")
203
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"])
206
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"])
210
211     t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
212                  [ "INBOUND NEIGHBORS",
213                    "${BASEDN}",
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",
220                    "${BASEDN}",
221                    "Last success",
222                    "CN=Configuration,${BASEDN}",
223                    "Last success",
224                    "CN=Configuration,${BASEDN}",
225                    "Last success"],
226                    ordered=True,
227                    regex=True)
228
229     t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
230                  [ "INBOUND NEIGHBORS",
231                    "${BASEDN}",
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",
238                    "${BASEDN}",
239                    "Last success",
240                    "CN=Configuration,${BASEDN}",
241                    "Last success",
242                    "CN=Configuration,${BASEDN}",
243                    "Last success" ],
244                    ordered=True,
245                    regex=True)
246
247     child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
248     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
249
250     retries = 10
251     i = child.expect(["The command completed successfully", "The network path was not found"])
252     while i == 1 and retries > 0:
253         child.expect("C:")
254         time.sleep(2)
255         child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
256         i = child.expect(["The command completed successfully", "The network path was not found"])
257         retries -=1
258
259     t.run_net_time(child)
260
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")
269
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'])
274
275     t.info("Checking if new users on windows propogate to samba")
276     child.sendline("net user test3 ${PASSWORD3} /add")
277     while True:
278         i = child.expect(["The command completed successfully",
279                           "The directory service was unable to allocate a relative identifier"])
280         if i == 0:
281             break
282         time.sleep(2)
283
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'])
286
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")
291
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}")
297
298
299 def run_dcpromo_rodc(t, vm):
300     '''run a RODC dcpromo to join a windows DC to the samba domain'''
301     t.setwinvars(vm)
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")
307     child.sendline('''
308 [DCInstall]
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
319 InstallDNS=No
320 ConfirmGc=Yes
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
330 \1a
331 ''')
332     child.expect("copied.")
333     child.sendline("dcpromo /answer:answers.txt")
334     i = child.expect(["You must restart this computer", "failed"], timeout=120)
335     if i != 0:
336         raise Exception("dcpromo failed")
337     child.sendline("shutdown -r -t 0")
338     t.wait_reboot()
339
340
341
342 def test_dcpromo_rodc(t, vm):
343     '''test the RODC dcpromo worked'''
344     t.info("Checking the w2k8 RODC join is OK")
345     t.chdir('${PREFIX}')
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")
354
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")
363
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"])
366
367     t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
368                  [ "INBOUND NEIGHBORS",
369                    "OUTBOUND NEIGHBORS",
370                    "${BASEDN}",
371                    "Last attempt.*was successful",
372                    "CN=Configuration,${BASEDN}",
373                    "Last attempt.*was successful",
374                    "CN=Configuration,${BASEDN}",
375                    "Last attempt.*was successful" ],
376                    ordered=True,
377                    regex=True)
378
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}")
388
389
390 def prep_join_as_dc(t, vm):
391     '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
392     t.setwinvars(vm)
393     t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
394     t.chdir('${PREFIX}')
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}")
398     t.rndc_cmd('flush')
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)
402
403 def join_as_dc(t, vm):
404     '''join a windows domain as a DC'''
405     t.setwinvars(vm)
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'] )
409
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}')
413
414
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")
418     t.chdir('${PREFIX}')
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)
422
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}')
426
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"])
431
432     retries = 10
433     i = 1
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"])
437         child.expect("C:")
438         if i == 1:
439             time.sleep(2)
440         retries -=1
441
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")
450
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'])
455
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'])
461
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")
466
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}")
472
473
474 def join_as_rodc(t, vm):
475     '''join a windows domain as a RODC'''
476     t.setwinvars(vm)
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}')
483
484
485 def test_join_as_rodc(t, vm):
486     '''test a windows domain RODC join'''
487     t.info("Checking the RODC join is OK")
488     t.chdir('${PREFIX}')
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)
492
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}')
496
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"])
500
501     retries = 10
502     i = 1
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"])
506         child.expect("C:")
507         if i == 1:
508             time.sleep(2)
509         retries -=1
510
511     t.info("Checking if showrepl is happy")
512     child.sendline("repadmin /showrepl")
513     child.expect("DSA invocationID")
514
515     t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
516                  [ "INBOUND NEIGHBORS",
517                    "OUTBOUND NEIGHBORS",
518                    "${WIN_BASEDN}",
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" ],
524                    ordered=True,
525                    regex=True)
526
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'])
532
533     # should this work?
534     t.info("Checking if new users propogate to windows")
535     t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
536
537     t.info("Checking propogation of user deletion")
538     child.sendline("net user test3 /del")
539     child.expect("The command completed successfully")
540
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}")
544
545
546 def test_howto(t):
547     '''test the Samba4 howto'''
548
549     t.check_prerequesites()
550
551     # we don't need fsync safety in these tests
552     t.putenv('TDB_NO_FSYNC', '1')
553
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"):
557         t.stop_bind()
558     if not t.skip("stop_vms"):
559         t.stop_vms()
560
561     if not t.skip("build"):
562         build_s4(t)
563
564     if not t.skip("provision"):
565         provision_s4(t)
566
567     if not t.skip("create-shares"):
568         create_shares(t)
569
570     if not t.skip("starts4"):
571         start_s4(t)
572     if not t.skip("smbclient"):
573         test_smbclient(t)
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"):
577         t.start_bind()
578     if not t.skip("dns"):
579         test_dns(t)
580     if not t.skip("kerberos"):
581         test_kerberos(t)
582     if not t.skip("dyndns"):
583         test_dyndns(t)
584
585     if t.have_vm('WINDOWS7') and not t.skip("windows7"):
586         run_winjoin(t, "WINDOWS7")
587         test_winjoin(t, "WINDOWS7")
588
589     if t.have_vm('WINXP') and not t.skip("winxp"):
590         run_winjoin(t, "WINXP")
591         test_winjoin(t, "WINXP")
592
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")
597
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")
602
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")
607
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')
612         create_shares(t)
613         start_s4(t)
614         test_smbclient(t)
615         t.restart_bind(kerberos_support=True, include='{PREFIX}/private/named.conf')
616         test_dns(t)
617         test_kerberos(t)
618         test_dyndns(t)
619         run_dcpromo(t, "W2K3B")
620         test_dcpromo(t, "W2K3B")
621
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")
626         create_shares(t)
627         start_s4(t)
628         test_dyndns(t)
629         test_join_as_dc(t, "W2K8R2A")
630
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")
635         create_shares(t)
636         start_s4(t)
637         test_dyndns(t)
638         test_join_as_rodc(t, "W2K8R2A")
639
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")
644         create_shares(t)
645         start_s4(t)
646         test_dyndns(t)
647         test_join_as_dc(t, "W2K3A")
648
649     t.info("Howto test: All OK")
650
651
652 def test_cleanup(t):
653     '''cleanup after tests'''
654     t.info("Cleaning up ...")
655     t.restore_resolv_conf()
656     if getattr(t, 'bind_child', False):
657         t.bind_child.kill()
658
659
660 if __name__ == '__main__':
661     t = wintest.wintest()
662
663     t.setup("test-s4-howto.py", "source4")
664
665     try:
666         test_howto(t)
667     except:
668         if not t.opts.nocleanup:
669             test_cleanup(t)
670         raise
671
672     if not t.opts.nocleanup:
673         test_cleanup(t)
674     t.info("S4 howto test: All OK")