import sys, os
import optparse
-import wintest
+import wintest, pexpect
def check_prerequesites(t):
t.info("Checking prerequesites")
raise Exception("You must run this script as root")
t.putenv("KRB5_CONFIG", '${PREFIX}/private/krb5.conf')
t.run_cmd('ifconfig ${INTERFACE} ${INTERFACE_NET} up')
+ t.run_cmd('ifconfig ${INTERFACE} inet6 del ${INTERFACE_IPV6}/64', checkfail=False)
+ t.run_cmd('ifconfig ${INTERFACE} inet6 add ${INTERFACE_IPV6}/64 up')
def build_s4(t):
t.del_files(["var", "private"])
t.run_cmd("rm -f etc/smb.conf")
options=' --function-level=%s -d${DEBUGLEVEL}' % func_level
- options += ' --option=interfaces=${INTERFACE}'
- options += ' --host-ip=${INTERFACE_IP} --host-ip6="::"'
+ options += ' --option=interfaces="${INTERFACE} ${INTERFACE_IPV6}"'
+ options += ' --host-ip=${INTERFACE_IP} --host-ip6=${INTERFACE_IPV6}'
options += ' --option=bindinterfacesonly=yes'
t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
def set_nameserver(t, nameserver):
'''set the nameserver in resolv.conf'''
- if not getattr(t, 'resolv_conf_backup', False):
- t.run_cmd("mv -f /etc/resolv.conf /etc/resolv.conf.wintest-bak")
- t.write_file("/etc/resolv.conf", '''
+ t.write_file("/etc/resolv.conf.wintest", '''
# Generated by wintest, the Samba v Windows automated testing system
nameserver %s
# your original resolv.conf appears below:
''' % t.substitute(nameserver))
- t.run_cmd('cat /etc/resolv.conf.wintest-bak >> /etc/resolv.conf')
+ child = t.pexpect_spawn("cat /etc/resolv.conf", crlf=False)
+ i = child.expect(['your original resolv.conf appears below:', pexpect.EOF])
+ if i == 0:
+ child.expect(pexpect.EOF)
+ contents = child.before.replace('\r', '')
+ t.write_file('/etc/resolv.conf.wintest', contents, mode='a')
+ t.write_file('/etc/resolv.conf.wintest-bak', contents)
+ t.run_cmd("mv -f /etc/resolv.conf.wintest /etc/resolv.conf")
t.resolv_conf_backup = '/etc/resolv.conf.wintest-bak';
nameserver = t.get_nameserver()
if nameserver == t.getvar('INTERFACE_IP'):
- raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration")
+ raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
t.setvar('DNSSERVER', nameserver)
t.write_file("etc/named.conf", '''
options {
- listen-on port 53 { ${INTERFACE_IP}; };
+ listen-on port 53 { ${INTERFACE_IP}; };
+ listen-on-v6 port 53 { ${INTERFACE_IPV6}; };
directory "${PREFIX}/var/named";
dump-file "${PREFIX}/var/named/data/cache_dump.db";
pid-file "${PREFIX}/var/named/named.pid";
statistics-file "${PREFIX}/var/named/data/named_stats.txt";
memstatistics-file "${PREFIX}/var/named/data/named_mem_stats.txt";
- allow-query { ${INTERFACE_NET}; 127.0.0.0/8; };
+ allow-query { any; };
recursion yes;
- tkey-gssapi-credential "DNS/${LCREALM}";
+ tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
tkey-domain "${REALM}";
+ max-cache-ttl 10;
+ max-ncache-ttl 10;
forward only;
forwarders {
controls {
inet ${INTERFACE_IP} port 953
- allow { 127.0.0.0/8; ${INTERFACE_NET}; } keys { "rndc-key"; };
+ allow { any; } keys { "rndc-key"; };
};
include "${PREFIX}/private/named.conf";
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
t.get_ipconfig(child)
t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
- t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
+ t.run_cmd('bin/samba-tool join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces="${INTERFACE} ${INTERFACE_IPV6"')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
t.info("Forcing kcc runs, and replication")
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
- t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+ t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
- t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
- t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
+ t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
+ t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${WIN_REALM} ${HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
child.expect("The command completed successfully")
t.info("Checking if new users on windows propogate to samba")
child.sendline("net user test3 ${PASSWORD3} /add")
child.expect("The command completed successfully")
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
t.info("Checking propogation of user deletion")
t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
child.expect("The command completed successfully")
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
t.vm_poweroff("${WIN_VM}")
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
t.get_ipconfig(child)
t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'] )
- t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
+ t.run_cmd('bin/samba-tool join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces="${INTERFACE} ${INTERFACE_IPV6}"')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
t.info("Forcing kcc runs, and replication")
- t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+ t.run_cmd('bin/samba-tool drs kcc ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
t.kinit("administrator@${WIN_REALM}", "${WIN_PASS}")
for nc in [ '${WIN_BASEDN}', 'CN=Configuration,${WIN_BASEDN}', 'CN=Schema,CN=Configuration,${WIN_BASEDN}' ]:
- t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
+ t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${WIN_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
child.sendline("net use t: \\\\${HOSTNAME}.${WIN_REALM}\\test")
child.expect("The command completed successfully")
t.info("Checking if new users on windows propogate to samba")
child.sendline("net user test3 ${PASSWORD3} /add")
child.expect("The command completed successfully")
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
# should this work?
t.info("Checking if new users propogate to windows")
child.sendline("net user test3 /del")
child.expect("The command completed successfully")
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
- t.retry_cmd("bin/smbclient -L ${HOSTNAME} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
t.vm_poweroff("${WIN_VM}")
f.close()
def run_cmd(self, cmd, dir=".", show=None, output=False, checkfail=True):
+ '''run a command'''
cmd = self.substitute(cmd)
if isinstance(cmd, list):
self.info('$ ' + " ".join(cmd))
else:
return subprocess.call(cmd, shell=shell, cwd=dir)
+
def run_child(self, cmd, dir="."):
+ '''create a child and return the Popen handle to it'''
cwd = os.getcwd()
cmd = self.substitute(cmd)
if isinstance(cmd, list):
else:
shell=True
os.chdir(dir)
- ret = subprocess.Popen(cmd, shell=shell)
+ ret = subprocess.Popen(cmd, shell=shell, stderr=subprocess.STDOUT)
os.chdir(cwd)
return ret
retries = retries - 1
raise RuntimeError("Failed to find %s" % contains)
- def pexpect_spawn(self, cmd, timeout=60):
+ def pexpect_spawn(self, cmd, timeout=60, crlf=True):
'''wrapper around pexpect spawn'''
cmd = self.substitute(cmd)
self.info("$ " + cmd)
line = self.substitute(line)
return ret.old_expect(line, timeout=timeout)
- ret.old_sendline = ret.sendline
- ret.sendline = sendline_sub
+ if crlf:
+ ret.old_sendline = ret.sendline
+ ret.sendline = sendline_sub
ret.old_expect = ret.expect
ret.expect = expect_sub
def get_nameserver(self):
'''Get the current nameserver from /etc/resolv.conf'''
- child = self.pexpect_spawn('cat /etc/resolv.conf')
- child.expect('nameserver')
+ child = self.pexpect_spawn('cat /etc/resolv.conf', crlf=False)
+ i = child.expect(['Generated by wintest', 'nameserver'])
+ if i == 0:
+ child.expect('your original resolv.conf')
+ child.expect('nameserver')
child.expect('\d+.\d+.\d+.\d+')
return child.after