Esempio n. 1
0
 def testParse(self):
     self.assertEqual(iscpy.Explode(iscpy.ScrubComments(self.named_file)), [
         'include "/home/jcollins/roster-dns-management/test/test_data/rndc.key"',
         ';', 'options', '{', 'pid-file "test_data/named.pid"', ';', '}',
         ';', 'controls', '{', 'inet 127.0.0.1 port 35638 allow', '{',
         'localhost', ';', '}', 'keys', '{', 'rndc-key', ';', '}', ';', '}',
         ';'
     ])
     self.assertEqual(
         iscpy.ParseISCString(self.named_file), {
             'include':
             '"/home/jcollins/roster-dns-management/test/test_data/rndc.key"',
             'options': {
                 'pid-file': '"test_data/named.pid"'
             },
             'controls': [{
                 'inet 127.0.0.1 port 35638 allow': {
                     'localhost': True
                 }
             }, {
                 'keys': {
                     'rndc-key': True
                 }
             }]
         })
     self.assertEqual(
         iscpy.MakeISC(iscpy.ParseISCString(self.named_file)),
         'include "/home/jcollins/roster-dns-management/test/test_data/rndc.key";\n'
         'options { pid-file "test_data/named.pid"; };\n'
         'controls { inet 127.0.0.1 port 35638 allow { localhost; } keys { rndc-key; }; };'
     )
Esempio n. 2
0
 def testExplode(self):
   self.assertEqual(iscpy.Explode(self.named_file),
                    ['options', '{', 'directory "/var/domain"', ';',
                     'recursion yes', ';', 'allow-query', '{', 'any', ';', '}',
                     ';', 'max-cache-size 512M', ';', '}', ';', 'logging', '{',
                     'channel "security"', '{',
                     'file "/var/log/named-security.log" versions 10 size 10m',
                     ';', 'print-time yes', ';', '}', ';',
                     'channel "query_logging"', '{', 'syslog local5', ';',
                     'severity info', ';', '}', ';', 'category "client"', '{',
                     '"null"', ';', '}', ';', 'category "update-security"',
                     '{', '"security"', ';', '}', ';', 'category "queries"',
                     '{', '"query_logging"', ';', '}', ';', '}', ';',
                     'controls', '{', 'inet * allow', '{', 'control-hosts',
                     ';', '}', 'keys', '{', 'rndc-key', ';', '}', ';',
                     '}', ';', 'include "/etc/rndc.key"', ';',
                     'acl control-hosts', '{', '127.0.0.1/32', ';',
                     '192.168.1.3/32', ';', '}', ';', 'acl admin', '{',
                     '192.168.0.0/16', ';', '192.168.1.2/32', ';',
                     '192.168.1.4/32', ';', '}', ';', 'view "unauthorized"',
                     '{', 'recursion no', ';', 'match-clients', '{',
                     'network-unauthorized', ';', '}', ';',
                     'additional-from-auth no', ';',
                     'additional-from-cache no', ';',
                     '//\t// Loopback network\t//\tzone "0.0.127.in-addr.arpa"',
                     '{', 'type slave', ';',
                     'file "test_data/university.rev.bak"',
                     ';', 'masters', '{', '192.168.1.3', ';', '}', ';', '}',
                     ';',
                     '//\t// 192.168.1.0/24\t//\tzone "1.210.128.in-addr.arpa"',
                     '{', 'type master', ';',
                     'file "test_data/test_reverse_zone.db"', ';',
                     'allow-query', '{', 'network-unauthorized', ';', '}', ';',
                     '}', ';', '//\t// Cache File\t//\tzone "."', '{',
                     'type hint', ';', 'file "named.ca"', ';', '}', ';', '}',
                     ';', 'view "authorized"', '{', 'recursion yes', ';',
                     'match-clients', '{', 'network-authorized', ';', '}', ';',
                     'allow-recursion', '{', 'network-authorized', ';', '}',
                     ';', 'allow-query-cache', '{', 'network-authorized', ';',
                     '}', ';', 'additional-from-auth yes', ';',
                     'additional-from-cache yes', ';', 'zone "university.edu"',
                     '{', 'type slave', ';',
                     'file "test_data/university.db.bak"', ';', 'masters', '{',
                     '192.168.11.37', ';', '}', ';', 'check-names ignore', ';',
                     '}', ';',
                     '//\t// Internal view of "smtp.university.edu"\t//\tzone "smtp.university.edu"',
                     '{', 'type master', ';', 'file "test_data/test_zone.db"',
                     ';', 'masters', '{', '192.168.11.37', ';', '}', ';', '}',
                     ';', '//\t// Cache File\t//\tzone "."', '{', 'type hint',
                     ';', 'file "named.ca"', ';', '}', ';', '}', ';'])
Esempio n. 3
0
 def testParse(self):
   self.assertEqual(iscpy.ParseTokens(
       iscpy.Explode(
           iscpy.ScrubComments(self.named_file))),
       {'acl control-hosts': {'127.0.0.1/32': True, '192.168.1.3/32': True},
        'acl admin': {'192.168.1.2/32': True, '192.168.1.4/32': True,
                      '192.168.0.0/16': True},
        'view "authorized"': {'zone "smtp.university.edu"':
            {'masters': {'192.168.11.37': True},
             'type': 'master', 'file': '"test_data/test_zone.db"'},
             'allow-query-cache': {'network-authorized': True},
             'allow-recursion': {'network-authorized': True},
             'recursion': 'yes',
             'zone "university.edu"': {'check-names': 'ignore',
                                       'masters': {'192.168.11.37': True},
             'type': 'slave', 'file': '"test_data/university.db.bak"'},
             'match-clients': {'network-authorized': True},
             'zone "."': {'type': 'hint', 'file': '"named.ca"'},
                          'additional-from-cache': 'yes',
                          'additional-from-auth': 'yes'},
             'controls': [{'inet * allow': {'control-hosts': True}},
                          {'keys': {'rndc-key': True}}],
         'view "unauthorized"': 
             {'zone "1.210.128.in-addr.arpa"':
                 {'allow-query': {'network-unauthorized': True},
                  'type': 'master',
                  'file': '"test_data/test_reverse_zone.db"'},
              'recursion': 'no',
              'match-clients': {'network-unauthorized': True},
              'zone "."': {'type': 'hint', 'file': '"named.ca"'},
              'zone "0.0.127.in-addr.arpa"': {
                  'masters': {'192.168.1.3': True}, 'type': 'slave',
                  'file': '"test_data/university.rev.bak"'},
              'additional-from-cache': 'no', 'additional-from-auth': 'no'},
              'logging': {'category "update-security"': {'"security"': True},
                          'category "queries"': {'"query_logging"': True},
                          'channel "query_logging"': 
                              {'syslog': 'local5', 'severity': 'info'},
                              'category "client"': {'"null"': True},
                              'channel "security"':
                                  {'file': '"/var/log/named-security.log" versions 10 size 10m',
                                   'print-time': 'yes'}},
         'include': '"/etc/rndc.key"',
         'options': {'directory': '"/var/domain"', 'recursion': 'yes',
                     'allow-query': {'any': True}, 'max-cache-size': '512M'}})
Esempio n. 4
0
def MakeNamedDict(named_string):
    """Makes a more organized named specific dict from parsed_dict

  Inputs:
    named_string: string of named file

  Outputs:
    dict: organized dict with keys views options and acls
    {'acls': {'acl1': ['10.1.0/32', '10.1.1/32']},
     'views': {'view1': {'zones': {'test_zone': {'file': '/path/to/zonefile',
                                                 'type': 'master',
                                                'options': 'zone_options'}},
                         'options': 'view_options'}}}
  """
    named_string = iscpy.ScrubComments(named_string)
    parsed_dict = copy.deepcopy(iscpy.ParseTokens(iscpy.Explode(named_string)))
    named_data = {'acls': {}, 'views': {}, 'options': {}, 'orphan_zones': {}}
    for key in parsed_dict:
        if (key.startswith('acl')):
            named_data['acls'][key.split()[1]] = []
            for cidr in parsed_dict[key]:
                named_data['acls'][key.split()[1]].append(cidr)
        elif (key.startswith('view')):
            view_name = key.split()[1].strip('"').strip()
            named_data['views'][view_name] = {'zones': {}, 'options': {}}
            for view_key in parsed_dict[key]:
                if (view_key.startswith('zone')):
                    zone_name = view_key.split()[1].strip('"').strip()
                    named_data['views'][view_name]['zones'][zone_name] = ({
                        'options': {},
                        'file':
                        ''
                    })
                    for zone_key in parsed_dict[key][view_key]:
                        if (zone_key.startswith('file')):
                            named_data['views'][view_name]['zones'][zone_name][
                                'file'] = (parsed_dict[key][view_key]
                                           [zone_key].strip('"').strip())
                        elif (zone_key.startswith('type')):
                            named_data['views'][view_name]['zones'][zone_name][
                                'type'] = (parsed_dict[key][view_key]
                                           [zone_key].strip('"').strip())
                        else:
                            named_data['views'][view_name]['zones'][zone_name][
                                'options'][zone_key] = parsed_dict[key][
                                    view_key][zone_key]
                else:
                    named_data['views'][view_name]['options'][view_key] = (
                        parsed_dict[key][view_key])
        elif (key.startswith('zone')):
            zone_name = key.split()[1].strip('"').strip()
            named_data['orphan_zones'][zone_name] = ({
                'options': {},
                'file': ''
            })
            for zone_key in parsed_dict[key]:
                if (zone_key.startswith('file')):
                    named_data['orphan_zones'][zone_name]['file'] = (
                        parsed_dict[key][zone_key].strip('"').strip())
                elif (zone_key.startswith('type')):
                    named_data['orphan_zones'][zone_name]['type'] = (
                        parsed_dict[key][zone_key].strip('"').strip())
                else:
                    named_data['orphan_zones'][zone_name]['options'][
                        zone_key] = parsed_dict[key][zone_key]
        else:
            named_data['options'][key] = parsed_dict[key]

    return named_data