Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/wintest/wintest.py

    r740 r988  
    2626            self.run_cmd('ifconfig ${INTERFACE} inet6 del ${INTERFACE_IPV6}/64', checkfail=False)
    2727            self.run_cmd('ifconfig ${INTERFACE} inet6 add ${INTERFACE_IPV6}/64 up')
     28
     29        self.run_cmd('ifconfig ${NAMED_INTERFACE} ${NAMED_INTERFACE_NET} up')
     30        if self.getvar('NAMED_INTERFACE_IPV6'):
     31            self.run_cmd('ifconfig ${NAMED_INTERFACE} inet6 del ${NAMED_INTERFACE_IPV6}/64', checkfail=False)
     32            self.run_cmd('ifconfig ${NAMED_INTERFACE} inet6 add ${NAMED_INTERFACE_IPV6}/64 up')
    2833
    2934    def stop_vms(self):
     
    326331        self.chdir('${PREFIX}')
    327332
    328         nameserver = self.get_nameserver()
    329         if nameserver == self.getvar('INTERFACE_IP'):
    330             raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
    331         self.setvar('DNSSERVER', nameserver)
    332 
    333         if self.getvar('INTERFACE_IPV6'):
    334             ipv6_listen = 'listen-on-v6 port 53 { ${INTERFACE_IPV6}; };'
     333        if self.getvar('NAMED_INTERFACE_IPV6'):
     334            ipv6_listen = 'listen-on-v6 port 53 { ${NAMED_INTERFACE_IPV6}; };'
    335335        else:
    336336            ipv6_listen = ''
     
    339339        if not kerberos_support:
    340340            self.setvar("NAMED_TKEY_OPTION", "")
    341         else:
     341        elif self.getvar('NAMESERVER_BACKEND') != 'SAMBA_INTERNAL':
    342342            if self.named_supports_gssapi_keytab():
    343343                self.setvar("NAMED_TKEY_OPTION",
     
    351351            self.putenv('KEYTAB_FILE', '${PREFIX}/private/dns.keytab')
    352352            self.putenv('KRB5_KTNAME', '${PREFIX}/private/dns.keytab')
    353 
    354         if include:
     353        else:
     354            self.setvar("NAMED_TKEY_OPTION", "")
     355
     356        if include and self.getvar('NAMESERVER_BACKEND') != 'SAMBA_INTERNAL':
    355357            self.setvar("NAMED_INCLUDE", 'include "%s";' % include)
    356358        else:
     
    361363        self.write_file("etc/named.conf", '''
    362364options {
    363         listen-on port 53 { ${INTERFACE_IP};  };
     365        listen-on port 53 { ${NAMED_INTERFACE_IP};  };
    364366        ${BIND_LISTEN_IPV6}
    365367        directory       "${PREFIX}/var/named";
     
    387389
    388390controls {
    389         inet ${INTERFACE_IP} port 953
     391        inet ${NAMED_INTERFACE_IP} port 953
    390392        allow { any; } keys { "rndc-key"; };
    391393};
     
    393395${NAMED_INCLUDE}
    394396''')
     397       
     398        if self.getvar('NAMESERVER_BACKEND') == 'SAMBA_INTERNAL':
     399              self.write_file('etc/named.conf',
     400                         '''
     401zone "%s" IN {
     402      type forward;
     403      forward only;
     404      forwarders {
     405         %s;
     406      };
     407};
     408''' % (self.getvar('LCREALM'), self.getvar('INTERFACE_IP')),
     409                     mode='a')
     410         
    395411
    396412        # add forwarding for the windows domains
    397413        domains = self.get_domains()
     414
    398415        for d in domains:
    399416            self.write_file('etc/named.conf',
     
    419436options {
    420437        default-key "rndc-key";
    421         default-server  ${INTERFACE_IP};
     438        default-server  ${NAMED_INTERFACE_IP};
    422439        default-port 953;
    423440};
     
    428445        '''Stop our private BIND from listening and operating'''
    429446        self.rndc_cmd("stop", checkfail=False)
    430         self.port_wait("${INTERFACE_IP}", 53, wait_for_fail=True)
     447        self.port_wait("${NAMED_INTERFACE_IP}", 53, wait_for_fail=True)
    431448
    432449        self.run_cmd("rm -rf var/named")
     
    438455        self.chdir('${PREFIX}')
    439456
    440         self.set_nameserver(self.getvar('INTERFACE_IP'))
     457        self.set_nameserver(self.getvar('NAMED_INTERFACE_IP'))
    441458
    442459        self.run_cmd("mkdir -p var/named/data")
     
    445462        self.bind_child = self.run_child("${BIND9} -u ${BIND_USER} -n 1 -c ${PREFIX}/etc/named.conf -g")
    446463
    447         self.port_wait("${INTERFACE_IP}", 53)
     464        self.port_wait("${NAMED_INTERFACE_IP}", 53)
    448465        self.rndc_cmd("flush")
    449466
     
    492509    def port_wait(self, hostname, port, retries=200, delay=3, wait_for_fail=False):
    493510        '''wait for a host to come up on the network'''
    494         self.retry_cmd("nc -v -z -w 1 %s %u" % (hostname, port), ['succeeded'],
    495                        retries=retries, delay=delay, wait_for_fail=wait_for_fail)
     511
     512        while retries > 0:
     513            child = self.pexpect_spawn("nc -v -z -w 1 %s %u" % (hostname, port), crlf=False, timeout=1)
     514            child.expect([pexpect.EOF, pexpect.TIMEOUT])
     515            child.close()
     516            i = child.exitstatus
     517            if wait_for_fail:
     518                #wait for timeout or fail
     519                if i == None or i > 0:
     520                    return
     521            else:
     522                if i == 0:
     523                    return
     524
     525            time.sleep(delay)
     526            retries -= 1
     527            self.info("retrying (retries=%u delay=%u)" % (retries, delay))
     528
     529        raise RuntimeError("gave up waiting for %s:%d" % (hostname, port))
    496530
    497531    def run_net_time(self, child):
     
    532566        self.setvar('WIN_SUBNET_MASK', child.after)
    533567        child.expect('Default Gateway')
    534         child.expect('\d+.\d+.\d+.\d+')
    535         self.setvar('WIN_DEFAULT_GATEWAY', child.after)
    536         child.expect("C:")
     568        i = child.expect(['\d+.\d+.\d+.\d+', "C:"])
     569        if i == 0:
     570            self.setvar('WIN_DEFAULT_GATEWAY', child.after)
     571            child.expect("C:")
    537572
    538573    def get_is_dc(self, child):
    539574        '''check if a windows machine is a domain controller'''
    540575        child.sendline("dcdiag")
    541         i = child.expect(["is not a Directory Server",
     576        i = child.expect(["is not a [Directory Server|DC]",
    542577                          "is not recognized as an internal or external command",
    543578                          "Home Server = ",
     
    564599
    565600    def set_noexpire(self, child, username):
    566         '''Ensure this user's password does not expire'''
     601        """Ensure this user's password does not expire"""
    567602        child.sendline('wmic useraccount where name="%s" set PasswordExpires=FALSE' % username)
    568603        child.expect("update successful")
     
    572607        '''remove the annoying telnet restrictions'''
    573608        child.sendline('tlntadmn config maxconn=1024')
    574         child.expect("The settings were successfully updated")
     609        child.expect(["The settings were successfully updated", "Access is denied"])
    575610        child.expect("C:")
    576611
     
    578613        '''remove the annoying firewall'''
    579614        child.sendline('netsh advfirewall set allprofiles state off')
    580         i = child.expect(["Ok", "The following command was not found: advfirewall set allprofiles state off"])
     615        i = child.expect(["Ok", "The following command was not found: advfirewall set allprofiles state off", "The requested operation requires elevation", "Access is denied"])
    581616        child.expect("C:")
    582617        if i == 1:
    583618            child.sendline('netsh firewall set opmode mode = DISABLE profile = ALL')
    584             i = child.expect(["Ok", "The following command was not found"])
     619            i = child.expect(["Ok", "The following command was not found", "Access is denied"])
    585620            if i != 0:
    586621                self.info("Firewall disable failed - ignoring")
     
    588623
    589624    def set_dns(self, child):
    590         child.sendline('netsh interface ip set dns "${WIN_NIC}" static ${INTERFACE_IP} primary')
     625        child.sendline('netsh interface ip set dns "${WIN_NIC}" static ${NAMED_INTERFACE_IP} primary')
    591626        i = child.expect(['C:', pexpect.EOF, pexpect.TIMEOUT], timeout=5)
    592627        if i > 0:
     
    644679        set_route = False
    645680        set_dns = False
     681        set_telnetclients = True
     682        start_telnet = True
    646683        if self.getvar('WIN_IP'):
    647684            ip = self.getvar('WIN_IP')
     
    667704            child.sendline(password)
    668705            i = child.expect(["C:",
     706                              "TelnetClients",
    669707                              "Denying new connections due to the limit on number of connections",
    670708                              "No more connections are allowed to telnet server",
     
    673711                              "Connection refused",
    674712                              pexpect.EOF])
     713            if i == 1:
     714                if set_telnetclients:
     715                    self.run_cmd('bin/net rpc group add TelnetClients -S $WIN_IP -U$WIN_USER%$WIN_PASS')
     716                    self.run_cmd('bin/net rpc group addmem TelnetClients "authenticated users" -S $WIN_IP -U$WIN_USER%$WIN_PASS')
     717                    child.close()
     718                    retries -= 1
     719                    set_telnetclients = False
     720                    self.info("retrying (retries=%u delay=%u)" % (retries, delay))
     721                    continue
     722                else:
     723                    raise RuntimeError("Failed to connect with telnet due to missing TelnetClients membership")
     724
     725            if i == 6:
     726                # This only works if it is installed and enabled, but not started.  Not entirely likely, but possible
     727                self.run_cmd('bin/net rpc service start TlntSvr -S $WIN_IP -U$WIN_USER%$WIN_PASS')
     728                child.close()
     729                start_telnet = False
     730                retries -= 1
     731                self.info("retrying (retries=%u delay=%u)" % (retries, delay))
     732                continue
     733
    675734            if i != 0:
    676735                child.close()
     
    805864        child.expect("C:")
    806865        child.sendline("dcpromo /answer:answers.txt")
    807         i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:"], timeout=240)
     866        i = child.expect(["You must restart this computer", "failed", "Active Directory Domain Services was not installed", "C:", pexpect.TIMEOUT], timeout=240)
    808867        if i == 1 or i == 2:
    809868            raise Exception("dcpromo failed")
     869        if i == 4: # timeout
     870            child = self.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}")
     871
    810872        child.sendline("shutdown -r -t 0")
    811873        self.port_wait("${WIN_IP}", 139, wait_for_fail=True)
    812874        self.port_wait("${WIN_IP}", 139)
    813         self.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'] )
     875
     876        child = self.open_telnet("${WIN_HOSTNAME}", "administrator", "${WIN_PASS}")
     877        # Check if we became a DC by now
     878        if not self.get_is_dc(child):
     879            raise Exception("dcpromo failed (and wasn't a DC even after rebooting)")
     880        # Give DNS registration a kick
     881        child.sendline("ipconfig /registerdns")
     882
     883        self.retry_cmd("host -t SRV _ldap._tcp.${WIN_REALM} ${WIN_IP}", ['has SRV record'], retries=60, delay=5 )
    814884
    815885
     
    825895        '''join a windows box to a domain'''
    826896        child = self.open_telnet("${WIN_HOSTNAME}", "${WIN_USER}", "${WIN_PASS}", set_time=True, set_ip=True, set_noexpire=True)
    827         child.sendline("ipconfig /flushdns")
    828         child.expect("C:")
    829         child.sendline("netdom join ${WIN_HOSTNAME} /Domain:%s /UserD:%s /PasswordD:%s" % (domain, username, password))
    830         child.expect("The command completed successfully")
     897        retries = 5
     898        while retries > 0:
     899            child.sendline("ipconfig /flushdns")
     900            child.expect("C:")
     901            child.sendline("netdom join ${WIN_HOSTNAME} /Domain:%s /UserD:%s /PasswordD:%s" % (domain, username, password))
     902            i = child.expect(["The command completed successfully",
     903                             "The specified domain either does not exist or could not be contacted."], timeout=120)
     904            if i == 0:
     905                break
     906            time.sleep(10)
     907            retries -= 1
     908
    831909        child.expect("C:")
    832910        child.sendline("shutdown /r -t 0")
     
    843921        self.info('Testing smbclient')
    844922        self.chdir('${PREFIX}')
    845         self.cmd_contains("bin/smbclient --version", ["${SAMBA_VERSION}"])
    846         self.retry_cmd('bin/smbclient -L ${WIN_HOSTNAME} -U%s%%%s %s' % (username, password, args), ["IPC"])
     923        smbclient = self.getvar("smbclient")
     924        self.cmd_contains("%s --version" % (smbclient), ["${SAMBA_VERSION}"])
     925        self.retry_cmd('%s -L ${WIN_HOSTNAME} -U%s%%%s %s' % (smbclient, username, password, args), ["IPC"], retries=60, delay=5)
     926
     927    def test_net_use(self, vm, realm, domain, username, password):
     928        self.setwinvars(vm)
     929        self.info('Testing net use against Samba3 member')
     930        child = self.open_telnet("${WIN_HOSTNAME}", "%s\\%s" % (domain, username), password)
     931        child.sendline("net use t: \\\\${HOSTNAME}.%s\\test" % realm)
     932        child.expect("The command completed successfully")
    847933
    848934
     
    858944        self.parser.add_option("--sourcetree", type='string', default=None, help='override sourcetree location')
    859945        self.parser.add_option("--nocleanup", action='store_true', default=False, help='disable cleanup code')
     946        self.parser.add_option("--use-ntvfs", action='store_true', default=False, help='use NTVFS for the fileserver')
     947        self.parser.add_option("--dns-backend", type="choice",
     948            choices=["SAMBA_INTERNAL", "BIND9_FLATFILE", "BIND9_DLZ", "NONE"],
     949            help="The DNS server backend. SAMBA_INTERNAL is the builtin name server (default), " \
     950                 "BIND9_FLATFILE uses bind9 text database to store zone information, " \
     951                 "BIND9_DLZ uses samba4 AD to store zone information, " \
     952                 "NONE skips the DNS setup entirely (not recommended)",
     953            default="SAMBA_INTERNAL")
    860954
    861955        self.opts, self.args = self.parser.parse_args()
     
    869963
    870964        self.load_config(self.opts.conf)
     965
     966        nameserver = self.get_nameserver()
     967        if nameserver == self.getvar('NAMED_INTERFACE_IP'):
     968            raise RuntimeError("old /etc/resolv.conf must not contain %s as a nameserver, this will create loops with the generated dns configuration" % nameserver)
     969        self.setvar('DNSSERVER', nameserver)
    871970
    872971        self.set_skip(self.opts.skip)
     
    891990            self.chdir('${SOURCETREE}/' + subdir)
    892991            self.run_cmd('make clean')
     992
     993        if self.opts.use_ntvfs:
     994            self.setvar('USE_NTVFS', "--use-ntvfs")
     995        else:
     996            self.setvar('USE_NTVFS', "")
     997
     998        self.setvar('NAMESERVER_BACKEND', self.opts.dns_backend)
     999
     1000        self.setvar('DNS_FORWARDER', "--option=dns forwarder=%s" % nameserver)
Note: See TracChangeset for help on using the changeset viewer.