33f4acaf12ee1b63402c3371b0cb846439c0def2
[samba.git] / wintest / test-s3.py
1 #!/usr/bin/env python
2
3 '''automated testing of Samba3 against windows'''
4
5 import sys, os
6 import optparse
7 import wintest
8
9 def set_libpath(t):
10     t.putenv("LD_LIBRARY_PATH", "${PREFIX}/lib")
11
12 def build_s3(t):
13     '''build samba3'''
14     t.info('Building s3')
15     t.chdir('${SOURCETREE}/source3')
16     t.putenv('CC', 'ccache gcc')
17     t.run_cmd("./autogen.sh")
18     t.run_cmd("./configure -C --prefix=${PREFIX} --enable-developer")
19     t.run_cmd('make basics')
20     t.run_cmd('make -j4')
21     t.run_cmd('rm -rf ${PREFIX}')
22     t.run_cmd('make install')
23
24 def start_s3(t):
25     t.info('Starting Samba3')
26     t.chdir("${PREFIX}")
27     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
28     t.run_cmd("rm -f var/locks/*.pid")
29     t.run_cmd(['sbin/nmbd', "-D"])
30     t.run_cmd(['sbin/winbindd', "-D"])
31     t.run_cmd(['sbin/smbd', "-D"])
32     t.port_wait("${INTERFACE_IP}", 139)
33
34
35 def test_wbinfo(t):
36     t.info('Testing wbinfo')
37     t.chdir('${PREFIX}')
38     t.cmd_contains("bin/wbinfo --version", ["Version 3."])
39     t.cmd_contains("bin/wbinfo -p", ["Ping to winbindd succeeded"])
40     t.retry_cmd("bin/wbinfo --online-status",
41                 ["BUILTIN : online",
42                  "${HOSTNAME} : online",
43                  "${WIN_DOMAIN} : online"],
44                 casefold=True)
45     t.cmd_contains("bin/wbinfo -u",
46                    ["${WIN_DOMAIN}/administrator",
47                     "${WIN_DOMAIN}/krbtgt" ],
48                    casefold=True)
49     t.cmd_contains("bin/wbinfo -g",
50                    ["${WIN_DOMAIN}/domain users",
51                     "${WIN_DOMAIN}/domain guests",
52                     "${WIN_DOMAIN}/domain admins"],
53                    casefold=True)
54     t.cmd_contains("bin/wbinfo --name-to-sid administrator",
55                    "S-1-5-.*-500 SID_USER .1",
56                    regex=True)
57     t.cmd_contains("bin/wbinfo --name-to-sid 'domain users'",
58                    "S-1-5-.*-513 SID_DOM_GROUP .2",
59                    regex=True)
60
61     t.retry_cmd("bin/wbinfo --authenticate=${WIN_DOMAIN}/administrator%${WIN_PASS}",
62                 ["plaintext password authentication succeeded",
63                  "challenge/response password authentication succeeded"])
64
65
66 def test_smbclient(t):
67     t.info('Testing smbclient')
68     t.chdir('${PREFIX}')
69     t.cmd_contains("bin/smbclient --version", ["Version 3."])
70     t.cmd_contains('bin/smbclient -L ${INTERFACE_IP} -U%', ["Domain=[${WIN_DOMAIN}]", "test", "IPC$", "Samba 3."],
71                    casefold=True)
72     child = t.pexpect_spawn('bin/smbclient //${HOSTNAME}.${WIN_REALM}/test -Uroot%${PASSWORD2}')
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")
82
83
84 def create_shares(t):
85     t.info("Adding test shares")
86     t.chdir('${PREFIX}')
87     t.write_file("lib/smb.conf", '''
88 [test]
89        path = ${PREFIX}/test
90        read only = no
91        ''',
92                  mode='a')
93     t.run_cmd("mkdir -p test")
94
95
96 def prep_join_as_member(t, vm):
97     '''prepare to join a windows domain as a member server'''
98     t.setwinvars(vm)
99     t.info("Starting VMs for joining ${WIN_VM} as a member using net ads join")
100     t.chdir('${PREFIX}')
101     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
102     t.vm_poweroff("${WIN_VM}", checkfail=False)
103     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
104     child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
105     t.get_ipconfig(child)
106     t.del_files(["var", "private"])
107     t.write_file("lib/smb.conf", '''
108 [global]
109         netbios name = ${HOSTNAME}
110         log level = ${DEBUGLEVEL}
111         realm = ${WIN_REALM}
112         workgroup = ${WIN_DOMAIN}
113         security = ADS
114         bind interfaces only = yes
115         interfaces = ${INTERFACE}
116         winbind separator = /
117         idmap uid = 1000000-2000000
118         idmap gid = 1000000-2000000
119         winbind enum users = yes
120         winbind enum groups = yes
121         max protocol = SMB2
122         map hidden = no
123         map system = no
124         ea support = yes
125         panic action = xterm -e gdb --pid %d
126     ''')
127
128 def join_as_member(t, vm):
129     '''join a windows domain as a member server'''
130     t.setwinvars(vm)
131     t.info("Joining ${WIN_VM} as a member using net ads join")
132     t.port_wait("${WIN_IP}", 389)
133     t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
134     t.cmd_contains("bin/net ads join -Uadministrator%${WIN_PASS}", ["Joined"])
135     t.cmd_contains("bin/net ads testjoin", ["Join is OK"])
136     t.cmd_contains("bin/net ads dns register ${HOSTNAME}.${WIN_REALM} -P", ["Successfully registered hostname with DNS"])
137     t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}",
138                  ['${HOSTNAME}.${WIN_REALM} has address'])
139
140
141 def test_join_as_member(t, vm):
142     '''test the domain join'''
143     t.setwinvars(vm)
144     t.info('Testing join as member')
145     t.chdir('${PREFIX}')
146     t.run_cmd('bin/net ads user add root -Uadministrator%${WIN_PASS}')
147     child = t.pexpect_spawn('bin/net ads password root -Uadministrator%${WIN_PASS}')
148     child.expect("Enter new password for root")
149     child.sendline("${PASSWORD2}")
150     child.expect("Password change for ");
151     child.expect(" completed")
152     child = t.pexpect_spawn('bin/net rpc shell -S ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}')
153     child.expect("net rpc>")
154     child.sendline("user edit disabled root no")
155     child.expect("Set root's disabled flag")
156     test_wbinfo(t)
157     test_smbclient(t)
158
159
160 def test_s3(t):
161     '''basic s3 testing'''
162
163     t.check_prerequesites()
164     set_libpath(t)
165
166     if not t.skip("configure_bind"):
167         t.configure_bind()
168     if not t.skip("stop_bind"):
169         t.stop_bind()
170     if not t.skip("stop_vms"):
171         t.stop_vms()
172
173     if not t.skip("build"):
174         build_s3(t)
175
176     if not t.skip("configure_bind2"):
177         t.configure_bind()
178     if not t.skip("start_bind"):
179         t.start_bind()
180
181     if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
182         prep_join_as_member(t, "W2K8R2A")
183         t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
184         join_as_member(t, "W2K8R2A")
185         create_shares(t)
186         start_s3(t)
187         test_join_as_member(t, "W2K8R2A")
188
189     t.info("S3 test: All OK")
190
191
192 def test_cleanup(t):
193     '''cleanup after tests'''
194     t.info("Cleaning up ...")
195     t.restore_resolv_conf()
196     if getattr(t, 'bind_child', False):
197         t.bind_child.kill()
198
199
200 if __name__ == '__main__':
201     t = wintest.wintest()
202
203     t.setup("test-s3.py", "source3")
204
205     try:
206         test_s3(t)
207     except:
208         if not t.opts.nocleanup:
209             test_cleanup(t)
210         raise
211
212     if not t.opts.nocleanup:
213         test_cleanup(t)
214     t.info("S3 test: All OK")