s4:torture:rpc: fix a comment typo in samba3.smb2-reauth2
[Samba.git] / wintest / test-s3.py
blob9539122e3afcaf0806e7d4afa0712fdbae2e78b9
1 #!/usr/bin/env python
3 '''automated testing of Samba3 against windows'''
5 import sys, os
6 import optparse
7 import wintest
9 def set_libpath(t):
10 t.putenv("LD_LIBRARY_PATH", "${PREFIX}/lib")
12 def set_krb5_conf(t):
13 t.run_cmd("mkdir -p ${PREFIX}/etc")
14 t.write_file("${PREFIX}/etc/krb5.conf",
15 '''[libdefaults]
16 dns_lookup_realm = false
17 dns_lookup_kdc = true''')
19 t.putenv("KRB5_CONFIG", '${PREFIX}/etc/krb5.conf')
21 def build_s3(t):
22 '''build samba3'''
23 t.info('Building s3')
24 t.chdir('${SOURCETREE}/source3')
25 t.putenv('CC', 'ccache gcc')
26 t.run_cmd("./autogen.sh")
27 t.run_cmd("./configure -C --prefix=${PREFIX} --enable-developer")
28 t.run_cmd('make basics')
29 t.run_cmd('make -j4')
30 t.run_cmd('rm -rf ${PREFIX}')
31 t.run_cmd('make install')
33 def start_s3(t):
34 t.info('Starting Samba3')
35 t.chdir("${PREFIX}")
36 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
37 t.run_cmd("rm -f var/locks/*.pid")
38 t.run_cmd(['sbin/nmbd', "-D"])
39 t.run_cmd(['sbin/winbindd', "-D"])
40 t.run_cmd(['sbin/smbd', "-D"])
41 t.port_wait("${INTERFACE_IP}", 139)
43 def test_wbinfo(t):
44 t.info('Testing wbinfo')
45 t.chdir('${PREFIX}')
46 t.cmd_contains("bin/wbinfo --version", ["Version 4."])
47 t.cmd_contains("bin/wbinfo -p", ["Ping to winbindd succeeded"])
48 t.retry_cmd("bin/wbinfo --online-status",
49 ["BUILTIN : online",
50 "${HOSTNAME} : online",
51 "${WIN_DOMAIN} : online"],
52 casefold=True)
53 t.cmd_contains("bin/wbinfo -u",
54 ["${WIN_DOMAIN}/administrator",
55 "${WIN_DOMAIN}/krbtgt" ],
56 casefold=True)
57 t.cmd_contains("bin/wbinfo -g",
58 ["${WIN_DOMAIN}/domain users",
59 "${WIN_DOMAIN}/domain guests",
60 "${WIN_DOMAIN}/domain admins"],
61 casefold=True)
62 t.cmd_contains("bin/wbinfo --name-to-sid administrator",
63 "S-1-5-.*-500 SID_USER .1",
64 regex=True)
65 t.cmd_contains("bin/wbinfo --name-to-sid 'domain users'",
66 "S-1-5-.*-513 SID_DOM_GROUP .2",
67 regex=True)
69 t.retry_cmd("bin/wbinfo --authenticate=${WIN_DOMAIN}/administrator%${WIN_PASS}",
70 ["plaintext password authentication succeeded",
71 "challenge/response password authentication succeeded"])
73 t.retry_cmd("bin/wbinfo --krb5auth=${WIN_DOMAIN}/administrator%${WIN_PASS}",
74 ["succeeded"])
77 def test_smbclient(t):
78 t.info('Testing smbclient')
79 t.chdir('${PREFIX}')
80 t.cmd_contains("bin/smbclient --version", ["Version 4."])
81 t.cmd_contains('bin/smbclient -L ${INTERFACE_IP} -U%', ["Domain=[${WIN_DOMAIN}]", "test", "IPC$", "Samba 4."],
82 casefold=True)
83 child = t.pexpect_spawn('bin/smbclient //${HOSTNAME}.${WIN_REALM}/test -Uroot@${WIN_REALM}%${PASSWORD2}')
84 child.expect("smb:")
85 child.sendline("dir")
86 child.expect("blocks available")
87 child.sendline("mkdir testdir")
88 child.expect("smb:")
89 child.sendline("cd testdir")
90 child.expect('testdir')
91 child.sendline("cd ..")
92 child.sendline("rmdir testdir")
94 child = t.pexpect_spawn('bin/smbclient //${HOSTNAME}.${WIN_REALM}/test -Uroot@${WIN_REALM}%${PASSWORD2} -k')
95 child.expect("smb:")
96 child.sendline("dir")
97 child.expect("blocks available")
98 child.sendline("mkdir testdir")
99 child.expect("smb:")
100 child.sendline("cd testdir")
101 child.expect('testdir')
102 child.sendline("cd ..")
103 child.sendline("rmdir testdir")
105 def create_shares(t):
106 t.info("Adding test shares")
107 t.chdir('${PREFIX}')
108 t.write_file("etc/smb.conf", '''
109 [test]
110 path = ${PREFIX}/test
111 read only = no
112 ''',
113 mode='a')
114 t.run_cmd("mkdir -p test")
117 def prep_join_as_member(t, vm):
118 '''prepare to join a windows domain as a member server'''
119 t.setwinvars(vm)
120 t.info("Starting VMs for joining ${WIN_VM} as a member using net ads join")
121 t.chdir('${PREFIX}')
122 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
123 t.vm_poweroff("${WIN_VM}", checkfail=False)
124 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
125 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
126 t.get_ipconfig(child)
127 t.del_files(["var", "private"])
128 t.write_file("etc/smb.conf", '''
129 [global]
130 netbios name = ${HOSTNAME}
131 log level = ${DEBUGLEVEL}
132 realm = ${WIN_REALM}
133 workgroup = ${WIN_DOMAIN}
134 security = ADS
135 bind interfaces only = yes
136 interfaces = ${INTERFACE}
137 winbind separator = /
138 idmap uid = 1000000-2000000
139 idmap gid = 1000000-2000000
140 winbind enum users = yes
141 winbind enum groups = yes
142 max protocol = SMB2
143 map hidden = no
144 map system = no
145 ea support = yes
146 panic action = xterm -e gdb --pid %d
147 ''')
149 def join_as_member(t, vm):
150 '''join a windows domain as a member server'''
151 t.setwinvars(vm)
152 t.info("Joining ${WIN_VM} as a member using net ads join")
153 t.port_wait("${WIN_IP}", 389)
154 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
155 t.cmd_contains("bin/net ads join -Uadministrator%${WIN_PASS}", ["Joined"])
156 t.cmd_contains("bin/net ads testjoin", ["Join is OK"])
157 t.cmd_contains("bin/net ads dns register ${HOSTNAME}.${WIN_REALM} -P", ["Successfully registered hostname with DNS"])
158 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}",
159 ['${HOSTNAME}.${WIN_REALM} has address'])
161 def create_root_account(t, vm):
162 t.setwinvars(vm)
163 t.info("Creating 'root' account for testing Samba3 member server")
164 t.chdir('${PREFIX}')
165 t.run_cmd('bin/net ads user add root -Uadministrator%${WIN_PASS}')
166 child = t.pexpect_spawn('bin/net ads password root -Uadministrator%${WIN_PASS}')
167 child.expect("Enter new password for root")
168 child.sendline("${PASSWORD2}")
169 child.expect("Password change for ");
170 child.expect(" completed")
171 child = t.pexpect_spawn('bin/net rpc shell -S ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}')
172 child.expect("net rpc>")
173 child.sendline("user edit disabled root no")
174 child.expect("Set root's disabled flag")
176 def test_join_as_member(t, vm):
177 '''test the domain join'''
178 t.setwinvars(vm)
179 t.info('Testing join as member')
180 t.chdir('${PREFIX}')
181 test_wbinfo(t)
182 test_smbclient(t)
185 def test_s3(t):
186 '''basic s3 testing'''
188 t.setvar("SAMBA_VERSION", "Version 4")
189 t.check_prerequesites()
190 set_libpath(t)
192 if not t.skip("configure_bind"):
193 t.configure_bind()
194 if not t.skip("stop_bind"):
195 t.stop_bind()
196 if not t.skip("stop_vms"):
197 t.stop_vms()
199 if not t.skip("build"):
200 build_s3(t)
202 set_krb5_conf(t)
203 if not t.skip("configure_bind2"):
204 t.configure_bind()
205 if not t.skip("start_bind"):
206 t.start_bind()
208 dc_started = False
209 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
210 t.start_winvm('W2K8R2A')
211 dc_started = True
212 prep_join_as_member(t, "W2K8R2A")
213 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
214 join_as_member(t, "W2K8R2A")
215 create_shares(t)
216 start_s3(t)
217 create_root_account(t, "W2K8R2A")
218 test_join_as_member(t, "W2K8R2A")
220 if t.have_var('WINDOWS7_VM') and t.have_var('W2K8R2A_VM') and not t.skip("join_windows7_2008r2"):
221 if not dc_started:
222 t.start_winvm('W2K8R2A')
223 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
224 dc_started = True
225 else:
226 t.setwinvars('W2K8R2A')
227 realm = t.getvar("WIN_REALM")
228 dom_username = t.getvar("WIN_USER")
229 dom_password = t.getvar("WIN_PASS")
230 dom_realm = t.getvar("WIN_REALM")
231 t.start_winvm('WINDOWS7')
232 t.test_remote_smbclient("WINDOWS7")
233 t.run_winjoin('WINDOWS7', realm, username=dom_username, password=dom_password)
234 t.test_remote_smbclient("WINDOWS7", dom_username, dom_password)
235 t.test_remote_smbclient('WINDOWS7', dom_username, dom_password, args='--option=clientntlmv2auth=no')
236 t.test_remote_smbclient('WINDOWS7', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k")
237 t.test_remote_smbclient('WINDOWS7', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k --option=clientusespnegoprincipal=yes")
238 t.test_net_use('WINDOWS7', dom_realm, t.getvar("W2K8R2A_DOMAIN"), 'root', '${PASSWORD2}')
240 if t.have_var('WINXP_VM') and t.have_var('W2K8R2A_VM') and not t.skip("join_winxp_2008r2"):
241 if not dc_started:
242 t.start_winvm('W2K8R2A')
243 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
244 dc_started = True
245 else:
246 t.setwinvars('W2K8R2A')
247 realm = t.getvar("WIN_REALM")
248 dom_username = t.getvar("WIN_USER")
249 dom_password = t.getvar("WIN_PASS")
250 dom_realm = t.getvar("WIN_REALM")
251 t.start_winvm('WINXP')
252 t.run_winjoin('WINXP', realm, username=dom_username, password=dom_password)
253 t.test_remote_smbclient('WINXP', dom_username, dom_password)
254 t.test_remote_smbclient('WINXP', dom_username, dom_password, args='--option=clientntlmv2auth=no')
255 t.test_remote_smbclient('WINXP', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k")
256 t.test_remote_smbclient('WINXP', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k --clientusespnegoprincipal=yes")
257 t.test_net_use('WINXP', dom_realm, t.getvar("W2K8R2A_DOMAIN"), 'root', '${PASSWORD2}')
259 t.info("S3 test: All OK")
262 def test_cleanup(t):
263 '''cleanup after tests'''
264 t.info("Cleaning up ...")
265 t.restore_resolv_conf()
266 if getattr(t, 'bind_child', False):
267 t.bind_child.kill()
270 if __name__ == '__main__':
271 t = wintest.wintest()
273 t.setup("test-s3.py", "source3")
275 try:
276 test_s3(t)
277 except:
278 if not t.opts.nocleanup:
279 test_cleanup(t)
280 raise
282 if not t.opts.nocleanup:
283 test_cleanup(t)
284 t.info("S3 test: All OK")