s4:rpc_server: remove unused dcesrv_connection_context->private_date
[samba.git] / wintest / test-s4-howto.py
index 99e11d7..5102387 100755 (executable)
@@ -1,27 +1,23 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 '''automated testing of the steps of the Samba4 HOWTO'''
 
-import sys, os
-import optparse
-import wintest, pexpect, time
+import sys
+import os
+import wintest
+import pexpect
+import time
+import subprocess
 
-def check_prerequesites(t):
-    t.info("Checking prerequesites")
-    t.setvar('HOSTNAME', t.cmd_output("hostname -s").strip())
-    if os.getuid() != 0:
-        raise Exception("You must run this script as root")
+
+def set_krb5_conf(t):
     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):
     '''build samba4'''
     t.info('Building s4')
-    t.chdir('${SOURCETREE}/source4')
+    t.chdir('${SOURCETREE}')
     t.putenv('CC', 'ccache gcc')
     t.run_cmd('make reconfigure || ./configure --enable-auto-reconfigure --enable-developer --prefix=${PREFIX} -C')
     t.run_cmd('make -j')
@@ -35,22 +31,29 @@ def provision_s4(t, func_level="2008"):
     t.chdir('${PREFIX}')
     t.del_files(["var", "private"])
     t.run_cmd("rm -f etc/smb.conf")
-    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']
+    provision = ['bin/samba-tool',
+                 'domain',
+                 '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',
+                 '--dns-backend=${NAMESERVER_BACKEND}',
+                 '${DNS_FORWARDER}']
+    if t.getvar('USE_NTVFS'):
+        provision.append('${USE_NTVFS}')
+
     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 user add testallowed ${PASSWORD1}')
+    t.run_cmd('bin/samba-tool user add testdenied ${PASSWORD1}')
     t.run_cmd('bin/samba-tool group addmembers "Allowed RODC Password Replication Group" testallowed')
 
 
@@ -60,23 +63,18 @@ def start_s4(t):
     t.chdir("${PREFIX}")
     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%"'])
+               '--option', 'panic action=gnome-terminal -e "gdb --pid %d"', '--option', 'max protocol=nt1'])
     t.port_wait("${INTERFACE_IP}", 139)
 
-def stop_vms(t):
-    '''Shut down any existing alive VMs, so they don't collide with what we are doing'''
-    t.info('Shutting down any of our VMs already running')
-    vms = t.get_vms()
-    for v in vms:
-        t.vm_poweroff(v, checkfail=False)
 
 def test_smbclient(t):
-    '''test smbclient'''
+    '''test smbclient against localhost'''
     t.info('Testing smbclient')
+    smbclient = t.getvar("smbclient")
     t.chdir('${PREFIX}')
-    t.cmd_contains("bin/smbclient --version", ["Version 4.0"])
-    t.retry_cmd('bin/smbclient -L ${INTERFACE_IP} -U%', ["netlogon", "sysvol", "IPC Service"])
-    child = t.pexpect_spawn('bin/smbclient //${INTERFACE_IP}/netlogon -Uadministrator%${PASSWORD1}')
+    t.cmd_contains("%s --version" % (smbclient), ["Version 4.1"])
+    t.retry_cmd('%s -L ${INTERFACE_IP} -U%%' % (smbclient), ["netlogon", "sysvol", "IPC Service"])
+    child = t.pexpect_spawn('%s //${INTERFACE_IP}/netlogon -Uadministrator%%${PASSWORD1}' % (smbclient))
     child.expect("smb:")
     child.sendline("dir")
     child.expect("blocks available")
@@ -105,144 +103,16 @@ def create_shares(t):
     t.run_cmd("mkdir -p var/profiles")
 
 
-def set_nameserver(t, nameserver):
-    '''set the nameserver in 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))
-    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):
-    '''run a rndc command'''
-    t.run_cmd("${RNDC} -c ${PREFIX}/etc/rndc.conf %s" % cmd, checkfail=checkfail)
-
-
-def restart_bind(t):
-    '''restart the test environment version of bind'''
-    t.info("Restarting bind9")
-    t.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
-    t.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
-    t.chdir('${PREFIX}')
-
-    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" % 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};  };
-       ${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     { any; };
-       recursion yes;
-       tkey-gssapi-credential "DNS/${HOSTNAME}.${LCREALM}";
-       tkey-domain "${REALM}";
-        max-cache-ttl 10;
-        max-ncache-ttl 10;
-
-       forward only;
-       forwarders {
-                 ${DNSSERVER};
-       };
-
-};
-
-key "rndc-key" {
-       algorithm hmac-md5;
-       secret "lA/cTrno03mt5Ju17ybEYw==";
-};
-controls {
-       inet ${INTERFACE_IP} port 953
-       allow { any; } keys { "rndc-key"; };
-};
-
-include "${PREFIX}/private/named.conf";
-''')
-
-    # add forwarding for the windows domains
-    domains = t.get_domains()
-    for d in domains:
-        t.write_file('etc/named.conf',
-                     '''
-zone "%s" IN {
-      type forward;
-      forward only;
-      forwarders {
-         %s;
-      };
-};
-''' % (d, domains[d]),
-                     mode='a')
-
-
-    t.write_file("etc/rndc.conf", '''
-# Start of rndc.conf
-key "rndc-key" {
-       algorithm hmac-md5;
-       secret "lA/cTrno03mt5Ju17ybEYw==";
-};
-
-options {
-       default-key "rndc-key";
-       default-server  ${INTERFACE_IP};
-       default-port 953;
-};
-''')
-
-    set_nameserver(t, t.getvar('INTERFACE_IP'))
-
-    rndc_cmd(t, "stop", checkfail=False)
-    t.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
-
-    t.run_cmd("rm -rf var/named")
-    t.run_cmd("mkdir -p var/named/data")
-    t.run_cmd("chown -R ${BIND_USER} var/named")
-
-    t.bind_child = t.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
-
-    t.port_wait("${INTERFACE_IP}", 53)
-    rndc_cmd(t, "flush")
-
-
 def test_dns(t):
     '''test that DNS is OK'''
     t.info("Testing DNS")
     t.cmd_contains("host -t SRV _ldap._tcp.${LCREALM}.",
-                 ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
+                   ['_ldap._tcp.${LCREALM} has SRV record 0 100 389 ${HOSTNAME}.${LCREALM}'])
     t.cmd_contains("host -t SRV  _kerberos._udp.${LCREALM}.",
-                 ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
+                   ['_kerberos._udp.${LCREALM} has SRV record 0 100 88 ${HOSTNAME}.${LCREALM}'])
     t.cmd_contains("host -t A ${HOSTNAME}.${LCREALM}",
-                 ['${HOSTNAME}.${LCREALM} has address'])
+                   ['${HOSTNAME}.${LCREALM} has address'])
+
 
 def test_kerberos(t):
     '''test that kerberos is OK'''
@@ -257,40 +127,30 @@ def test_dyndns(t):
     '''test that dynamic DNS is working'''
     t.chdir('${PREFIX}')
     t.run_cmd("sbin/samba_dnsupdate --fail-immediately")
-    rndc_cmd(t, "flush")
+    if not t.getvar('NAMESERVER_BACKEND') == 'SAMBA_INTERNAL':
+        t.rndc_cmd("flush")
 
 
 def run_winjoin(t, vm):
     '''join a windows box to our domain'''
     t.setwinvars(vm)
 
-    t.info("Joining a windows box to the domain")
-    t.vm_poweroff("${WIN_VM}", checkfail=False)
-    t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
-    child.sendline("netdom join ${WIN_HOSTNAME} /Domain:${LCREALM} /PasswordD:${PASSWORD1} /UserD:administrator")
-    child.expect("The command completed successfully")
-    child.expect("C:")
-    child.sendline("shutdown /r -t 0")
-    t.wait_reboot()
-    child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True)
-    child.sendline("ipconfig /registerdns")
-    child.expect("Registration of the DNS resource records for all adapters of this computer has been initiated. Any errors will be reported in the Event Viewer")
-    child.expect("C:")
+    t.run_winjoin(t, "${LCREALM}")
+
 
 def test_winjoin(t, vm):
     t.info("Checking the windows join is OK")
+    smbclient = t.getvar("smbclient")
     t.chdir('${PREFIX}')
     t.port_wait("${WIN_IP}", 139)
-    t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"], retries=100)
+    t.retry_cmd('%s -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"], retries=100)
     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/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
-    t.cmd_contains('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
+    t.cmd_contains('%s -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
+    t.cmd_contains('%s -L ${WIN_HOSTNAME}.${LCREALM} -k no -Utestallowed@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
+    t.cmd_contains('%s -L ${WIN_HOSTNAME}.${LCREALM} -k yes -Utestallowed@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
     child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}")
     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
     child.expect("The command completed successfully")
-    t.vm_poweroff("${WIN_VM}")
 
 
 def run_dcpromo(t, vm):
@@ -298,9 +158,7 @@ def run_dcpromo(t, vm):
     t.setwinvars(vm)
 
     t.info("Joining a windows VM ${WIN_VM} to the domain as a DC using dcpromo")
-    t.vm_poweroff("${WIN_VM}", checkfail=False)
-    t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
+    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True, set_noexpire=True)
     child.sendline("copy /Y con answers.txt")
     child.sendline('''
 [DCINSTALL]
@@ -325,8 +183,13 @@ SafeModeAdminPassword=${PASSWORD1}
     child.expect("C:")
     child.expect("C:")
     child.sendline("dcpromo /answer:answers.txt")
-    i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
+    i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=240)
     if i == 1 or i == 2:
+        child.sendline("echo off")
+        child.sendline("echo START DCPROMO log")
+        child.sendline("more c:\windows\debug\dcpromoui.log")
+        child.sendline("echo END DCPROMO log")
+        child.expect("END DCPROMO")
         raise Exception("dcpromo failed")
     t.wait_reboot()
 
@@ -334,14 +197,15 @@ SafeModeAdminPassword=${PASSWORD1}
 def test_dcpromo(t, vm):
     '''test that dcpromo worked'''
     t.info("Checking the dcpromo join is OK")
+    smbclient = t.getvar("smbclient")
     t.chdir('${PREFIX}')
     t.port_wait("${WIN_IP}", 139)
-    t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${INTERFACE_IP}",
+    t.retry_cmd("host -t A ${WIN_HOSTNAME}.${LCREALM}. ${NAMED_INTERFACE_IP}",
                 ['${WIN_HOSTNAME}.${LCREALM} has address'],
                 retries=30, delay=10, casefold=True)
-    t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
+    t.retry_cmd('%s -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
     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('%s -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
 
     t.cmd_contains("bin/samba-tool drs kcc ${HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
     t.retry_cmd("bin/samba-tool drs kcc ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}", ['Consistency check', 'successful'])
@@ -351,43 +215,43 @@ def test_dcpromo(t, vm):
     # 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}' ]:
+    for nc in ['${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}']:
         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}.${LCREALM} -k yes",
-                 "INBOUND NEIGHBORS",
-                   "${BASEDN}",
-                   "Last attempt .* was successful",
-                   "CN=Configuration,${BASEDN}",
-                   "Last attempt .* was successful",
-                   "CN=Configuration,${BASEDN}", # cope with either order
-                   "Last attempt .* was successful",
-                   "OUTBOUND NEIGHBORS",
-                   "${BASEDN}",
-                   "Last success",
-                   "CN=Configuration,${BASEDN}",
-                   "Last success",
-                   "CN=Configuration,${BASEDN}",
-                   "Last success"],
+                   ["INBOUND NEIGHBORS",
+                    "${BASEDN}",
+                    "Last attempt .* was successful",
+                    "CN=Configuration,${BASEDN}",
+                    "Last attempt .* was successful",
+                    "CN=Configuration,${BASEDN}",  # cope with either order
+                    "Last attempt .* was successful",
+                    "OUTBOUND NEIGHBORS",
+                    "${BASEDN}",
+                    "Last success",
+                    "CN=Configuration,${BASEDN}",
+                    "Last success",
+                    "CN=Configuration,${BASEDN}",
+                    "Last success"],
                    ordered=True,
                    regex=True)
 
     t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${LCREALM} -k yes",
-                 "INBOUND NEIGHBORS",
-                   "${BASEDN}",
-                   "Last attempt .* was successful",
-                   "CN=Configuration,${BASEDN}",
-                   "Last attempt .* was successful",
-                   "CN=Configuration,${BASEDN}",
-                   "Last attempt .* was successful",
-                   "OUTBOUND NEIGHBORS",
-                   "${BASEDN}",
-                   "Last success",
-                   "CN=Configuration,${BASEDN}",
-                   "Last success",
-                   "CN=Configuration,${BASEDN}",
-                   "Last success" ],
+                   ["INBOUND NEIGHBORS",
+                    "${BASEDN}",
+                    "Last attempt .* was successful",
+                    "CN=Configuration,${BASEDN}",
+                    "Last attempt .* was successful",
+                    "CN=Configuration,${BASEDN}",
+                    "Last attempt .* was successful",
+                    "OUTBOUND NEIGHBORS",
+                    "${BASEDN}",
+                    "Last success",
+                    "CN=Configuration,${BASEDN}",
+                    "Last success",
+                    "CN=Configuration,${BASEDN}",
+                    "Last success"],
                    ordered=True,
                    regex=True)
 
@@ -401,7 +265,7 @@ def test_dcpromo(t, vm):
         time.sleep(2)
         child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
         i = child.expect(["The command completed successfully", "The network path was not found"])
-        retries -=1
+        retries -= 1
 
     t.run_net_time(child)
 
@@ -414,12 +278,12 @@ def test_dcpromo(t, vm):
     child.expect("CN=Schema,CN=Configuration,${BASEDN}")
     child.expect("was successful")
 
-    t.info("Checking if new users propogate to windows")
-    t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
+    t.info("Checking if new users propagate to windows")
+    t.retry_cmd('bin/samba-tool user add test2 ${PASSWORD2}', ["created successfully"])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k no" % (smbclient), ['Sharename', 'Remote IPC'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k yes" % (smbclient), ['Sharename', 'Remote IPC'])
 
-    t.info("Checking if new users on windows propogate to samba")
+    t.info("Checking if new users on windows propagate to samba")
     child.sendline("net user test3 ${PASSWORD3} /add")
     while True:
         i = child.expect(["The command completed successfully",
@@ -428,18 +292,18 @@ def test_dcpromo(t, vm):
             break
         time.sleep(2)
 
-    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.retry_cmd("%s -L ${HOSTNAME}.${LCREALM} -Utest3%%${PASSWORD3} -k no" % (smbclient), ['Sharename', 'IPC'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${LCREALM} -Utest3%%${PASSWORD3} -k yes" % (smbclient), ['Sharename', 'IPC'])
 
     t.info("Checking propogation of user deletion")
     t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${LCREALM}%${PASSWORD1}')
     child.sendline("net user test3 /del")
     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}.${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}.${LCREALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k no" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${LCREALM} -Utest3%%${PASSWORD3} -k no" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k yes" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${LCREALM} -Utest3%%${PASSWORD3} -k yes" % (smbclient), ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
@@ -478,23 +342,29 @@ RebootOnCompletion=No
 ''')
     child.expect("copied.")
     child.sendline("dcpromo /answer:answers.txt")
-    i = child.expect(["You must restart this computer", "failed"], timeout=120)
+    i = child.expect(["You must restart this computer", "failed", "could not be located in this domain"], timeout=120)
     if i != 0:
+        child.sendline("echo off")
+        child.sendline("echo START DCPROMO log")
+        child.sendline("more c:\windows\debug\dcpromoui.log")
+        child.sendline("echo END DCPROMO log")
+        child.expect("END DCPROMO")
         raise Exception("dcpromo failed")
     child.sendline("shutdown -r -t 0")
     t.wait_reboot()
 
 
-
 def test_dcpromo_rodc(t, vm):
     '''test the RODC dcpromo worked'''
     t.info("Checking the w2k8 RODC join is OK")
+    smbclient = t.getvar("smbclient")
     t.chdir('${PREFIX}')
     t.port_wait("${WIN_IP}", 139)
-    t.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%${PASSWORD1}', ["C$", "IPC$", "Sharename"])
-    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"])
     child = t.open_telnet("${WIN_HOSTNAME}", "${DOMAIN}\\administrator", "${PASSWORD1}", set_time=True)
+    child.sendline("ipconfig /registerdns")
+    t.retry_cmd('%s -L ${WIN_HOSTNAME}.${LCREALM} -Uadministrator@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
+    t.cmd_contains("host -t A ${WIN_HOSTNAME}.${LCREALM}.", ['has address'])
+    t.cmd_contains('%s -L ${WIN_HOSTNAME}.${LCREALM} -Utestallowed@${LCREALM}%%${PASSWORD1}' % (smbclient), ["C$", "IPC$", "Sharename"])
     child.sendline("net use t: \\\\${HOSTNAME}.${LCREALM}\\test")
     child.expect("The command completed successfully")
 
@@ -507,48 +377,62 @@ def test_dcpromo_rodc(t, vm):
     child.expect("CN=Configuration,${BASEDN}")
     child.expect("was successful")
 
+    for nc in ['${BASEDN}', 'CN=Configuration,${BASEDN}', 'CN=Schema,CN=Configuration,${BASEDN}']:
+        t.cmd_contains("bin/samba-tool drs replicate --add-ref ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} %s" % nc, ["was successful"])
+
+    t.cmd_contains("bin/samba-tool drs showrepl ${HOSTNAME}.${LCREALM}",
+                   ["INBOUND NEIGHBORS",
+                    "OUTBOUND NEIGHBORS",
+                    "${BASEDN}",
+                    "Last attempt.*was successful",
+                    "CN=Configuration,${BASEDN}",
+                    "Last attempt.*was successful",
+                    "CN=Configuration,${BASEDN}",
+                    "Last attempt.*was successful"],
+                   ordered=True,
+                   regex=True)
+
     t.info("Checking if new users are available on windows")
-    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}.${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 add test2 ${PASSWORD2}')
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k yes" % (smbclient), ['Sharename', 'Remote IPC'])
+    t.retry_cmd("bin/samba-tool drs replicate ${WIN_HOSTNAME}.${LCREALM} ${HOSTNAME}.${LCREALM} ${BASEDN}", ["was successful"])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k no" % (smbclient), ['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.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%${PASSWORD2} -k no", ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k yes" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${LCREALM} -Utest2%%${PASSWORD2} -k no" % (smbclient), ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
 def prep_join_as_dc(t, vm):
     '''start VM and shutdown Samba in preperation to join a windows domain as a DC'''
-    t.setwinvars(vm)
-    t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool join DC")
+    t.info("Starting VMs for joining ${WIN_VM} as a second DC using samba-tool domain join DC")
     t.chdir('${PREFIX}')
     t.run_cmd('killall -9 -q samba smbd nmbd winbindd', checkfail=False)
-    t.vm_poweroff("${WIN_VM}", checkfail=False)
-    t.vm_restore("${WIN_VM}", "${WIN_SNAPSHOT}")
-    rndc_cmd(t, 'flush')
+    if not t.getvar('NAMESERVER_BACKEND') == 'SAMBA_INTERNAL':
+        t.rndc_cmd('flush')
     t.run_cmd("rm -rf etc/smb.conf private")
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
     t.get_ipconfig(child)
 
+
 def join_as_dc(t, vm):
     '''join a windows domain as a DC'''
     t.setwinvars(vm)
-    t.info("Joining ${WIN_VM} as a second DC using samba-tool join DC")
+    t.info("Joining ${WIN_VM} as a second DC using samba-tool domain join DC")
     t.port_wait("${WIN_IP}", 389)
-    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
+    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'])
 
-    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.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'])
+    t.run_cmd('bin/samba-tool domain join ${WIN_REALM} DC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
     t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
 
 def test_join_as_dc(t, vm):
     '''test the join of a windows domain as a DC'''
     t.info("Checking the DC join is OK")
+    smbclient = t.getvar("smbclient")
     t.chdir('${PREFIX}')
-    t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
+    t.retry_cmd('%s -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%%${WIN_PASS}' % (smbclient), ["C$", "IPC$", "Sharename"])
     t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
@@ -557,10 +441,13 @@ def test_join_as_dc(t, vm):
     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}' ]:
+    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_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("ipconfig /flushdns")
+    child.expect("Successfully flushed")
+
     retries = 10
     i = 1
     while i == 1 and retries > 0:
@@ -569,7 +456,7 @@ def test_join_as_dc(t, vm):
         child.expect("C:")
         if i == 1:
             time.sleep(2)
-        retries -=1
+        retries -= 1
 
     t.info("Checking if showrepl is happy")
     child.sendline("repadmin /showrepl")
@@ -580,45 +467,49 @@ def test_join_as_dc(t, vm):
     child.expect("CN=Configuration,${WIN_BASEDN}")
     child.expect("was successful")
 
-    t.info("Checking if new users propogate to windows")
-    t.retry_cmd('bin/samba-tool newuser test2 ${PASSWORD2}', ["created successfully"])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k no", ['Sharename', 'Remote IPC'])
-    t.retry_cmd("bin/smbclient -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%${PASSWORD2} -k yes", ['Sharename', 'Remote IPC'])
+    t.info("Checking if new users propagate to windows")
+    t.retry_cmd('bin/samba-tool user add test2 ${PASSWORD2}', ["created successfully"])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%%${PASSWORD2} -k no" % (smbclient), ['Sharename', 'Remote IPC'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%%${PASSWORD2} -k yes" % (smbclient), ['Sharename', 'Remote IPC'])
 
-    t.info("Checking if new users on windows propogate to samba")
+    t.info("Checking if new users on windows propagate to samba")
     child.sendline("net user test3 ${PASSWORD3} /add")
     child.expect("The command completed successfully")
-    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.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k no" % (smbclient), ['Sharename', 'IPC'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k yes" % (smbclient), ['Sharename', 'IPC'])
 
     t.info("Checking propogation of user deletion")
     t.run_cmd('bin/samba-tool user delete test2 -Uadministrator@${WIN_REALM}%${WIN_PASS}')
     child.sendline("net user test3 /del")
     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}.${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}.${WIN_REALM} -Utest3%${PASSWORD3} -k yes", ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%%${PASSWORD2} -k no" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k no" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${WIN_HOSTNAME}.${WIN_REALM} -Utest2%%${PASSWORD2} -k yes" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k yes" % (smbclient), ['LOGON_FAILURE'])
+
+    t.run_cmd('bin/samba-tool domain demote -Uadministrator@${WIN_REALM}%${WIN_PASS}')
+
     t.vm_poweroff("${WIN_VM}")
 
 
 def join_as_rodc(t, vm):
     '''join a windows domain as a RODC'''
     t.setwinvars(vm)
-    t.info("Joining ${WIN_VM} as a RODC using samba-tool join DC")
+    t.info("Joining ${WIN_VM} as a RODC using samba-tool domain join DC")
     t.port_wait("${WIN_IP}", 389)
-    t.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
-    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.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'])
+    t.retry_cmd("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator%${WIN_PASS}", ['INBOUND NEIGHBORS'])
+    t.run_cmd('bin/samba-tool domain join ${WIN_REALM} RODC -Uadministrator%${WIN_PASS} -d${DEBUGLEVEL} --option=interfaces=${INTERFACE}')
     t.run_cmd('bin/samba-tool drs kcc ${WIN_HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}')
 
 
 def test_join_as_rodc(t, vm):
     '''test a windows domain RODC join'''
     t.info("Checking the RODC join is OK")
+    smbclient = t.getvar("smbclient")
     t.chdir('${PREFIX}')
-    t.retry_cmd('bin/smbclient -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%${WIN_PASS}', ["C$", "IPC$", "Sharename"])
+    t.retry_cmd('%s -L ${HOSTNAME}.${WIN_REALM} -Uadministrator@${WIN_REALM}%%${WIN_PASS}' % (smbclient), ["C$", "IPC$", "Sharename"])
     t.cmd_contains("host -t A ${HOSTNAME}.${WIN_REALM}.", ['has address'])
     child = t.open_telnet("${WIN_HOSTNAME}", "${WIN_DOMAIN}\\administrator", "${WIN_PASS}", set_time=True)
 
@@ -627,7 +518,7 @@ def test_join_as_rodc(t, vm):
     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}' ]:
+    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_REALM} ${WIN_HOSTNAME}.${WIN_REALM} %s -k yes" % nc, ["was successful"])
 
     retries = 10
@@ -638,120 +529,82 @@ def test_join_as_rodc(t, vm):
         child.expect("C:")
         if i == 1:
             time.sleep(2)
-        retries -=1
+        retries -= 1
 
     t.info("Checking if showrepl is happy")
     child.sendline("repadmin /showrepl")
     child.expect("DSA invocationID")
 
     t.cmd_contains("bin/samba-tool drs showrepl ${WIN_HOSTNAME}.${WIN_REALM} -k yes",
-                 "INBOUND NEIGHBORS",
-                   "OUTBOUND NEIGHBORS",
-                   "${WIN_BASEDN}",
-                   "Last attempt .* was successful",
-                   "CN=Configuration,${WIN_BASEDN}",
-                   "Last attempt .* was successful",
-                   "CN=Configuration,${WIN_BASEDN}",
-                   "Last attempt .* was successful" ],
+                   ["INBOUND NEIGHBORS",
+                    "OUTBOUND NEIGHBORS",
+                    "${WIN_BASEDN}",
+                    "Last attempt .* was successful",
+                    "CN=Configuration,${WIN_BASEDN}",
+                    "Last attempt .* was successful",
+                    "CN=Configuration,${WIN_BASEDN}",
+                    "Last attempt .* was successful"],
                    ordered=True,
                    regex=True)
 
-    t.info("Checking if new users on windows propogate to samba")
+    t.info("Checking if new users on windows propagate to samba")
     child.sendline("net user test3 ${PASSWORD3} /add")
     child.expect("The command completed successfully")
-    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.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k no" % (smbclient), ['Sharename', 'IPC'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k yes" % (smbclient), ['Sharename', 'IPC'])
 
     # should this work?
-    t.info("Checking if new users propogate to windows")
-    t.cmd_contains('bin/samba-tool newuser test2 ${PASSWORD2}', ['No RID Set DN'])
+    t.info("Checking if new users propagate to windows")
+    t.cmd_contains('bin/samba-tool user add test2 ${PASSWORD2}', ['No RID Set DN'])
 
     t.info("Checking propogation of user deletion")
     child.sendline("net user test3 /del")
     child.expect("The command completed successfully")
 
-    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.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k no" % (smbclient), ['LOGON_FAILURE'])
+    t.retry_cmd("%s -L ${HOSTNAME}.${WIN_REALM} -Utest3%%${PASSWORD3} -k yes" % (smbclient), ['LOGON_FAILURE'])
     t.vm_poweroff("${WIN_VM}")
 
 
-def run_dcpromo_as_first_dc(t, vm, func_level=None):
-    t.setwinvars(vm)
-    t.info("Configuring a windows VM ${WIN_VM} at the first DC in the domain using dcpromo")
-    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_time=True)
-    child.sendline("dcdiag");
-    if t.get_is_dc(child):
-        return
-
-    if func_level == '2008r2':
-        t.setvar("FUNCTION_LEVEL_INT", str(4))
-    elif func_level == '2003':
-        t.setvar("FUNCTION_LEVEL_INT", str(1))
-    else:
-        t.setvar("FUNCTION_LEVEL_INT", str(0))
-
-    child = t.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}", set_ip=True)
-    child.sendline("dcdiag");
-
-    """This server must therefore not yet be a directory server, so we must promote it"""
-    child.sendline("copy /Y con answers.txt")
-    child.sendline('''
-[DCInstall]
-; New forest promotion
-ReplicaOrNewDomain=Domain
-NewDomain=Forest
-NewDomainDNSName=${WIN_REALM}
-ForestLevel=${FUNCTION_LEVEL_INT}
-DomainNetbiosName=${WIN_DOMAIN}
-DomainLevel=${FUNCTION_LEVEL_INT}
-InstallDNS=Yes
-ConfirmGc=Yes
-CreateDNSDelegation=No
-DatabasePath="C:\Windows\NTDS"
-LogPath="C:\Windows\NTDS"
-SYSVOLPath="C:\Windows\SYSVOL"
-; Set SafeModeAdminPassword to the correct value prior to using the unattend file
-SafeModeAdminPassword=${WIN_PASS}
-; Run-time flags (optional)
-RebootOnCompletion=No
-\1a
-''')
-    child.expect("copied.")
-    child.expect("C:")
-    child.expect("C:")
-    child.sendline("dcpromo /answer:answers.txt")
-    i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=120)
-    if i == 1 or i == 2:
-        raise Exception("dcpromo failed")
-    child.sendline("shutdown -r -t 0")
-    t.port_wait("${WIN_IP}", 139, wait_for_fail=True)
-    t.port_wait("${WIN_IP}", 139)
-
 def test_howto(t):
     '''test the Samba4 howto'''
 
-    check_prerequesites(t)
+    t.setvar("SAMBA_VERSION", "Version 4")
+    t.setvar("smbclient", "bin/smbclient4")
+    t.check_prerequesites()
 
     # we don't need fsync safety in these tests
     t.putenv('TDB_NO_FSYNC', '1')
 
+    if not t.skip("configure_bind"):
+        t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
+    if not t.skip("stop_bind"):
+        t.stop_bind()
+
+    if not t.skip("stop_vms"):
+        t.stop_vms()
+
     if not t.skip("build"):
         build_s4(t)
 
     if not t.skip("provision"):
         provision_s4(t)
 
+    set_krb5_conf(t)
+
     if not t.skip("create-shares"):
         create_shares(t)
 
     if not t.skip("starts4"):
         start_s4(t)
-    if not t.skip("stop_vms"):
-        stop_vms(t)
     if not t.skip("smbclient"):
         test_smbclient(t)
-    if not t.skip("startbind"):
-        restart_bind(t)
+
+    if not t.skip("configure_bind2"):
+        t.configure_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
+    if not t.skip("start_bind"):
+        t.start_bind()
+
     if not t.skip("dns"):
         test_dns(t)
     if not t.skip("kerberos"):
@@ -760,25 +613,44 @@ def test_howto(t):
         test_dyndns(t)
 
     if t.have_vm('WINDOWS7') and not t.skip("windows7"):
+        t.start_winvm("WINDOWS7")
+        t.test_remote_smbclient("WINDOWS7")
         run_winjoin(t, "WINDOWS7")
         test_winjoin(t, "WINDOWS7")
+        t.vm_poweroff("${WIN_VM}")
 
     if t.have_vm('WINXP') and not t.skip("winxp"):
+        t.start_winvm("WINXP")
         run_winjoin(t, "WINXP")
         test_winjoin(t, "WINXP")
+        t.test_remote_smbclient("WINXP", "administrator", "${PASSWORD1}")
+        t.vm_poweroff("${WIN_VM}")
+
+    if t.have_vm('W2K3C') and not t.skip("win2k3_member"):
+        t.start_winvm("W2K3C")
+        run_winjoin(t, "W2K3C")
+        test_winjoin(t, "W2K3C")
+        t.test_remote_smbclient("W2K3C", "administrator", "${PASSWORD1}")
+        t.vm_poweroff("${WIN_VM}")
 
     if t.have_vm('W2K8R2C') and not t.skip("dcpromo_rodc"):
         t.info("Testing w2k8r2 RODC dcpromo")
+        t.start_winvm("W2K8R2C")
+        t.test_remote_smbclient('W2K8R2C')
         run_dcpromo_rodc(t, "W2K8R2C")
         test_dcpromo_rodc(t, "W2K8R2C")
 
     if t.have_vm('W2K8R2B') and not t.skip("dcpromo_w2k8r2"):
         t.info("Testing w2k8r2 dcpromo")
+        t.start_winvm("W2K8R2B")
+        t.test_remote_smbclient('W2K8R2B')
         run_dcpromo(t, "W2K8R2B")
         test_dcpromo(t, "W2K8R2B")
 
     if t.have_vm('W2K8B') and not t.skip("dcpromo_w2k8"):
         t.info("Testing w2k8 dcpromo")
+        t.start_winvm("W2K8B")
+        t.test_remote_smbclient('W2K8B')
         run_dcpromo(t, "W2K8B")
         test_dcpromo(t, "W2K8B")
 
@@ -789,16 +661,19 @@ def test_howto(t):
         create_shares(t)
         start_s4(t)
         test_smbclient(t)
-        restart_bind(t)
+        t.restart_bind(kerberos_support=True, include='${PREFIX}/private/named.conf')
         test_dns(t)
         test_kerberos(t)
         test_dyndns(t)
+        t.start_winvm("W2K3B")
+        t.test_remote_smbclient('W2K3B')
         run_dcpromo(t, "W2K3B")
         test_dcpromo(t, "W2K3B")
 
     if t.have_vm('W2K8R2A') and not t.skip("join_w2k8r2"):
+        t.start_winvm("W2K8R2A")
         prep_join_as_dc(t, "W2K8R2A")
-        run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
+        t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
         join_as_dc(t, "W2K8R2A")
         create_shares(t)
         start_s4(t)
@@ -806,8 +681,9 @@ def test_howto(t):
         test_join_as_dc(t, "W2K8R2A")
 
     if t.have_vm('W2K8R2A') and not t.skip("join_rodc"):
+        t.start_winvm("W2K8R2A")
         prep_join_as_dc(t, "W2K8R2A")
-        run_dcpromo_as_first_dc(t, "W2K8R2A", func_level='2008r2')
+        t.run_dcpromo_as_first_dc("W2K8R2A", func_level='2008r2')
         join_as_rodc(t, "W2K8R2A")
         create_shares(t)
         start_s4(t)
@@ -815,8 +691,9 @@ def test_howto(t):
         test_join_as_rodc(t, "W2K8R2A")
 
     if t.have_vm('W2K3A') and not t.skip("join_w2k3"):
+        t.start_winvm("W2K3A")
         prep_join_as_dc(t, "W2K3A")
-        run_dcpromo_as_first_dc(t, "W2K3A", func_level='2003')
+        t.run_dcpromo_as_first_dc("W2K3A", func_level='2003')
         join_as_dc(t, "W2K3A")
         create_shares(t)
         start_s4(t)
@@ -829,61 +706,23 @@ def test_howto(t):
 def test_cleanup(t):
     '''cleanup after tests'''
     t.info("Cleaning up ...")
-    restore_resolv_conf(t)
+    t.restore_resolv_conf()
     if getattr(t, 'bind_child', False):
         t.bind_child.kill()
 
 
 if __name__ == '__main__':
-    parser = optparse.OptionParser("test-howto.py")
-    parser.add_option("--conf", type='string', default='', help='config file')
-    parser.add_option("--skip", type='string', default='', help='list of steps to skip (comma separated)')
-    parser.add_option("--vms", type='string', default=None, help='list of VMs to use (comma separated)')
-    parser.add_option("--list", action='store_true', default=False, help='list the available steps')
-    parser.add_option("--rebase", action='store_true', default=False, help='do a git pull --rebase')
-    parser.add_option("--clean", action='store_true', default=False, help='clean the tree')
-    parser.add_option("--prefix", type='string', default=None, help='override install prefix')
-    parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
-    parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
-
-    opts, args = parser.parse_args()
-
-    if not opts.conf:
-        print("Please specify a config file with --conf")
-        sys.exit(1)
-
     t = wintest.wintest()
-    t.load_config(opts.conf)
-
-    t.set_skip(opts.skip)
-    t.set_vms(opts.vms)
-
-    if opts.list:
-        t.list_steps_mode()
-
-    if opts.prefix:
-        t.setvar('PREFIX', opts.prefix)
-
-    if opts.sourcetree:
-        t.setvar('SOURCETREE', opts.sourcetree)
-
-    if opts.rebase:
-        t.info('rebasing')
-        t.chdir('${SOURCETREE}')
-        t.run_cmd('git pull --rebase')
 
-    if opts.clean:
-        t.info('rebasing')
-        t.chdir('${SOURCETREE}/source4')
-        t.run_cmd('rm -rf bin')
+    t.setup("test-s4-howto.py", "source4")
 
     try:
         test_howto(t)
     except:
-        if not opts.nocleanup:
+        if not t.opts.nocleanup:
             test_cleanup(t)
         raise
 
-    if not opts.nocleanup:
+    if not t.opts.nocleanup:
         test_cleanup(t)
     t.info("S4 howto test: All OK")