"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/bin/python/isc/keyzone.py.in" (4 Sep 2020, 1982 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ############################################################################
    2 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3 #
    4 # This Source Code Form is subject to the terms of the Mozilla Public
    5 # License, v. 2.0. If a copy of the MPL was not distributed with this
    6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7 #
    8 # See the COPYRIGHT file distributed with this work for additional
    9 # information regarding copyright ownership.
   10 ############################################################################
   11 
   12 import os
   13 import sys
   14 import re
   15 from subprocess import Popen, PIPE
   16 
   17 ########################################################################
   18 # Exceptions
   19 ########################################################################
   20 class KeyZoneException(Exception):
   21     pass
   22 
   23 ########################################################################
   24 # class keyzone
   25 ########################################################################
   26 class keyzone:
   27     """reads a zone file to find data relevant to keys"""
   28 
   29     def __init__(self, name, filename, czpath):
   30         self.maxttl = None
   31         self.keyttl = None
   32 
   33         if not name:
   34             return
   35 
   36         if not czpath or not os.path.isfile(czpath) \
   37                 or not os.access(czpath, os.X_OK):
   38             raise KeyZoneException('"named-compilezone" not found')
   39             return
   40 
   41         maxttl = keyttl = None
   42 
   43         fp, _ = Popen([czpath, "-o", "-", name, filename],
   44                       stdout=PIPE, stderr=PIPE).communicate()
   45         for line in fp.splitlines():
   46             if type(line) is not str:
   47                 line = line.decode('ascii')
   48             if re.search('^[:space:]*;', line):
   49                 continue
   50             fields = line.split()
   51             if not maxttl or int(fields[1]) > maxttl:
   52                 maxttl = int(fields[1])
   53             if fields[3] == "DNSKEY":
   54                 keyttl = int(fields[1])
   55 
   56         self.keyttl = keyttl
   57         self.maxttl = maxttl