s4-provision Add an invalid names check for 'domain == netbiosname'
[nivanova/samba-autobuild/.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 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("LD_LIBRARY_PATH", "${PREFIX}/lib")
15
16
17 def build_s3(t):
18     '''build samba3'''
19     t.info('Building s3')
20     t.chdir('${SOURCETREE}/source3')
21     t.putenv('CC', 'ccache gcc')
22     t.run_cmd("./autogen.sh")
23     t.run_cmd("./configure -C --prefix=${PREFIX} --enable-developer")
24     t.run_cmd('make basics')
25     t.run_cmd('make -j4')
26     t.run_cmd('rm -rf ${PREFIX}')
27     t.run_cmd('make install')
28
29 def start_s3(t):
30     t.info('Starting Samba3')
31     t.chdir("${PREFIX}")
32     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
33     t.run_cmd("rm -f var/locks/*.pid")
34     t.run_cmd(['sbin/nmbd', "-D"])
35     t.run_cmd(['sbin/winbindd', "-D"])
36     t.run_cmd(['sbin/smbd', "-D"])
37     t.port_wait("localhost", 139)
38
39
40 def test_wbinfo(t):
41     t.info('Testing wbinfo')
42     t.chdir('${PREFIX}')
43     t.cmd_contains("bin/wbinfo --version", ["Version 3."])
44     t.cmd_contains("bin/wbinfo -p", ["Ping to winbindd succeeded"])
45     t.retry_cmd("bin/wbinfo --online-status",
46                 ["BUILTIN : online",
47                  "${HOSTNAME} : online",
48                  "${WIN_DOMAIN} : online"],
49                 casefold=True)
50     t.cmd_contains("bin/wbinfo -u",
51                    ["${WIN_DOMAIN}/administrator",
52                     "${WIN_DOMAIN}/krbtgt" ],
53                    casefold=True)
54     t.cmd_contains("bin/wbinfo -g",
55                    ["${WIN_DOMAIN}/domain users",
56                     "${WIN_DOMAIN}/domain guests",
57                     "${WIN_DOMAIN}/domain admins"],
58                    casefold=True)
59     t.cmd_contains("bin/wbinfo --name-to-sid administrator",
60                    "S-1-5-.*-500 SID_USER .1",
61                    regex=True)
62     t.cmd_contains("bin/wbinfo --name-to-sid 'domain users'",
63                    "S-1-5-.*-513 SID_DOM_GROUP .2",
64                    regex=True)
65
66     t.retry_cmd("bin/wbinfo --authenticate=administrator%${WIN_PASS}",
67                 ["plaintext password authentication succeeded",
68                  "challenge/response password authentication succeeded"])
69
70
71 def test_smbclient(t):
72     t.info('Testing smbclient')
73     t.chdir('${PREFIX}')
74     t.cmd_contains("bin/smbclient --version", ["Version 3."])
75     t.cmd_contains('bin/smbclient -L localhost -U%', ["Domain=[${WIN_DOMAIN}]", "test", "IPC$", "Samba 3."],
76                    casefold=True)
77     child = t.pexpect_spawn('bin/smbclient //${HOSTNAME}/test -Uadministrator%${WIN_PASS}')
78     child.expect("smb:")
79     child.sendline("dir")
80     child.expect("blocks available")
81     child.sendline("mkdir testdir")
82     child.expect("smb:")
83     child.sendline("cd testdir")
84     child.expect('testdir')
85     child.sendline("cd ..")
86     child.sendline("rmdir testdir")
87
88
89 def create_shares(t):
90     t.info("Adding test shares")
91     t.chdir('${PREFIX}')
92     t.write_file("lib/smb.conf", '''
93 [test]
94        path = ${PREFIX}/test
95        read only = no
96        ''',
97                  mode='a')
98     t.run_cmd("mkdir -p test")
99
100
101 def join_as_member(t, vm):
102     '''join a windows domain as a member server'''
103     t.setwinvars(vm)
104     t.info("Joining ${WIN_VM} as a member using net ads join")
105     t.chdir('${PREFIX}')
106     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
107     t.vm_poweroff("${WIN_VM}", checkfail=False)
108     t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
109     t.ping_wait("${WIN_HOSTNAME}")
110     child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
111     t.del_files(["var", "private"])
112     t.write_file("lib/smb.conf", '''
113 [global]
114         netbios name = ${HOSTNAME}
115         log level = ${DEBUGLEVEL}
116         realm = ${WIN_REALM}
117         workgroup = ${WIN_DOMAIN}
118         security = ADS
119         interfaces = ${INTERFACE}
120         winbind separator = /
121         idmap uid = 1000000-2000000
122         idmap gid = 1000000-2000000
123         winbind enum users = yes
124         winbind enum groups = yes
125         max protocol = SMB2
126         map hidden = no
127         map system = no
128         ea support = yes
129         panic action = xterm -e gdb --pid %d
130     ''')
131     t.cmd_contains("bin/net ads join -Uadministrator%${WIN_PASS}", ["Joined"])
132     t.cmd_contains("bin/net ads testjoin", ["Join is OK"])
133
134
135 def test_join_as_member(t, vm):
136     '''test the domain join'''
137     t.setwinvars(vm)
138     t.info('Testing join as member')
139     t.chdir('${PREFIX}')
140     t.run_cmd('bin/net ads user add root -Uadministrator%${WIN_PASS}')
141     test_wbinfo(t)
142     test_smbclient(t)
143
144
145 def test_s3(t):
146     '''basic s3 testing'''
147
148     check_prerequesites(t)
149
150     if not t.skip("build"):
151         build_s3(t)
152
153     if t.have_var('W2K8R2A_VM') and not t.skip("join_w2k8r2"):
154         join_as_member(t, "W2K8R2A")
155         create_shares(t)
156         start_s3(t)
157         test_join_as_member(t, "W2K8R2A")
158
159     t.info("S3 test: All OK")
160
161
162 if __name__ == '__main__':
163     t = wintest.wintest()
164
165     t.setup("test-s3.py", "source3")
166
167     test_s3(t)