wintest Add automatic dcpromo is the host isn't a DC yet
[Samba/gebeck_regimport.git] / wintest / test-s4-howto.py
blob48634da7bb18b0049f2de05bbe72faff624d1edc
1 #!/usr/bin/env python
3 '''automated testing of the steps of the Samba4 HOWTO'''
5 import sys, os
6 import optparse
7 import wintest, pexpect
9 def check_prerequesites(t):
10 t.info("Checking prerequesites")
11 t.setvar('HOSTNAME', t.cmd_output("hostname -s").strip())
12 if os.getuid() != 0:
13 raise Exception("You must run this script as root")
14 t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
15 t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_NET} up')
16 if t.getvar('INTERFACE_IPV6'):
17 t.run_cmd('ifconfig ${INTERFACE} inet6 del ${INTERFACE_IPV6}/64', checkfail=False)
18 t.run_cmd('ifconfig ${INTERFACE} inet6 add ${INTERFACE_IPV6}/64 up')
21 def build_s4(t):
22 '''build samba4'''
23 t.info('Building s4')
24 t.chdir('${SOURCETREE}/source4')
25 t.putenv('CC', 'ccache gcc')
26 t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
27 t.run_cmd('make -j')
28 t.run_cmd('rm -rf ${PREFIX}')
29 t.run_cmd('make -j install')
32 def provision_s4(t, func_level="2008"):
33 '''provision s4 as a DC'''
34 t.info('Provisioning s4')
35 t.chdir('${PREFIX}')
36 t.del_files(["var", "private"])
37 t.run_cmd("rm -f etc/smb.conf")
38 provision=['sbin/provision',
39 '--realm=${LCREALM}',
40 '--domain=${DOMAIN}',
41 '--adminpass=${PASSWORD1}',
42 '--server-role=domain controller',
43 '--function-level=%s' % func_level,
44 '-d${DEBUGLEVEL}',
45 '--option=interfaces=${INTERFACE}',
46 '--host-ip=${INTERFACE_IP}',
47 '--option=bind interfaces only=yes',
48 '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
49 if t.getvar('INTERFACE_IPV6'):
50 provision.append('--host-ip6=${INTERFACE_IPV6}')
51 t.run_cmd(provision)
52 t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
53 t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
54 t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
57 def start_s4(t):
58 '''startup samba4'''
59 t.info('Starting Samba4')
60 t.chdir("${PREFIX}")
61 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
62 t.run_cmd(['sbin/samba',
63 '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
64 t.port_wait("${INTERFACE_IP}", 139)
66 def test_smbclient(t):
67 '''test smbclient'''
68 t.info('Testing smbclient')
69 t.chdir('${PREFIX}')
70 t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
71 t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
72 child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
73 child.expect("smb:")
74 child.sendline("dir")
75 child.expect("blocks available")
76 child.sendline("mkdir testdir")
77 child.expect("smb:")
78 child.sendline("cd testdir")
79 child.expect('testdir')
80 child.sendline("cd ..")
81 child.sendline("rmdir testdir")
84 def create_shares(t):
85 '''create some test shares'''
86 t.info("Adding test shares")
87 t.chdir('${PREFIX}')
88 t.write_file("etc/smb.conf", '''
89 [test]
90 path = ${PREFIX}/test
91 read only = no
92 [profiles]
93 path = ${PREFIX}/var/profiles
94 read only = no
95 ''',
96 mode='a')
97 t.run_cmd("mkdir -p test")
98 t.run_cmd("mkdir -p var/profiles")
101 def set_nameserver(t, nameserver):
102 '''set the nameserver in resolv.conf'''
103 t.write_file("/etc/resolv.conf.wintest", '''
104 # Generated by wintest, the Samba v Windows automated testing system
105 nameserver %s
107 # your original resolv.conf appears below:
108 ''' % t.substitute(nameserver))
109 child = t.pexpect_spawn("cat /etc/resolv.conf", crlf=False)
110 i = child.expect(['your original resolv.conf appears below:', pexpect.EOF])
111 if i == 0:
112 child.expect(pexpect.EOF)
113 contents = child.before.lstrip().replace('\r', '')
114 t.write_file('/etc/resolv.conf.wintest', contents, mode='a')
115 t.write_file('/etc/resolv.conf.wintest-bak', contents)
116 t.run_cmd("mv -f /etc/resolv.conf.wintest /etc/resolv.conf")
117 t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
120 def restore_resolv_conf(t):
121 '''restore the /etc/resolv.conf after testing is complete'''
122 if getattr(t, 'resolv_conf_backup', False):
123 t.info("restoring /etc/resolv.conf")
124 t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
126 def rndc_cmd(t, cmd, checkfail=True):
127 '''run a rndc command'''
128 t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
131 def restart_bind(t):
132 '''restart the test environment version of bind'''
133 t.info("Restarting bind9")
134 t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
135 t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
136 t.chdir('${PREFIX}')
137 t.run_cmd("mkdir -p var/named/data")
138 t.run_cmd("chown -R ${BIND_USER} var/named")
140 nameserver = t.get_nameserver()
141 if nameserver == t.getvar('INTERFACE_IP'):
142 raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
143 t.setvar('DNSSERVER', nameserver)
145 if t.getvar('INTERFACE_IPV6'):
146 ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
147 else:
148 ipv6_listen = ''
149 t.setvar('BIND_LISTEN_IPV6', ipv6_listen)
151 t.write_file("etc/named.conf", '''
152 options {
153 listen-on port 53 { ${INTERFACE_IP}; };
154 ${BIND_LISTEN_IPV6}
155 directory "${PREFIX}/var/named";
156 dump-file "${PREFIX}/var/named/data/cache_dump.db";
157 pid-file "${PREFIX}/var/named/named.pid";
158 statistics-file "${PREFIX}/var/named/data/named_stats.txt";
159 memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
160 allow-query { any; };
161 recursion yes;
162 tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
163 tkey-domain "${REALM}";
164 max-cache-ttl 10;
165 max-ncache-ttl 10;
167 forward only;
168 forwarders {
169 ${DNSSERVER};
174 key "rndc-key" {
175 algorithm hmac-md5;
176 secret "lA/cTrno03mt5Ju17ybEYw==";
179 controls {
180 inet ${INTERFACE_IP} port 953
181 allow { any; } keys { "rndc-key"; };
184 include "${PREFIX}/private/named.conf";
185 ''')
187 # add forwarding for the windows domains
188 domains = t.get_domains()
189 for d in domains:
190 t.write_file('etc/named.conf',
192 zone "%s" IN {
193 type forward;
194 forward only;
195 forwarders {
199 ''' % (d, domains[d]),
200 mode='a')
203 t.write_file("etc/rndc.conf", '''
204 # Start of rndc.conf
205 key "rndc-key" {
206 algorithm hmac-md5;
207 secret "lA/cTrno03mt5Ju17ybEYw==";
210 options {
211 default-key "rndc-key";
212 default-server ${INTERFACE_IP};
213 default-port 953;
215 ''')
217 set_nameserver(t, t.getvar('INTERFACE_IP'))
219 rndc_cmd(t, "stop", checkfail=False)
220 t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
221 t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
223 t.port_wait("${INTERFACE_IP}", 53)
224 rndc_cmd(t, "flush")
227 def test_dns(t):
228 '''test that DNS is OK'''
229 t.info("Testing DNS")
230 t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
231 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
232 t.cmd_contains("host -t SRV _kerberos._udp.${LCREALM}.",
233 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
234 t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
235 ['${HOSTNAME}.${LCREALM} has address'])
237 def test_kerberos(t):
238 '''test that kerberos is OK'''
239 t.info("Testing kerberos")
240 t.run_cmd("kdestroy")
241 t.kinit("administrator@${REALM}", "${PASSWORD1}")
242 # this copes with the differences between MIT and Heimdal klist
243 t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
246 def test_dyndns(t):
247 '''test that dynamic DNS is working'''
248 t.chdir('${PREFIX}')
249 t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
250 rndc_cmd(t, "flush")
253 def run_winjoin(t, vm):
254 '''join a windows box to our domain'''
255 t.setwinvars(vm)
257 t.info("Joining a windows box to the domain")
258 t.vm_poweroff("${WIN_VM}", checkfail=False)
259 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
260 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
261 child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
262 child.expect("The command completed successfully")
263 child.expect("C:")
264 child.sendline("shutdown /r -t 0")
265 t.wait_reboot()
266 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
267 child.sendline("ipconfig /registerdns")
268 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")
269 child.expect("C:")
271 def test_winjoin(t, vm):
272 t.info("Checking the windows join is OK")
273 t.chdir('${PREFIX}')
274 t.port_wait("${WIN_IP}", 139)
275 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
276 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
277 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
278 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
279 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
280 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
281 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
282 child.expect("The command completed successfully")
283 t.vm_poweroff("${WIN_VM}")
286 def run_dcpromo(t, vm):
287 '''run a dcpromo on windows'''
288 t.setwinvars(vm)
290 t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
291 t.vm_poweroff("${WIN_VM}", checkfail=False)
292 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
293 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
294 child.sendline("copy /Y con answers.txt")
295 child.sendline('''
296 [DCINSTALL]
297 RebootOnSuccess=Yes
298 RebootOnCompletion=Yes
299 ReplicaOrNewDomain=Replica
300 ReplicaDomainDNSName=${LCREALM}
301 SiteName=Default-First-Site-Name
302 InstallDNS=No
303 ConfirmGc=Yes
304 CreateDNSDelegation=No
305 UserDomain=${LCREALM}
306 UserName=${LCREALM}\\administrator
307 Password=${PASSWORD1}
308 DatabasePath="C:\Windows\NTDS"
309 LogPath="C:\Windows\NTDS"
310 SYSVOLPath="C:\Windows\SYSVOL"
311 SafeModeAdminPassword=${PASSWORD1}
312 \x1a
313 ''')
314 child.expect("copied.")
315 child.expect("C:")
316 child.expect("C:")
317 child.sendline("dcpromo /answer:answers.txt")
318 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
319 if i == 1 or i == 2:
320 raise Exception("dcpromo failed")
321 t.wait_reboot()
324 def test_dcpromo(t, vm):
325 '''test that dcpromo worked'''
326 t.info("Checking the dcpromo join is OK")
327 t.chdir('${PREFIX}')
328 t.port_wait("${WIN_IP}", 139)
329 t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
330 ['${WIN_HOSTNAME}.${LCREALM} has address'],
331 retries=30, delay=10, casefold=True)
332 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
333 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
334 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
336 t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
337 t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
339 t.kinit("administrator@${REALM}", "${PASSWORD1}")
341 # the first replication will transfer the dnsHostname attribute
342 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
344 for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
345 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
346 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
348 t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
349 [ "INBOUND NEIGHBORS",
350 "${BASEDN}",
351 "Last attempt .* was successful",
352 "CN=Configuration,${BASEDN}",
353 "Last attempt .* was successful",
354 "CN=Configuration,${BASEDN}", # cope with either order
355 "Last attempt .* was successful",
356 "OUTBOUND NEIGHBORS",
357 "${BASEDN}",
358 "Last success",
359 "CN=Configuration,${BASEDN}",
360 "Last success",
361 "CN=Configuration,${BASEDN}",
362 "Last success"],
363 ordered=True,
364 regex=True)
366 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
367 [ "INBOUND 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 "OUTBOUND NEIGHBORS",
375 "${BASEDN}",
376 "Last success",
377 "CN=Configuration,${BASEDN}",
378 "Last success",
379 "CN=Configuration,${BASEDN}",
380 "Last success" ],
381 ordered=True,
382 regex=True)
384 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
385 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
386 child.expect("The command completed successfully")
388 t.run_net_time(child)
390 t.info("Checking if showrepl is happy")
391 child.sendline("repadmin /showrepl")
392 child.expect("${BASEDN}")
393 child.expect("was successful")
394 child.expect("CN=Configuration,${BASEDN}")
395 child.expect("was successful")
396 child.expect("CN=Schema,CN=Configuration,${BASEDN}")
397 child.expect("was successful")
399 t.info("Checking if new users propogate to windows")
400 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
401 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
402 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
404 t.info("Checking if new users on windows propogate to samba")
405 child.sendline("net user test3 ${PASSWORD3} /add")
406 while True:
407 i = child.expect(["The command completed successfully",
408 "The directory service was unable to allocate a relative identifier"])
409 if i == 0:
410 break
411 time.sleep(2)
413 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
414 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
416 t.info("Checking propogation of user deletion")
417 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
418 child.sendline("net user test3 /del")
419 child.expect("The command completed successfully")
421 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
422 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
423 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
424 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
425 t.vm_poweroff("${WIN_VM}")
428 def run_dcpromo_rodc(t, vm):
429 '''run a RODC dcpromo to join a windows DC to the samba domain'''
430 t.setwinvars(vm)
431 t.info("Joining a w2k8 box to the domain as a RODC")
432 t.vm_poweroff("${WIN_VM}", checkfail=False)
433 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
434 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
435 child.sendline("copy /Y con answers.txt")
436 child.sendline('''
437 [DCInstall]
438 ReplicaOrNewDomain=ReadOnlyReplica
439 ReplicaDomainDNSName=${LCREALM}
440 PasswordReplicationDenied="BUILTIN\Administrators"
441 PasswordReplicationDenied="BUILTIN\Server Operators"
442 PasswordReplicationDenied="BUILTIN\Backup Operators"
443 PasswordReplicationDenied="BUILTIN\Account Operators"
444 PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
445 PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
446 DelegatedAdmin="${DOMAIN}\\Administrator"
447 SiteName=Default-First-Site-Name
448 InstallDNS=No
449 ConfirmGc=Yes
450 CreateDNSDelegation=No
451 UserDomain=${LCREALM}
452 UserName=${LCREALM}\\administrator
453 Password=${PASSWORD1}
454 DatabasePath="C:\Windows\NTDS"
455 LogPath="C:\Windows\NTDS"
456 SYSVOLPath="C:\Windows\SYSVOL"
457 SafeModeAdminPassword=${PASSWORD1}
458 RebootOnCompletion=No
459 \x1a
460 ''')
461 child.expect("copied.")
462 child.sendline("dcpromo /answer:answers.txt")
463 i = child.expect(["You must restart this computer", "failed"], timeout=120)
464 if i != 0:
465 raise Exception("dcpromo failed")
466 child.sendline("shutdown -r -t 0")
467 t.wait_reboot()
471 def test_dcpromo_rodc(t, vm):
472 '''test the RODC dcpromo worked'''
473 t.info("Checking the w2k8 RODC join is OK")
474 t.chdir('${PREFIX}')
475 t.port_wait("${WIN_IP}", 139)
476 t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
477 t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
478 t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
479 child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
480 child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
481 child.expect("The command completed successfully")
483 t.info("Checking if showrepl is happy")
484 child.sendline("repadmin /showrepl")
485 child.expect("${BASEDN}")
486 child.expect("was successful")
487 child.expect("CN=Configuration,${BASEDN}")
488 child.expect("was successful")
489 child.expect("CN=Configuration,${BASEDN}")
490 child.expect("was successful")
492 t.info("Checking if new users are available on windows")
493 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
494 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
495 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
496 t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN} -k yes", ["was successful"])
497 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
498 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
499 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
500 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
501 t.vm_poweroff("${WIN_VM}")
504 def prep_join_as_dc(t, vm):
505 '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
506 t.setwinvars(vm)
507 t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
508 t.chdir('${PREFIX}')
509 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
510 t.vm_poweroff("${WIN_VM}", checkfail=False)
511 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
512 rndc_cmd(t, 'flush')
513 t.run_cmd("rm -rf etc/smb.conf private")
514 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
515 t.get_ipconfig(child)
517 def join_as_dc(t, vm):
518 '''join a windows domain as a DC'''
519 t.setwinvars(vm)
520 t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
521 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
522 t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
523 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
526 def test_join_as_dc(t, vm):
527 '''test the join of a windows domain as a DC'''
528 t.info("Checking the DC join is OK")
529 t.chdir('${PREFIX}')
530 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
531 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
532 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
534 t.info("Forcing kcc runs, and replication")
535 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
536 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
538 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
539 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
540 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
541 t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
543 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
544 child.expect("The command completed successfully")
546 t.info("Checking if showrepl is happy")
547 child.sendline("repadmin /showrepl")
548 child.expect("${WIN_BASEDN}")
549 child.expect("was successful")
550 child.expect("CN=Configuration,${WIN_BASEDN}")
551 child.expect("was successful")
552 child.expect("CN=Configuration,${WIN_BASEDN}")
553 child.expect("was successful")
555 t.info("Checking if new users propogate to windows")
556 t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
557 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
558 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
560 t.info("Checking if new users on windows propogate to samba")
561 child.sendline("net user test3 ${PASSWORD3} /add")
562 child.expect("The command completed successfully")
563 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
564 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
566 t.info("Checking propogation of user deletion")
567 t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
568 child.sendline("net user test3 /del")
569 child.expect("The command completed successfully")
571 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
572 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
573 t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
574 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
575 t.vm_poweroff("${WIN_VM}")
578 def join_as_rodc(t, vm):
579 '''join a windows domain as a RODC'''
580 t.setwinvars(vm)
581 t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
582 t.chdir('${PREFIX}')
583 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
584 t.vm_poweroff("${WIN_VM}", checkfail=False)
585 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
586 rndc_cmd(t, 'flush')
587 t.run_cmd("rm -rf etc/smb.conf private")
588 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
589 t.get_ipconfig(child)
590 t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
591 t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
592 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
595 def test_join_as_rodc(t, vm):
596 '''test a windows domain RODC join'''
597 t.info("Checking the RODC join is OK")
598 t.chdir('${PREFIX}')
599 t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
600 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
601 child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
603 t.info("Forcing kcc runs, and replication")
604 t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
605 t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
607 t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
608 for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
609 t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
611 child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
612 child.expect("The command completed successfully")
614 t.info("Checking if showrepl is happy")
615 child.sendline("repadmin /showrepl")
616 child.expect("DSA invocationID")
618 t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
619 [ "INBOUND NEIGHBORS",
620 "OUTBOUND NEIGHBORS",
621 "${WIN_BASEDN}",
622 "Last attempt .* was successful",
623 "CN=Configuration,${WIN_BASEDN}",
624 "Last attempt .* was successful",
625 "CN=Configuration,${WIN_BASEDN}",
626 "Last attempt .* was successful" ],
627 ordered=True,
628 regex=True)
630 t.info("Checking if new users on windows propogate to samba")
631 child.sendline("net user test3 ${PASSWORD3} /add")
632 child.expect("The command completed successfully")
633 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
634 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
636 # should this work?
637 t.info("Checking if new users propogate to windows")
638 t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
640 t.info("Checking propogation of user deletion")
641 child.sendline("net user test3 /del")
642 child.expect("The command completed successfully")
644 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
645 t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
646 t.vm_poweroff("${WIN_VM}")
649 def run_dcpromo_as_first_dc(t, vm, func_level=None):
650 t.setwinvars(vm)
651 t.info("Configuring a windows VM ${WIN_VM} at the first DC in the domain using dcpromo")
652 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
653 child.sendline("dcdiag");
654 if t.get_is_dc(child):
655 return
657 if func_level == '2008r2':
658 t.setvar("FUNCTION_LEVEL_INT", str(4))
659 elif func_level == '2003':
660 t.setvar("FUNCTION_LEVEL_INT", str(1))
661 else:
662 t.setvar("FUNCTION_LEVEL_INT", str(0))
664 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
665 child.sendline("dcdiag");
667 """This server must therefore not yet be a directory server, so we must promote it"""
668 child.sendline("copy /Y con answers.txt")
669 child.sendline('''
670 [DCInstall]
671 ; New forest promotion
672 ReplicaOrNewDomain=Domain
673 NewDomain=Forest
674 NewDomainDNSName=${WIN_REALM}
675 ForestLevel=${FUNCTION_LEVEL_INT}
676 DomainNetbiosName=${WIN_DOMAIN}
677 DomainLevel=${FUNCTION_LEVEL_INT}
678 InstallDNS=Yes
679 ConfirmGc=Yes
680 CreateDNSDelegation=No
681 DatabasePath="C:\Windows\NTDS"
682 LogPath="C:\Windows\NTDS"
683 SYSVOLPath="C:\Windows\SYSVOL"
684 ; Set SafeModeAdminPassword to the correct value prior to using the unattend file
685 SafeModeAdminPassword=${WIN_PASS}
686 ; Run-time flags (optional)
687 RebootOnCompletion=No
688 \x1a
689 ''')
690 child.expect("copied.")
691 child.expect("C:")
692 child.expect("C:")
693 child.sendline("dcpromo /answer:answers.txt")
694 i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
695 if i == 1 or i == 2:
696 raise Exception("dcpromo failed")
697 child.sendline("shutdown -r -t 0")
698 t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
699 t.port_wait("${WIN_IP}", 139)
701 def test_howto(t):
702 '''test the Samba4 howto'''
704 check_prerequesites(t)
706 # we don't need fsync safety in these tests
707 t.putenv('TDB_NO_FSYNC', '1')
709 if not t.skip("build"):
710 build_s4(t)
712 if not t.skip("provision"):
713 provision_s4(t)
715 if not t.skip("create-shares"):
716 create_shares(t)
718 if not t.skip("starts4"):
719 start_s4(t)
720 if not t.skip("smbclient"):
721 test_smbclient(t)
722 if not t.skip("startbind"):
723 restart_bind(t)
724 if not t.skip("dns"):
725 test_dns(t)
726 if not t.skip("kerberos"):
727 test_kerberos(t)
728 if not t.skip("dyndns"):
729 test_dyndns(t)
731 if t.have_vm('WINDOWS7') and not t.skip("windows7"):
732 run_winjoin(t, "WINDOWS7")
733 test_winjoin(t, "WINDOWS7")
735 if t.have_vm('WINXP') and not t.skip("winxp"):
736 run_winjoin(t, "WINXP")
737 test_winjoin(t, "WINXP")
739 if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
740 t.info("Testing w2k8r2 RODC dcpromo")
741 run_dcpromo_rodc(t, "W2K8R2C")
742 test_dcpromo_rodc(t, "W2K8R2C")
744 if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
745 t.info("Testing w2k8r2 dcpromo")
746 run_dcpromo(t, "W2K8R2B")
747 test_dcpromo(t, "W2K8R2B")
749 if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
750 t.info("Testing w2k8 dcpromo")
751 run_dcpromo(t, "W2K8B")
752 test_dcpromo(t, "W2K8B")
754 if t.have_vm('W2K3B') and not t.skip("dcpromo_w2k3"):
755 t.info("Testing w2k3 dcpromo")
756 t.info("Changing to 2003 functional level")
757 provision_s4(t, func_level='2003')
758 create_shares(t)
759 start_s4(t)
760 test_smbclient(t)
761 restart_bind(t)
762 test_dns(t)
763 test_kerberos(t)
764 test_dyndns(t)
765 run_dcpromo(t, "W2K3B")
766 test_dcpromo(t, "W2K3B")
768 if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
769 prep_join_as_dc(t, "W2K8R2A")
770 run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
771 join_as_dc(t, "W2K8R2A")
772 create_shares(t)
773 start_s4(t)
774 test_dyndns(t)
775 test_join_as_dc(t, "W2K8R2A")
777 if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
778 prep_join_as_rodc(t, "W2K8R2A")
779 run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
780 join_as_rodc(t, "W2K8R2A")
781 create_shares(t)
782 start_s4(t)
783 test_dyndns(t)
784 test_join_as_rodc(t, "W2K8R2A")
786 if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
787 prep_join_as_dc(t, "W2K3A")
788 run_dcpromo_as_first_dc(t, "W2K3A", func_level='2003')
789 join_as_dc(t, "W2K3A")
790 create_shares(t)
791 start_s4(t)
792 test_dyndns(t)
793 test_join_as_dc(t, "W2K3A")
795 t.info("Howto test: All OK")
798 def test_cleanup(t):
799 '''cleanup after tests'''
800 t.info("Cleaning up ...")
801 restore_resolv_conf(t)
802 if getattr(t, 'bind_child', False):
803 t.bind_child.kill()
806 if __name__ == '__main__':
807 parser = optparse.OptionParser("test-howto.py")
808 parser.add_option("--conf", type='string', default='', help='config file')
809 parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
810 parser.add_option("--vms", type='string', default='', help='list of VMs to use (comma separated)')
811 parser.add_option("--list", action='store_true', default=False, help='list the available steps')
812 parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
813 parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
814 parser.add_option("--prefix", type='string', default=None, help='override install prefix')
815 parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
816 parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
818 opts, args = parser.parse_args()
820 if not opts.conf:
821 print("Please specify a config file with --conf")
822 sys.exit(1)
824 t = wintest.wintest()
825 t.load_config(opts.conf)
827 t.set_skip(opts.skip)
828 t.set_vms(opts.vms)
830 if opts.list:
831 t.list_steps_mode()
833 if opts.prefix:
834 t.setvar('PREFIX', opts.prefix)
836 if opts.sourcetree:
837 t.setvar('SOURCETREE', opts.sourcetree)
839 if opts.rebase:
840 t.info('rebasing')
841 t.chdir('${SOURCETREE}')
842 t.run_cmd('git pull --rebase')
844 if opts.clean:
845 t.info('rebasing')
846 t.chdir('${SOURCETREE}/source4')
847 t.run_cmd('rm -rf bin')
849 try:
850 test_howto(t)
851 except:
852 if not opts.nocleanup:
853 test_cleanup(t)
854 raise
856 if not opts.nocleanup:
857 test_cleanup(t)
858 t.info("S4 howto test: All OK")