s3:lib: make use of samba_tevent_context_init()
[Samba/gebeck_regimport.git] / wintest / test-s3.py
blobe6dbfc75f1f57c1cacc99c6c1219cc8ee0aaea3b
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 smbclient = t.getvar("smbclient")
80 t.chdir('${PREFIX}')
81 t.cmd_contains("%s --version" % (smbclient), ["Version 4."])
82 t.cmd_contains('%s -L ${INTERFACE_IP} -U%%' % (smbclient), ["Domain=[${WIN_DOMAIN}]", "test", "IPC$", "Samba 4."],
83 casefold=True)
84 child = t.pexpect_spawn('%s //${HOSTNAME}.${WIN_REALM}/test -Uroot@${WIN_REALM}%%${PASSWORD2}' % (smbclient))
85 child.expect("smb:")
86 child.sendline("dir")
87 child.expect("blocks available")
88 child.sendline("mkdir testdir")
89 child.expect("smb:")
90 child.sendline("cd testdir")
91 child.expect('testdir')
92 child.sendline("cd ..")
93 child.sendline("rmdir testdir")
95 child = t.pexpect_spawn('%s //${HOSTNAME}.${WIN_REALM}/test -Uroot@${WIN_REALM}%%${PASSWORD2} -k' % (smbclient))
96 child.expect("smb:")
97 child.sendline("dir")
98 child.expect("blocks available")
99 child.sendline("mkdir testdir")
100 child.expect("smb:")
101 child.sendline("cd testdir")
102 child.expect('testdir')
103 child.sendline("cd ..")
104 child.sendline("rmdir testdir")
106 def create_shares(t):
107 t.info("Adding test shares")
108 t.chdir('${PREFIX}')
109 t.write_file("etc/smb.conf", '''
110 [test]
111 path = ${PREFIX}/test
112 read only = no
113 ''',
114 mode='a')
115 t.run_cmd("mkdir -p test")
118 def prep_join_as_member(t, vm):
119 '''prepare to join a windows domain as a member server'''
120 t.setwinvars(vm)
121 t.info("Starting VMs for joining ${WIN_VM} as a member using net ads join")
122 t.chdir('${PREFIX}')
123 t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
124 t.vm_poweroff("${WIN_VM}", checkfail=False)
125 t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
126 child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
127 t.get_ipconfig(child)
128 t.del_files(["var", "private"])
129 t.write_file("etc/smb.conf", '''
130 [global]
131 netbios name = ${HOSTNAME}
132 log level = ${DEBUGLEVEL}
133 realm = ${WIN_REALM}
134 workgroup = ${WIN_DOMAIN}
135 security = ADS
136 bind interfaces only = yes
137 interfaces = ${INTERFACE}
138 winbind separator = /
139 idmap uid = 1000000-2000000
140 idmap gid = 1000000-2000000
141 winbind enum users = yes
142 winbind enum groups = yes
143 max protocol = SMB2
144 map hidden = no
145 map system = no
146 ea support = yes
147 panic action = xterm -e gdb --pid %d
148 ''')
150 def join_as_member(t, vm):
151 '''join a windows domain as a member server'''
152 t.setwinvars(vm)
153 t.info("Joining ${WIN_VM} as a member using net ads join")
154 t.port_wait("${WIN_IP}", 389)
155 t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
156 t.cmd_contains("bin/net ads join -Uadministrator%${WIN_PASS}", ["Joined"])
157 t.cmd_contains("bin/net ads testjoin", ["Join is OK"])
158 t.cmd_contains("bin/net ads dns register ${HOSTNAME}.${WIN_REALM} -P", ["Successfully registered hostname with DNS"])
159 t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}",
160 ['${HOSTNAME}.${WIN_REALM} has address'])
162 def create_root_account(t, vm):
163 t.setwinvars(vm)
164 t.info("Creating 'root' account for testing Samba3 member server")
165 t.chdir('${PREFIX}')
166 t.run_cmd('bin/net ads user add root -Uadministrator%${WIN_PASS}')
167 child = t.pexpect_spawn('bin/net ads password root -Uadministrator%${WIN_PASS}')
168 child.expect("Enter new password for root")
169 child.sendline("${PASSWORD2}")
170 child.expect("Password change for ");
171 child.expect(" completed")
172 child = t.pexpect_spawn('bin/net rpc shell -S ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}')
173 child.expect("net rpc>")
174 child.sendline("user edit disabled root no")
175 child.expect("Set root's disabled flag")
177 def test_join_as_member(t, vm):
178 '''test the domain join'''
179 t.setwinvars(vm)
180 t.info('Testing join as member')
181 t.chdir('${PREFIX}')
182 test_wbinfo(t)
183 test_smbclient(t)
186 def test_s3(t):
187 '''basic s3 testing'''
189 t.setvar("SAMBA_VERSION", "Version 4")
190 t.setvar("smbclient", "bin/smbclient")
191 t.check_prerequesites()
192 set_libpath(t)
194 if not t.skip("configure_bind"):
195 t.configure_bind()
196 if not t.skip("stop_bind"):
197 t.stop_bind()
198 if not t.skip("stop_vms"):
199 t.stop_vms()
201 if not t.skip("build"):
202 build_s3(t)
204 set_krb5_conf(t)
205 if not t.skip("configure_bind2"):
206 t.configure_bind()
207 if not t.skip("start_bind"):
208 t.start_bind()
210 dc_started = False
211 if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
212 t.start_winvm('W2K8R2A')
213 dc_started = True
214 prep_join_as_member(t, "W2K8R2A")
215 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
216 join_as_member(t, "W2K8R2A")
217 create_shares(t)
218 start_s3(t)
219 create_root_account(t, "W2K8R2A")
220 test_join_as_member(t, "W2K8R2A")
222 if t.have_var('WINDOWS7_VM') and t.have_var('W2K8R2A_VM') and not t.skip("join_windows7_2008r2"):
223 if not dc_started:
224 t.start_winvm('W2K8R2A')
225 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
226 dc_started = True
227 else:
228 t.setwinvars('W2K8R2A')
229 realm = t.getvar("WIN_REALM")
230 dom_username = t.getvar("WIN_USER")
231 dom_password = t.getvar("WIN_PASS")
232 dom_realm = t.getvar("WIN_REALM")
233 t.start_winvm('WINDOWS7')
234 t.test_remote_smbclient("WINDOWS7")
235 t.run_winjoin('WINDOWS7', realm, username=dom_username, password=dom_password)
236 t.test_remote_smbclient("WINDOWS7", dom_username, dom_password)
237 t.test_remote_smbclient('WINDOWS7', dom_username, dom_password, args='--option=clientntlmv2auth=no')
238 t.test_remote_smbclient('WINDOWS7', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k")
239 t.test_remote_smbclient('WINDOWS7', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k --option=clientusespnegoprincipal=yes")
240 t.test_net_use('WINDOWS7', dom_realm, t.getvar("W2K8R2A_DOMAIN"), 'root', '${PASSWORD2}')
242 if t.have_var('WINXP_VM') and t.have_var('W2K8R2A_VM') and not t.skip("join_winxp_2008r2"):
243 if not dc_started:
244 t.start_winvm('W2K8R2A')
245 t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
246 dc_started = True
247 else:
248 t.setwinvars('W2K8R2A')
249 realm = t.getvar("WIN_REALM")
250 dom_username = t.getvar("WIN_USER")
251 dom_password = t.getvar("WIN_PASS")
252 dom_realm = t.getvar("WIN_REALM")
253 t.start_winvm('WINXP')
254 t.run_winjoin('WINXP', realm, username=dom_username, password=dom_password)
255 t.test_remote_smbclient('WINXP', dom_username, dom_password)
256 t.test_remote_smbclient('WINXP', dom_username, dom_password, args='--option=clientntlmv2auth=no')
257 t.test_remote_smbclient('WINXP', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k")
258 t.test_remote_smbclient('WINXP', "%s@%s" % (dom_username, dom_realm), dom_password, args="-k --clientusespnegoprincipal=yes")
259 t.test_net_use('WINXP', dom_realm, t.getvar("W2K8R2A_DOMAIN"), 'root', '${PASSWORD2}')
261 t.info("S3 test: All OK")
264 def test_cleanup(t):
265 '''cleanup after tests'''
266 t.info("Cleaning up ...")
267 t.restore_resolv_conf()
268 if getattr(t, 'bind_child', False):
269 t.bind_child.kill()
272 if __name__ == '__main__':
273 t = wintest.wintest()
275 t.setup("test-s3.py", "source3")
277 try:
278 test_s3(t)
279 except:
280 if not t.opts.nocleanup:
281 test_cleanup(t)
282 raise
284 if not t.opts.nocleanup:
285 test_cleanup(t)
286 t.info("S3 test: All OK")