~veger/ubuntu/precise/samba/fix-for-902339

« back to all changes in this revision

Viewing changes to wintest/test-s4-howto.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
'''automated testing of the steps of the Samba4 HOWTO'''
 
4
 
 
5
import sys, os
 
6
import wintest, pexpect, time, subprocess
 
7
 
 
8
def set_krb5_conf(t):
 
9
    t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
 
10
 
 
11
def build_s4(t):
 
12
    '''build samba4'''
 
13
    t.info('Building s4')
 
14
    t.chdir('${SOURCETREE}')
 
15
    t.putenv('CC', 'ccache gcc')
 
16
    t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
 
17
    t.run_cmd('make -j')
 
18
    t.run_cmd('rm -rf ${PREFIX}')
 
19
    t.run_cmd('make -j install')
 
20
 
 
21
 
 
22
def provision_s4(t, func_level="2008"):
 
23
    '''provision s4 as a DC'''
 
24
    t.info('Provisioning s4')
 
25
    t.chdir('${PREFIX}')
 
26
    t.del_files(["var", "private"])
 
27
    t.run_cmd("rm -f etc/smb.conf")
 
28
    provision=['sbin/provision',
 
29
               '--realm=${LCREALM}',
 
30
               '--domain=${DOMAIN}',
 
31
               '--adminpass=${PASSWORD1}',
 
32
               '--server-role=domain controller',
 
33
               '--function-level=%s' % func_level,
 
34
               '-d${DEBUGLEVEL}',
 
35
               '--option=interfaces=${INTERFACE}',
 
36
               '--host-ip=${INTERFACE_IP}',
 
37
               '--option=bind interfaces only=yes',
 
38
               '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
 
39
    if t.getvar('INTERFACE_IPV6'):
 
40
        provision.append('--host-ip6=${INTERFACE_IPV6}')
 
41
    t.run_cmd(provision)
 
42
    t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
 
43
    t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
 
44
    t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
 
45
 
 
46
 
 
47
def start_s4(t):
 
48
    '''startup samba4'''
 
49
    t.info('Starting Samba4')
 
50
    t.chdir("${PREFIX}")
 
51
    t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
 
52
    t.run_cmd(['sbin/samba',
 
53
             '--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
 
54
    t.port_wait("${INTERFACE_IP}", 139)
 
55
 
 
56
def test_smbclient(t):
 
57
    '''test smbclient against localhost'''
 
58
    t.info('Testing smbclient')
 
59
    t.chdir('${PREFIX}')
 
60
    t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
 
61
    t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
 
62
    child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
 
63
    child.expect("smb:")
 
64
    child.sendline("dir")
 
65
    child.expect("blocks available")
 
66
    child.sendline("mkdir testdir")
 
67
    child.expect("smb:")
 
68
    child.sendline("cd testdir")
 
69
    child.expect('testdir')
 
70
    child.sendline("cd ..")
 
71
    child.sendline("rmdir testdir")
 
72
 
 
73
 
 
74
def create_shares(t):
 
75
    '''create some test shares'''
 
76
    t.info("Adding test shares")
 
77
    t.chdir('${PREFIX}')
 
78
    t.write_file("etc/smb.conf", '''
 
79
[test]
 
80
       path = ${PREFIX}/test
 
81
       read only = no
 
82
[profiles]
 
83
       path = ${PREFIX}/var/profiles
 
84
       read only = no
 
85
    ''',
 
86
                 mode='a')
 
87
    t.run_cmd("mkdir -p test")
 
88
    t.run_cmd("mkdir -p var/profiles")
 
89
 
 
90
 
 
91
def test_dns(t):
 
92
    '''test that DNS is OK'''
 
93
    t.info("Testing DNS")
 
94
    t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
 
95
                 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
 
96
    t.cmd_contains("host -t SRV  _kerberos._udp.${LCREALM}.",
 
97
                 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
 
98
    t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
 
99
                 ['${HOSTNAME}.${LCREALM} has address'])
 
100
 
 
101
def test_kerberos(t):
 
102
    '''test that kerberos is OK'''
 
103
    t.info("Testing kerberos")
 
104
    t.run_cmd("kdestroy")
 
105
    t.kinit("administrator@${REALM}", "${PASSWORD1}")
 
106
    # this copes with the differences between MIT and Heimdal klist
 
107
    t.cmd_contains("klist", ["rincipal", "administrator@${REALM}"])
 
108
 
 
109
 
 
110
def test_dyndns(t):
 
111
    '''test that dynamic DNS is working'''
 
112
    t.chdir('${PREFIX}')
 
113
    t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
 
114
    t.rndc_cmd("flush")
 
115
 
 
116
 
 
117
def run_winjoin(t, vm):
 
118
    '''join a windows box to our domain'''
 
119
    t.setwinvars(vm)
 
120
 
 
121
    t.run_winjoin(t, "${LCREALM}")
 
122
 
 
123
def test_winjoin(t, vm):
 
124
    t.info("Checking the windows join is OK")
 
125
    t.chdir('${PREFIX}')
 
126
    t.port_wait("${WIN_IP}", 139)
 
127
    t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
 
128
    t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
 
129
    t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
130
    t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
131
    t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
132
    child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
 
133
    child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
 
134
    child.expect("The command completed successfully")
 
135
 
 
136
 
 
137
def run_dcpromo(t, vm):
 
138
    '''run a dcpromo on windows'''
 
139
    t.setwinvars(vm)
 
140
 
 
141
    t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
 
142
    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True, set_noexpire=True)
 
143
    child.sendline("copy /Y con answers.txt")
 
144
    child.sendline('''
 
145
[DCINSTALL]
 
146
RebootOnSuccess=Yes
 
147
RebootOnCompletion=Yes
 
148
ReplicaOrNewDomain=Replica
 
149
ReplicaDomainDNSName=${LCREALM}
 
150
SiteName=Default-First-Site-Name
 
151
InstallDNS=No
 
152
ConfirmGc=Yes
 
153
CreateDNSDelegation=No
 
154
UserDomain=${LCREALM}
 
155
UserName=${LCREALM}\\administrator
 
156
Password=${PASSWORD1}
 
157
DatabasePath="C:\Windows\NTDS"
 
158
LogPath="C:\Windows\NTDS"
 
159
SYSVOLPath="C:\Windows\SYSVOL"
 
160
SafeModeAdminPassword=${PASSWORD1}
 
161

 
162
''')
 
163
    child.expect("copied.")
 
164
    child.expect("C:")
 
165
    child.expect("C:")
 
166
    child.sendline("dcpromo /answer:answers.txt")
 
167
    i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
 
168
    if i == 1 or i == 2:
 
169
        child.sendline("echo off")
 
170
        child.sendline("echo START DCPROMO log")
 
171
        child.sendline("more c:\windows\debug\dcpromoui.log")
 
172
        child.sendline("echo END DCPROMO log")
 
173
        child.expect("END DCPROMO")
 
174
        raise Exception("dcpromo failed")
 
175
    t.wait_reboot()
 
176
 
 
177
 
 
178
def test_dcpromo(t, vm):
 
179
    '''test that dcpromo worked'''
 
180
    t.info("Checking the dcpromo join is OK")
 
181
    t.chdir('${PREFIX}')
 
182
    t.port_wait("${WIN_IP}", 139)
 
183
    t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
 
184
                ['${WIN_HOSTNAME}.${LCREALM} has address'],
 
185
                retries=30, delay=10, casefold=True)
 
186
    t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
187
    t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
 
188
    t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
189
 
 
190
    t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
 
191
    t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
 
192
 
 
193
    t.kinit("administrator@${REALM}", "${PASSWORD1}")
 
194
 
 
195
    # the first replication will transfer the dnsHostname attribute
 
196
    t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
 
197
 
 
198
    for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
 
199
        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
 
200
        t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
 
201
 
 
202
    t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
 
203
                 [ "INBOUND NEIGHBORS",
 
204
                   "${BASEDN}",
 
205
                   "Last attempt .* was successful",
 
206
                   "CN=Configuration,${BASEDN}",
 
207
                   "Last attempt .* was successful",
 
208
                   "CN=Configuration,${BASEDN}", # cope with either order
 
209
                   "Last attempt .* was successful",
 
210
                   "OUTBOUND NEIGHBORS",
 
211
                   "${BASEDN}",
 
212
                   "Last success",
 
213
                   "CN=Configuration,${BASEDN}",
 
214
                   "Last success",
 
215
                   "CN=Configuration,${BASEDN}",
 
216
                   "Last success"],
 
217
                   ordered=True,
 
218
                   regex=True)
 
219
 
 
220
    t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
 
221
                 [ "INBOUND NEIGHBORS",
 
222
                   "${BASEDN}",
 
223
                   "Last attempt .* was successful",
 
224
                   "CN=Configuration,${BASEDN}",
 
225
                   "Last attempt .* was successful",
 
226
                   "CN=Configuration,${BASEDN}",
 
227
                   "Last attempt .* was successful",
 
228
                   "OUTBOUND NEIGHBORS",
 
229
                   "${BASEDN}",
 
230
                   "Last success",
 
231
                   "CN=Configuration,${BASEDN}",
 
232
                   "Last success",
 
233
                   "CN=Configuration,${BASEDN}",
 
234
                   "Last success" ],
 
235
                   ordered=True,
 
236
                   regex=True)
 
237
 
 
238
    child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
 
239
    child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
 
240
 
 
241
    retries = 10
 
242
    i = child.expect(["The command completed successfully", "The network path was not found"])
 
243
    while i == 1 and retries > 0:
 
244
        child.expect("C:")
 
245
        time.sleep(2)
 
246
        child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
 
247
        i = child.expect(["The command completed successfully", "The network path was not found"])
 
248
        retries -=1
 
249
 
 
250
    t.run_net_time(child)
 
251
 
 
252
    t.info("Checking if showrepl is happy")
 
253
    child.sendline("repadmin /showrepl")
 
254
    child.expect("${BASEDN}")
 
255
    child.expect("was successful")
 
256
    child.expect("CN=Configuration,${BASEDN}")
 
257
    child.expect("was successful")
 
258
    child.expect("CN=Schema,CN=Configuration,${BASEDN}")
 
259
    child.expect("was successful")
 
260
 
 
261
    t.info("Checking if new users propogate to windows")
 
262
    t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
 
263
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
 
264
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
 
265
 
 
266
    t.info("Checking if new users on windows propogate to samba")
 
267
    child.sendline("net user test3 ${PASSWORD3} /add")
 
268
    while True:
 
269
        i = child.expect(["The command completed successfully",
 
270
                          "The directory service was unable to allocate a relative identifier"])
 
271
        if i == 0:
 
272
            break
 
273
        time.sleep(2)
 
274
 
 
275
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
 
276
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
 
277
 
 
278
    t.info("Checking propogation of user deletion")
 
279
    t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
 
280
    child.sendline("net user test3 /del")
 
281
    child.expect("The command completed successfully")
 
282
 
 
283
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
 
284
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
 
285
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
 
286
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
 
287
    t.vm_poweroff("${WIN_VM}")
 
288
 
 
289
 
 
290
def run_dcpromo_rodc(t, vm):
 
291
    '''run a RODC dcpromo to join a windows DC to the samba domain'''
 
292
    t.setwinvars(vm)
 
293
    t.info("Joining a w2k8 box to the domain as a RODC")
 
294
    t.vm_poweroff("${WIN_VM}", checkfail=False)
 
295
    t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
 
296
    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
 
297
    child.sendline("copy /Y con answers.txt")
 
298
    child.sendline('''
 
299
[DCInstall]
 
300
ReplicaOrNewDomain=ReadOnlyReplica
 
301
ReplicaDomainDNSName=${LCREALM}
 
302
PasswordReplicationDenied="BUILTIN\Administrators"
 
303
PasswordReplicationDenied="BUILTIN\Server Operators"
 
304
PasswordReplicationDenied="BUILTIN\Backup Operators"
 
305
PasswordReplicationDenied="BUILTIN\Account Operators"
 
306
PasswordReplicationDenied="${DOMAIN}\Denied RODC Password Replication Group"
 
307
PasswordReplicationAllowed="${DOMAIN}\Allowed RODC Password Replication Group"
 
308
DelegatedAdmin="${DOMAIN}\\Administrator"
 
309
SiteName=Default-First-Site-Name
 
310
InstallDNS=No
 
311
ConfirmGc=Yes
 
312
CreateDNSDelegation=No
 
313
UserDomain=${LCREALM}
 
314
UserName=${LCREALM}\\administrator
 
315
Password=${PASSWORD1}
 
316
DatabasePath="C:\Windows\NTDS"
 
317
LogPath="C:\Windows\NTDS"
 
318
SYSVOLPath="C:\Windows\SYSVOL"
 
319
SafeModeAdminPassword=${PASSWORD1}
 
320
RebootOnCompletion=No
 
321

 
322
''')
 
323
    child.expect("copied.")
 
324
    child.sendline("dcpromo /answer:answers.txt")
 
325
    i = child.expect(["You must restart this computer", "failed", "could not be located in this domain"], timeout=120)
 
326
    if i != 0:
 
327
        child.sendline("echo off")
 
328
        child.sendline("echo START DCPROMO log")
 
329
        child.sendline("more c:\windows\debug\dcpromoui.log")
 
330
        child.sendline("echo END DCPROMO log")
 
331
        child.expect("END DCPROMO")
 
332
        raise Exception("dcpromo failed")
 
333
    child.sendline("shutdown -r -t 0")
 
334
    t.wait_reboot()
 
335
 
 
336
 
 
337
 
 
338
def test_dcpromo_rodc(t, vm):
 
339
    '''test the RODC dcpromo worked'''
 
340
    t.info("Checking the w2k8 RODC join is OK")
 
341
    t.chdir('${PREFIX}')
 
342
    t.port_wait("${WIN_IP}", 139)
 
343
    child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
 
344
    child.sendline("ipconfig /registerdns")
 
345
    t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
346
    t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
 
347
    t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
 
348
    child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
 
349
    child.expect("The command completed successfully")
 
350
 
 
351
    t.info("Checking if showrepl is happy")
 
352
    child.sendline("repadmin /showrepl")
 
353
    child.expect("${BASEDN}")
 
354
    child.expect("was successful")
 
355
    child.expect("CN=Configuration,${BASEDN}")
 
356
    child.expect("was successful")
 
357
    child.expect("CN=Configuration,${BASEDN}")
 
358
    child.expect("was successful")
 
359
 
 
360
    for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
 
361
        t.cmd_contains("bin/samba-tool drs replicate --add-ref ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s" % nc, ["was successful"])
 
362
 
 
363
    t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
 
364
                 [ "INBOUND NEIGHBORS",
 
365
                   "OUTBOUND NEIGHBORS",
 
366
                   "${BASEDN}",
 
367
                   "Last attempt.*was successful",
 
368
                   "CN=Configuration,${BASEDN}",
 
369
                   "Last attempt.*was successful",
 
370
                   "CN=Configuration,${BASEDN}",
 
371
                   "Last attempt.*was successful" ],
 
372
                   ordered=True,
 
373
                   regex=True)
 
374
 
 
375
    t.info("Checking if new users are available on windows")
 
376
    t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
 
377
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
 
378
    t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN}", ["was successful"])
 
379
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
 
380
    t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
 
381
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
 
382
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
 
383
    t.vm_poweroff("${WIN_VM}")
 
384
 
 
385
 
 
386
def prep_join_as_dc(t, vm):
 
387
    '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
 
388
    t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
 
389
    t.chdir('${PREFIX}')
 
390
    t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
 
391
    t.rndc_cmd('flush')
 
392
    t.run_cmd("rm -rf etc/smb.conf private")
 
393
    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
394
    t.get_ipconfig(child)
 
395
 
 
396
def join_as_dc(t, vm):
 
397
    '''join a windows domain as a DC'''
 
398
    t.setwinvars(vm)
 
399
    t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
 
400
    t.port_wait("${WIN_IP}", 389)
 
401
    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
 
402
 
 
403
    t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
 
404
    t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
 
405
    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
406
 
 
407
 
 
408
def test_join_as_dc(t, vm):
 
409
    '''test the join of a windows domain as a DC'''
 
410
    t.info("Checking the DC join is OK")
 
411
    t.chdir('${PREFIX}')
 
412
    t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
 
413
    t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
 
414
    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
415
 
 
416
    t.info("Forcing kcc runs, and replication")
 
417
    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
418
    t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
419
 
 
420
    t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
 
421
    for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
 
422
        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
 
423
        t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
 
424
 
 
425
    retries = 10
 
426
    i = 1
 
427
    while i == 1 and retries > 0:
 
428
        child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
 
429
        i = child.expect(["The command completed successfully", "The network path was not found"])
 
430
        child.expect("C:")
 
431
        if i == 1:
 
432
            time.sleep(2)
 
433
        retries -=1
 
434
 
 
435
    t.info("Checking if showrepl is happy")
 
436
    child.sendline("repadmin /showrepl")
 
437
    child.expect("${WIN_BASEDN}")
 
438
    child.expect("was successful")
 
439
    child.expect("CN=Configuration,${WIN_BASEDN}")
 
440
    child.expect("was successful")
 
441
    child.expect("CN=Configuration,${WIN_BASEDN}")
 
442
    child.expect("was successful")
 
443
 
 
444
    t.info("Checking if new users propogate to windows")
 
445
    t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
 
446
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
 
447
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
 
448
 
 
449
    t.info("Checking if new users on windows propogate to samba")
 
450
    child.sendline("net user test3 ${PASSWORD3} /add")
 
451
    child.expect("The command completed successfully")
 
452
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
 
453
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
 
454
 
 
455
    t.info("Checking propogation of user deletion")
 
456
    t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
457
    child.sendline("net user test3 /del")
 
458
    child.expect("The command completed successfully")
 
459
 
 
460
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
 
461
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
 
462
    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
 
463
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
 
464
    t.vm_poweroff("${WIN_VM}")
 
465
 
 
466
 
 
467
def join_as_rodc(t, vm):
 
468
    '''join a windows domain as a RODC'''
 
469
    t.setwinvars(vm)
 
470
    t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
 
471
    t.port_wait("${WIN_IP}", 389)
 
472
    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
 
473
    t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
 
474
    t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
 
475
    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
476
 
 
477
 
 
478
def test_join_as_rodc(t, vm):
 
479
    '''test a windows domain RODC join'''
 
480
    t.info("Checking the RODC join is OK")
 
481
    t.chdir('${PREFIX}')
 
482
    t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
 
483
    t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
 
484
    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
485
 
 
486
    t.info("Forcing kcc runs, and replication")
 
487
    t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
488
    t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
489
 
 
490
    t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
 
491
    for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
 
492
        t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
 
493
 
 
494
    retries = 10
 
495
    i = 1
 
496
    while i == 1 and retries > 0:
 
497
        child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
 
498
        i = child.expect(["The command completed successfully", "The network path was not found"])
 
499
        child.expect("C:")
 
500
        if i == 1:
 
501
            time.sleep(2)
 
502
        retries -=1
 
503
 
 
504
    t.info("Checking if showrepl is happy")
 
505
    child.sendline("repadmin /showrepl")
 
506
    child.expect("DSA invocationID")
 
507
 
 
508
    t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
 
509
                 [ "INBOUND NEIGHBORS",
 
510
                   "OUTBOUND NEIGHBORS",
 
511
                   "${WIN_BASEDN}",
 
512
                   "Last attempt .* was successful",
 
513
                   "CN=Configuration,${WIN_BASEDN}",
 
514
                   "Last attempt .* was successful",
 
515
                   "CN=Configuration,${WIN_BASEDN}",
 
516
                   "Last attempt .* was successful" ],
 
517
                   ordered=True,
 
518
                   regex=True)
 
519
 
 
520
    t.info("Checking if new users on windows propogate to samba")
 
521
    child.sendline("net user test3 ${PASSWORD3} /add")
 
522
    child.expect("The command completed successfully")
 
523
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
 
524
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
 
525
 
 
526
    # should this work?
 
527
    t.info("Checking if new users propogate to windows")
 
528
    t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
 
529
 
 
530
    t.info("Checking propogation of user deletion")
 
531
    child.sendline("net user test3 /del")
 
532
    child.expect("The command completed successfully")
 
533
 
 
534
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
 
535
    t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
 
536
    t.vm_poweroff("${WIN_VM}")
 
537
 
 
538
 
 
539
def test_howto(t):
 
540
    '''test the Samba4 howto'''
 
541
 
 
542
    t.setvar("SAMBA_VERSION", "Version 4")
 
543
    t.check_prerequesites()
 
544
 
 
545
    # we don't need fsync safety in these tests
 
546
    t.putenv('TDB_NO_FSYNC', '1')
 
547
 
 
548
    if not t.skip("configure_bind"):
 
549
        t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
 
550
    if not t.skip("stop_bind"):
 
551
        t.stop_bind()
 
552
    if not t.skip("stop_vms"):
 
553
        t.stop_vms()
 
554
 
 
555
    if not t.skip("build"):
 
556
        build_s4(t)
 
557
 
 
558
    if not t.skip("provision"):
 
559
        provision_s4(t)
 
560
 
 
561
    set_krb5_conf(t)
 
562
 
 
563
    if not t.skip("create-shares"):
 
564
        create_shares(t)
 
565
 
 
566
    if not t.skip("starts4"):
 
567
        start_s4(t)
 
568
    if not t.skip("smbclient"):
 
569
        test_smbclient(t)
 
570
    if not t.skip("configure_bind2"):
 
571
        t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
 
572
    if not t.skip("start_bind"):
 
573
        t.start_bind()
 
574
    if not t.skip("dns"):
 
575
        test_dns(t)
 
576
    if not t.skip("kerberos"):
 
577
        test_kerberos(t)
 
578
    if not t.skip("dyndns"):
 
579
        test_dyndns(t)
 
580
 
 
581
    if t.have_vm('WINDOWS7') and not t.skip("windows7"):
 
582
        t.start_winvm("WINDOWS7")
 
583
        t.test_remote_smbclient("WINDOWS7")
 
584
        run_winjoin(t, "WINDOWS7")
 
585
        test_winjoin(t, "WINDOWS7")
 
586
        t.vm_poweroff("${WIN_VM}")
 
587
 
 
588
    if t.have_vm('WINXP') and not t.skip("winxp"):
 
589
        t.start_winvm("WINXP")
 
590
        run_winjoin(t, "WINXP")
 
591
        test_winjoin(t, "WINXP")
 
592
        t.test_remote_smbclient("WINXP", "administrator", "${PASSWORD1}")
 
593
        t.vm_poweroff("${WIN_VM}")
 
594
 
 
595
    if t.have_vm('W2K3C') and not t.skip("win2k3_member"):
 
596
        t.start_winvm("W2K3C")
 
597
        run_winjoin(t, "W2K3C")
 
598
        test_winjoin(t, "W2K3C")
 
599
        t.test_remote_smbclient("W2K3C", "administrator", "${PASSWORD1}")
 
600
        t.vm_poweroff("${WIN_VM}")
 
601
 
 
602
    if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
 
603
        t.info("Testing w2k8r2 RODC dcpromo")
 
604
        t.start_winvm("W2K8R2C")
 
605
        t.test_remote_smbclient('W2K8R2C')
 
606
        run_dcpromo_rodc(t, "W2K8R2C")
 
607
        test_dcpromo_rodc(t, "W2K8R2C")
 
608
 
 
609
    if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
 
610
        t.info("Testing w2k8r2 dcpromo")
 
611
        t.start_winvm("W2K8R2B")
 
612
        t.test_remote_smbclient('W2K8R2B')
 
613
        run_dcpromo(t, "W2K8R2B")
 
614
        test_dcpromo(t, "W2K8R2B")
 
615
 
 
616
    if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
 
617
        t.info("Testing w2k8 dcpromo")
 
618
        t.start_winvm("W2K8B")
 
619
        t.test_remote_smbclient('W2K8B')
 
620
        run_dcpromo(t, "W2K8B")
 
621
        test_dcpromo(t, "W2K8B")
 
622
 
 
623
    if t.have_vm('W2K3B') and not t.skip("dcpromo_w2k3"):
 
624
        t.info("Testing w2k3 dcpromo")
 
625
        t.info("Changing to 2003 functional level")
 
626
        provision_s4(t, func_level='2003')
 
627
        create_shares(t)
 
628
        start_s4(t)
 
629
        test_smbclient(t)
 
630
        t.restart_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
 
631
        test_dns(t)
 
632
        test_kerberos(t)
 
633
        test_dyndns(t)
 
634
        t.start_winvm("W2K3B")
 
635
        t.test_remote_smbclient('W2K3B')
 
636
        run_dcpromo(t, "W2K3B")
 
637
        test_dcpromo(t, "W2K3B")
 
638
 
 
639
    if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
 
640
        t.start_winvm("W2K8R2A")
 
641
        prep_join_as_dc(t, "W2K8R2A")
 
642
        t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
 
643
        join_as_dc(t, "W2K8R2A")
 
644
        create_shares(t)
 
645
        start_s4(t)
 
646
        test_dyndns(t)
 
647
        test_join_as_dc(t, "W2K8R2A")
 
648
 
 
649
    if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
 
650
        t.start_winvm("W2K8R2A")
 
651
        prep_join_as_dc(t, "W2K8R2A")
 
652
        t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
 
653
        join_as_rodc(t, "W2K8R2A")
 
654
        create_shares(t)
 
655
        start_s4(t)
 
656
        test_dyndns(t)
 
657
        test_join_as_rodc(t, "W2K8R2A")
 
658
 
 
659
    if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
 
660
        prep_join_as_dc(t, "W2K3A")
 
661
        t.run_dcpromo_as_first_dc("W2K3A", func_level='2003')
 
662
        join_as_dc(t, "W2K3A")
 
663
        create_shares(t)
 
664
        start_s4(t)
 
665
        test_dyndns(t)
 
666
        test_join_as_dc(t, "W2K3A")
 
667
 
 
668
    t.info("Howto test: All OK")
 
669
 
 
670
 
 
671
def test_cleanup(t):
 
672
    '''cleanup after tests'''
 
673
    t.info("Cleaning up ...")
 
674
    t.restore_resolv_conf()
 
675
    if getattr(t, 'bind_child', False):
 
676
        t.bind_child.kill()
 
677
 
 
678
 
 
679
if __name__ == '__main__':
 
680
    t = wintest.wintest()
 
681
 
 
682
    t.setup("test-s4-howto.py", "source4")
 
683
 
 
684
    try:
 
685
        test_howto(t)
 
686
    except:
 
687
        if not t.opts.nocleanup:
 
688
            test_cleanup(t)
 
689
        raise
 
690
 
 
691
    if not t.opts.nocleanup:
 
692
        test_cleanup(t)
 
693
    t.info("S4 howto test: All OK")