Example #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; }; };'
     )
Example #2
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'}})
Example #3
0
 def testScrubComments(self):
   self.assertEqual(iscpy.ScrubComments(self.named_file),
                    'options {\ndirectory "/var/domain";\nrecursion yes;\n'
                    'allow-query { any; };\nmax-cache-size 512M;\n};\n\n'
                    'logging {\nchannel "security" {\n'
                    'file "/var/log/named-security.log" '
                    'versions 10 size 10m;\nprint-time yes;\n};\n'
                    'channel "query_logging" {\nsyslog local5;\n'
                    'severity info;\n};\ncategory "client" { "null"; };\n'
                    'category "update-security" { "security"; };\n'
                    'category "queries" { "query_logging"; };\n};\n\n'
                    'controls {\ninet * allow { control-hosts; } keys '
                    '{rndc-key; };\n};\n\ninclude "/etc/rndc.key";\n\n'
                    'acl control-hosts {\n127.0.0.1/32;\n192.168.1.3/32;\n};\n'
                    '\nacl admin {\n192.168.0.0/16;\n192.168.1.2/32;\n'
                    '192.168.1.4/32;\n};\n\nview "unauthorized" {\n'
                    'recursion no;\nmatch-clients { network-unauthorized; };\n'
                    'additional-from-auth no;\nadditional-from-cache no;\n\n'
                    'zone "0.0.127.in-addr.arpa" {\ntype slave;\n'
                    'file "test_data/university.rev.bak";\nmasters {\n'
                    '192.168.1.3;\n'
                    '};\n};\n\nzone "1.210.128.in-addr.arpa" {\ntype master;\n'
                    'file "test_data/test_reverse_zone.db";\n'
                    'allow-query { network-unauthorized; };\n};\n\n'
                    'zone "." {\ntype hint;\nfile "named.ca";\n};\n};\n\n'
                    'view "authorized" {\nrecursion yes;\n'
                    'match-clients { network-authorized; };\n'
                    'allow-recursion { network-authorized; };\n'
                    'allow-query-cache { network-authorized; };\n'
                    'additional-from-auth yes;\nadditional-from-cache yes;\n\n'
                    'zone "university.edu" {\ntype slave;\n'
                    'file "test_data/university.db.bak";\nmasters {\n'
                    '192.168.11.37;\n};\ncheck-names ignore;\n};\n\n'
                    'zone "smtp.university.edu" {\ntype master;\n'
                    'file "test_data/test_zone.db";\nmasters {\n'
                    '192.168.11.37;\n};\n};\n\nzone "." {\ntype hint;\n'
                    'file "named.ca";\n};\n};\n\n')
Example #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
Example #5
0
 def testScrubComments03(self):
   self.assertEqual(iscpy.ScrubComments("/*\n*\n*\n*/foobar"), "foobar")