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')
+ if t.getvar('INTERFACE_IPV6'):
+ 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.chdir('${PREFIX}')
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="::"'
- t.run_cmd('sbin/provision --realm=${LCREALM} --domain=${DOMAIN} --adminpass=${PASSWORD1} --server-role="domain controller"' + options)
+ provision=['sbin/provision',
+ '--realm=${LCREALM}',
+ '--domain=${DOMAIN}',
+ '--adminpass=${PASSWORD1}',
+ '--server-role=domain controller',
+ '--function-level=%s' % func_level,
+ '-d${DEBUGLEVEL}',
+ '--option=interfaces=${INTERFACE}',
+ '--host-ip=${INTERFACE_IP}',
+ '--option=bind interfaces only=yes',
+ '--option=rndc command=${RNDC} -c${PREFIX}/etc/rndc.conf']
+ if t.getvar('INTERFACE_IPV6'):
+ provision.append('--host-ip6=${INTERFACE_IPV6}')
+ t.run_cmd(provision)
t.run_cmd('bin/samba-tool newuser testallowed ${PASSWORD1}')
t.run_cmd('bin/samba-tool newuser testdenied ${PASSWORD1}')
t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
t.run_cmd(['sbin/samba',
'--option', 'panic action=gnome-terminal -e "gdb --pid %PID%"'])
- t.port_wait("localhost", 139)
-
+ t.port_wait("${INTERFACE_IP}", 139)
def test_smbclient(t):
'''test smbclient'''
t.info('Testing smbclient')
t.chdir('${PREFIX}')
t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
- t.retry_cmd('bin/smbclient -L localhost -U%', ["netlogon", "sysvol", "IPC Service"])
- child = t.pexpect_spawn('bin/smbclient //localhost/netlogon -Uadministrator%${PASSWORD1}')
+ t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
+ child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
child.expect("smb:")
child.sendline("dir")
child.expect("blocks available")
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.lstrip().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';
def restore_resolv_conf(t):
'''restore the /etc/resolv.conf after testing is complete'''
if getattr(t, 'resolv_conf_backup', False):
+ t.info("restoring /etc/resolv.conf")
t.run_cmd("mv -f %s /etc/resolv.conf" % t.resolv_conf_backup)
def rndc_cmd(t, cmd, checkfail=True):
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)
+ if t.getvar('INTERFACE_IPV6'):
+ ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
+ else:
+ ipv6_listen = ''
+ t.setvar('BIND_LISTEN_IPV6', ipv6_listen)
+
t.write_file("etc/named.conf", '''
options {
- listen-on port 53 { ${INTERFACE_IP}; };
+ listen-on port 53 { ${INTERFACE_IP}; };
+ ${BIND_LISTEN_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";
t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
- t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
+ t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
t.cmd_contains("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
t.kinit("administrator@${REALM}", "${PASSWORD1}")
+
+ # the first replication will transfer the dnsHostname attribute
+ t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME} CN=Configuration,${BASEDN} -k yes", ["was successful"])
+
for nc in [ '${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}' ]:
- t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
- t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME} %s -k yes" % nc, ["was successful"])
+ t.cmd_contains("bin/samba-tool drs replicate ${HOSTNAME}.${LCREALM} ${WIN_HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
+ t.cmd_contains("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s -k yes" % nc, ["was successful"])
- t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME} -k yes",
+ t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM} -k yes",
[ "INBOUND NEIGHBORS",
"${BASEDN}",
"Last attempt .* was successful",
break
time.sleep(2)
- 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}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['Sharename', 'IPC'])
+ t.retry_cmd("bin/smbclient -L ${HOSTNAME}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['Sharename', 'IPC'])
t.info("Checking propogation of user deletion")
t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
child.expect("The command completed successfully")
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -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}.${LCREALM} -Utest3%${PASSWORD3} -k no", ['LOGON_FAILURE'])
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -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}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
t.vm_poweroff("${WIN_VM}")
t.run_cmd('bin/samba-tool newuser test2 ${PASSWORD2}')
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
- t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME} ${BASEDN} -k yes", ["was successful"])
+ t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN} -k yes", ["was successful"])
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['LOGON_FAILURE'])
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.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}")
def test_cleanup(t):
'''cleanup after tests'''
+ t.info("Cleaning up ...")
restore_resolv_conf(t)
if getattr(t, 'bind_child', False):
t.bind_child.kill()
try:
test_howto(t)
- except Exception, str:
+ except:
if not opts.nocleanup:
test_cleanup(t)
raise