f1985945413f37bcae924476bf502313cfe859fc
[kai/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("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
123     child.expect("The command completed successfully")
124     child.expect("C:")
125     child.sendline("shutdown /r -t 0")
126     t.wait_reboot()
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")
130     child.expect("C:")
131
132 def test_winjoin(t, vm):
133     t.info("Checking the windows join is OK")
134     t.chdir('${PREFIX}')
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}")
145
146
147 def run_dcpromo(t, vm):
148     '''run a dcpromo on windows'''
149     t.setwinvars(vm)
150
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")
156     child.sendline('''
157 [DCINSTALL]
158 RebootOnSuccess=Yes
159 RebootOnCompletion=Yes
160 ReplicaOrNewDomain=Replica
161 ReplicaDomainDNSName=${LCREALM}
162 SiteName=Default-First-Site-Name
163 InstallDNS=No
164 ConfirmGc=Yes
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}
173 \1a
174 ''')
175     child.expect("copied.")
176     child.expect("C:")
177     child.expect("C:")
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)
180     if i == 1 or i == 2:
181         raise Exception("dcpromo failed")
182     t.wait_reboot()
183
184
185 def test_dcpromo(t, vm):
186     '''test that dcpromo worked'''
187     t.info("Checking the dcpromo join is OK")
188     t.chdir('${PREFIX}')
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"])
196
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'])
199
200     t.kinit("administrator@${REALM}", "${PASSWORD1}")
201
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"])
204
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"])
208
209     t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
210                  [ "INBOUND NEIGHBORS",
211                    "${BASEDN}",
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",
218                    "${BASEDN}",
219                    "Last success",
220                    "CN=Configuration,${BASEDN}",
221                    "Last success",
222                    "CN=Configuration,${BASEDN}",
223                    "Last success"],
224                    ordered=True,
225                    regex=True)
226
227     t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
228                  [ "INBOUND NEIGHBORS",
229                    "${BASEDN}",
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",
236                    "${BASEDN}",
237                    "Last success",
238                    "CN=Configuration,${BASEDN}",
239                    "Last success",
240                    "CN=Configuration,${BASEDN}",
241                    "Last success" ],
242                    ordered=True,
243                    regex=True)
244
245     child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
246     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
247
248     retries = 10
249     i = child.expect(["The command completed successfully", "The network path was not found"])
250     while i == 1 and retries > 0:
251         child.expect("C:")
252         time.sleep(2)
253         child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
254         i = child.expect(["The command completed successfully", "The network path was not found"])
255         retries -=1
256
257     t.run_net_time(child)
258
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")
267
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'])
272
273     t.info("Checking if new users on windows propogate to samba")
274     child.sendline("net user test3 ${PASSWORD3} /add")
275     while True:
276         i = child.expect(["The command completed successfully",
277                           "The directory service was unable to allocate a relative identifier"])
278         if i == 0:
279             break
280         time.sleep(2)
281
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'])
284
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")
289
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}")
295
296
297 def run_dcpromo_rodc(t, vm):
298     '''run a RODC dcpromo to join a windows DC to the samba domain'''
299     t.setwinvars(vm)
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")
305     child.sendline('''
306 [DCInstall]
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
317 InstallDNS=No
318 ConfirmGc=Yes
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
328 \1a
329 ''')
330     child.expect("copied.")
331     child.sendline("dcpromo /answer:answers.txt")
332     i = child.expect(["You must restart this computer", "failed"], timeout=120)
333     if i != 0:
334         raise Exception("dcpromo failed")
335     child.sendline("shutdown -r -t 0")
336     t.wait_reboot()
337
338
339
340 def test_dcpromo_rodc(t, vm):
341     '''test the RODC dcpromo worked'''
342     t.info("Checking the w2k8 RODC join is OK")
343     t.chdir('${PREFIX}')
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")
352
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")
361
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"])
364
365     t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
366                  [ "INBOUND NEIGHBORS",
367                    "OUTBOUND NEIGHBORS",
368                    "${BASEDN}",
369                    "Last attempt.*was successful",
370                    "CN=Configuration,${BASEDN}",
371                    "Last attempt.*was successful",
372                    "CN=Configuration,${BASEDN}",
373                    "Last attempt.*was successful" ],
374                    ordered=True,
375                    regex=True)
376
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}")
386
387
388 def prep_join_as_dc(t, vm):
389     '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
390     t.setwinvars(vm)
391     t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
392     t.chdir('${PREFIX}')
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}")
396     t.rndc_cmd('flush')
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)
400
401 def join_as_dc(t, vm):
402     '''join a windows domain as a DC'''
403     t.setwinvars(vm)
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'] )
407
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}')
411
412
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")
416     t.chdir('${PREFIX}')
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)
420
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}')
424
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"])
429
430     retries = 10
431     i = 1
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"])
435         child.expect("C:")
436         if i == 1:
437             time.sleep(2)
438         retries -=1
439
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")
448
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'])
453
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'])
459
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")
464
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}")
470
471
472 def join_as_rodc(t, vm):
473     '''join a windows domain as a RODC'''
474     t.setwinvars(vm)
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}')
481
482
483 def test_join_as_rodc(t, vm):
484     '''test a windows domain RODC join'''
485     t.info("Checking the RODC join is OK")
486     t.chdir('${PREFIX}')
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)
490
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}')
494
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"])
498
499     retries = 10
500     i = 1
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"])
504         child.expect("C:")
505         if i == 1:
506             time.sleep(2)
507         retries -=1
508
509     t.info("Checking if showrepl is happy")
510     child.sendline("repadmin /showrepl")
511     child.expect("DSA invocationID")
512
513     t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
514                  [ "INBOUND NEIGHBORS",
515                    "OUTBOUND NEIGHBORS",
516                    "${WIN_BASEDN}",
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" ],
522                    ordered=True,
523                    regex=True)
524
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'])
530
531     # should this work?
532     t.info("Checking if new users propogate to windows")
533     t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
534
535     t.info("Checking propogation of user deletion")
536     child.sendline("net user test3 /del")
537     child.expect("The command completed successfully")
538
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}")
542
543
544 def test_howto(t):
545     '''test the Samba4 howto'''
546
547     t.check_prerequesites()
548
549     # we don't need fsync safety in these tests
550     t.putenv('TDB_NO_FSYNC', '1')
551
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"):
555         t.stop_bind()
556     if not t.skip("stop_vms"):
557         t.stop_vms()
558
559     if not t.skip("build"):
560         build_s4(t)
561
562     if not t.skip("provision"):
563         provision_s4(t)
564
565     if not t.skip("create-shares"):
566         create_shares(t)
567
568     if not t.skip("starts4"):
569         start_s4(t)
570     if not t.skip("smbclient"):
571         test_smbclient(t)
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"):
575         t.start_bind()
576     if not t.skip("dns"):
577         test_dns(t)
578     if not t.skip("kerberos"):
579         test_kerberos(t)
580     if not t.skip("dyndns"):
581         test_dyndns(t)
582
583     if t.have_vm('WINDOWS7') and not t.skip("windows7"):
584         run_winjoin(t, "WINDOWS7")
585         test_winjoin(t, "WINDOWS7")
586
587     if t.have_vm('WINXP') and not t.skip("winxp"):
588         run_winjoin(t, "WINXP")
589         test_winjoin(t, "WINXP")
590
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")
595
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")
600
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")
605
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         run_dcpromo(t, "W2K3B")
618         test_dcpromo(t, "W2K3B")
619
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")
624         create_shares(t)
625         start_s4(t)
626         test_dyndns(t)
627         test_join_as_dc(t, "W2K8R2A")
628
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")
633         create_shares(t)
634         start_s4(t)
635         test_dyndns(t)
636         test_join_as_rodc(t, "W2K8R2A")
637
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")
642         create_shares(t)
643         start_s4(t)
644         test_dyndns(t)
645         test_join_as_dc(t, "W2K3A")
646
647     t.info("Howto test: All OK")
648
649
650 def test_cleanup(t):
651     '''cleanup after tests'''
652     t.info("Cleaning up ...")
653     t.restore_resolv_conf()
654     if getattr(t, 'bind_child', False):
655         t.bind_child.kill()
656
657
658 if __name__ == '__main__':
659     t = wintest.wintest()
660
661     t.setup("test-s4-howto.py", "source4")
662
663     try:
664         test_howto(t)
665     except:
666         if not t.opts.nocleanup:
667             test_cleanup(t)
668         raise
669
670     if not t.opts.nocleanup:
671         test_cleanup(t)
672     t.info("S4 howto test: All OK")