Ejemplo n.º 1
0
    def build(self, transaction=None, **kwargs):
        # dummy empty return value
        response_string_part = ''
        options_answer_part = None

        # http://tools.ietf.org/html/rfc4704#page-5
        # regarding RFC 4704 5. there are 3 kinds of client behaviour for N O S:
        # - client wants to update DNS itself -> sends 0 0 0
        # - client wants server to update DNS -> sends 0 0 1
        # - client wants no server DNS update -> sends 1 0 0
        if transaction.client:
            # flags for answer
            n, o, s = 0, 0, 0
            # use hostname supplied by client
            if cfg.DNS_USE_CLIENT_HOSTNAME:
                hostname = transaction.hostname
            # use hostname from config
            else:
                hostname = transaction.client.hostname
            if not hostname == '':
                if cfg.DNS_UPDATE == 1:
                    # DNS update done by server - don't care what client wants
                    if cfg.DNS_IGNORE_CLIENT:
                        s = 1
                        o = 1
                    else:
                        # honor the client's request for the server to initiate DNS updates
                        if transaction.dns_s == 1:
                            s = 1
                        # honor the client's request for no server-initiated DNS update
                        elif transaction.dns_n == 1:
                            n = 1
                else:
                    # no DNS update at all, not for server and not for client
                    if transaction.dns_n == 1 or \
                            transaction.dns_s == 1:
                        o = 1
                # sum of flags
                nos_flags = n * 4 + o * 2 + s * 1
                fqdn_binary = convert_dns_to_binary(f'{hostname}.{cfg.DOMAIN}')
                response_string_part = self.convert_to_string(
                    self.number, f'{nos_flags:02x}{fqdn_binary}')
            else:
                # if no hostname given put something in and force client override
                fqdn_binary = convert_dns_to_binary(
                    'invalid-hostname.{cfg.DOMAIN}')
                response_string_part = self.convert_to_string(
                    self.number, f'{3:02x}{fqdn_binary}')
            # options in answer to be logged
            options_answer_part = self.number

        return response_string_part, options_answer_part
Ejemplo n.º 2
0
 def build(self, **kwargs):
     converted_domain_search_list = ''
     for d in cfg.DOMAIN_SEARCH_LIST:
         converted_domain_search_list += convert_dns_to_binary(d)
     response_string_part = self.convert_to_string(
         self.number, converted_domain_search_list)
     return response_string_part, self.number
Ejemplo n.º 3
0
    def build(self, **kwargs):
        # dummy empty defaults
        response_string_part = ''
        options_answer_part = None
        ntp_server_options = ''

        if len(cfg.NTP_SERVER) > 0:
            for ntp_server_type in list(cfg.NTP_SERVER_DICT.keys()):
                # ntp_server_suboption
                for ntp_server in cfg.NTP_SERVER_DICT[ntp_server_type]:
                    ntp_server_suboption = ''
                    if ntp_server_type == 'SRV':
                        ntp_server_suboption = self.convert_to_string(
                            1,
                            hexlify(inet_pton(AF_INET6, ntp_server)).decode())
                    elif ntp_server_type == 'MC':
                        ntp_server_suboption = self.convert_to_string(
                            2,
                            hexlify(inet_pton(AF_INET6, ntp_server)).decode())
                    elif ntp_server_type == 'FQDN':
                        ntp_server_suboption = self.convert_to_string(
                            3, convert_dns_to_binary(ntp_server))
                    ntp_server_options += ntp_server_suboption
            response_string_part = self.convert_to_string(
                self.number, ntp_server_options)
            # options in answer to be logged
            options_answer_part = self.number

        return response_string_part, options_answer_part