From a686d12b750ff24fdaab9c65ec29f842c210678f Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Thu, 28 Apr 2016 22:34:07 -0700 Subject: [PATCH] [v9_10] fix update_copyrights to deal with python modules correctly (also removed an unnecessary part of python isc module, not used in 9.10) --- bin/python/isc/__init__.py | 3 +- bin/python/isc/keyseries.py | 194 ------------------------------------ util/copyrights | 17 +++- util/update_copyrights | 15 ++- 4 files changed, 29 insertions(+), 200 deletions(-) delete mode 100644 bin/python/isc/keyseries.py diff --git a/bin/python/isc/__init__.py b/bin/python/isc/__init__.py index 3bef6f36f1..fc1433bdc4 100644 --- a/bin/python/isc/__init__.py +++ b/bin/python/isc/__init__.py @@ -13,12 +13,11 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -__all__ = ['dnskey', 'eventlist', 'keydict', 'keyevent', 'keyseries', +__all__ = ['dnskey', 'eventlist', 'keydict', 'keyevent', 'keyzone', 'utils'] from isc.dnskey import * from isc.eventlist import * from isc.keydict import * from isc.keyevent import * -from isc.keyseries import * from isc.keyzone import * from isc.utils import * diff --git a/bin/python/isc/keyseries.py b/bin/python/isc/keyseries.py deleted file mode 100644 index ed09f71fda..0000000000 --- a/bin/python/isc/keyseries.py +++ /dev/null @@ -1,194 +0,0 @@ -############################################################################ -# Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. -############################################################################ - -from collections import defaultdict -from .dnskey import * -from .keydict import * -from .keyevent import * -from .policy import * -import time - - -class keyseries: - _K = defaultdict(lambda: defaultdict(list)) - _Z = defaultdict(lambda: defaultdict(list)) - _zones = set() - _kdict = None - _context = None - - def __init__(self, kdict, now=time.time(), context=None): - self._kdict = kdict - self._context = context - self._zones = set(kdict.missing()) - - for zone in kdict.zones(): - self._zones.add(zone) - for alg, keys in kdict[zone].items(): - for k in keys.values(): - if k.sep: - self._K[zone][alg].append(k) - else: - self._Z[zone][alg].append(k) - - for group in [self._K[zone][alg], self._Z[zone][alg]]: - group.sort() - for k in group: - if k.delete() and k.delete() < now: - group.remove(k) - - def __iter__(self): - for zone in self._zones: - for collection in [self._K, self._Z]: - if zone not in collection: - continue - for alg, keys in collection[zone].items(): - for key in keys: - yield key - - def dump(self): - for k in self: - print("%s" % repr(k)) - - def fixseries(self, keys, policy, now, **kwargs): - force = kwargs.get('force', False) - if not keys: - return - - # handle the first key - key = keys[0] - if key.sep: - rp = policy.ksk_rollperiod - prepub = policy.ksk_prepublish or (30 * 86400) - postpub = policy.ksk_postpublish or (30 * 86400) - else: - rp = policy.zsk_rollperiod - prepub = policy.zsk_prepublish or (30 * 86400) - postpub = policy.zsk_postpublish or (30 * 86400) - - # the first key should be published and active - p = key.publish() - a = key.activate() - if not p or p > now: - key.setpublish(now) - if not a or a > now: - key.setactivate(now) - - if not rp: - key.setinactive(None, **kwargs) - key.setdelete(None, **kwargs) - else: - key.setinactive(a + rp, **kwargs) - key.setdelete(a + rp + postpub, **kwargs) - - if policy.keyttl != key.ttl: - key.setttl(policy.keyttl) - - # handle all the subsequent keys - prev = key - for key in keys[1:]: - # if no rollperiod, then all keys after the first in - # the series kept inactive. - # (XXX: we need to change this to allow standby keys) - if not rp: - key.setpublish(None, **kwargs) - key.setactivate(None, **kwargs) - key.setinactive(None, **kwargs) - key.setdelete(None, **kwargs) - if policy.keyttl != key.ttl: - key.setttl(policy.keyttl) - continue - - # otherwise, ensure all dates are set correctly based on - # the initial key - a = prev.inactive() - p = a - prepub - key.setactivate(a, **kwargs) - key.setpublish(p, **kwargs) - key.setinactive(a + rp, **kwargs) - key.setdelete(a + rp + postpub, **kwargs) - prev.setdelete(a + postpub, **kwargs) - if policy.keyttl != key.ttl: - key.setttl(policy.keyttl) - prev = key - - # if we haven't got sufficient coverage, create successor key(s) - while rp and prev.inactive() and \ - prev.inactive() < now + policy.coverage: - # commit changes to predecessor: a successor can only be - # generated if Inactive has been set in the predecessor key - prev.commit(self._context['settime_path'], **kwargs) - key = prev.generate_successor(self._context['keygen_path'], - **kwargs) - - key.setinactive(key.activate() + rp, **kwargs) - key.setdelete(key.inactive() + postpub, **kwargs) - keys.append(key) - prev = key - - # last key? we already know we have sufficient coverage now, so - # disable the inactivation of the final key (if it was set), - # ensuring that if dnssec-keymgr isn't run again, the last key - # in the series will at least remain usable. - prev.setinactive(None, **kwargs) - prev.setdelete(None, **kwargs) - - # commit changes - for key in keys: - key.commit(self._context['settime_path'], **kwargs) - - - def enforce_policy(self, policies, now=time.time(), **kwargs): - # If zones is provided as a parameter, use that list. - # If not, use what we have in this object - zones = kwargs.get('zones', self._zones) - keys_dir = kwargs.get('dir', self._context.get('keys_path', None)) - force = kwargs.get('force', False) - - for zone in zones: - collections = [] - policy = policies.policy(zone) - keys_dir = keys_dir or policy.directory or '.' - alg = policy.algorithm - algnum = dnskey.algnum(alg) - if 'ksk' not in kwargs or not kwargs['ksk']: - if len(self._Z[zone][algnum]) == 0: - k = dnskey.generate(self._context['keygen_path'], - keys_dir, zone, alg, - policy.zsk_keysize, False, - policy.keyttl or 3600, - **kwargs) - self._Z[zone][algnum].append(k) - collections.append(self._Z[zone]) - - if 'zsk' not in kwargs or not kwargs['zsk']: - if len(self._K[zone][algnum]) == 0: - k = dnskey.generate(self._context['keygen_path'], - keys_dir, zone, alg, - policy.ksk_keysize, True, - policy.keyttl or 3600, - **kwargs) - self._K[zone][algnum].append(k) - collections.append(self._K[zone]) - - for collection in collections: - for algorithm, keys in collection.items(): - if algorithm != algnum: - continue - try: - self.fixseries(keys, policy, now, **kwargs) - except Exception as e: - raise Exception('%s/%s: %s' % - (zone, dnskey.algstr(algnum), str(e))) diff --git a/util/copyrights b/util/copyrights index 22b0e708ef..8008bf1553 100644 --- a/util/copyrights +++ b/util/copyrights @@ -368,11 +368,26 @@ ./bin/python/dnssec-checkds.8 MAN DOCBOOK ./bin/python/dnssec-checkds.docbook SGML 2012,2013,2014,2015 ./bin/python/dnssec-checkds.html HTML DOCBOOK -./bin/python/dnssec-checkds.py.in PYTHON 2012,2013,2014,2015 +./bin/python/dnssec-checkds.py.in PYTHON-BIN 2012,2013,2014,2015,2016 ./bin/python/dnssec-coverage.8 MAN DOCBOOK ./bin/python/dnssec-coverage.docbook SGML 2013,2014,2015 ./bin/python/dnssec-coverage.html HTML DOCBOOK ./bin/python/dnssec-coverage.py.in PYTHON 2013,2014,2015 +./bin/python/isc/.gitignore X 2016 +./bin/python/isc/Makefile.in MAKE 2016 +./bin/python/isc/__init__.py PYTHON 2016 +./bin/python/isc/checkds.py PYTHON 2012,2013,2014,2015,2016 +./bin/python/isc/coverage.py PYTHON 2013,2014,2015,2016 +./bin/python/isc/dnskey.py PYTHON 2013,2014,2015,2016 +./bin/python/isc/eventlist.py PYTHON 2015,2016 +./bin/python/isc/keydict.py PYTHON 2016 +./bin/python/isc/keyevent.py PYTHON 2013,2014,2015,2016 +./bin/python/isc/keyzone.py PYTHON 2013,2014,2015,2016 +./bin/python/isc/tests/Makefile.in MAKE 2016 +./bin/python/isc/tests/dnskey_test.py PYTHON 2016 +./bin/python/isc/tests/testdata/Kexample.com.+007+35529.key X 2016 +./bin/python/isc/tests/testdata/Kexample.com.+007+35529.private X 2016 +./bin/python/isc/utils.py.in PYTHON 2016 ./bin/rndc/.gitignore X 2012,2014 ./bin/rndc/Makefile.in MAKE 2000,2001,2002,2004,2007,2009,2012,2014,2015 ./bin/rndc/include/rndc/os.h C 2001,2004,2005,2007,2009 diff --git a/util/update_copyrights b/util/update_copyrights index e85473c61d..ce0a8cab60 100644 --- a/util/update_copyrights +++ b/util/update_copyrights @@ -182,6 +182,7 @@ foreach $file (keys %file_types) { $zone_comment = 0; $man_comment = 0; $python_comment = 0; + $python_bin_comment = 0; $start_comment = ""; $end_comment = ""; $first = ""; @@ -193,6 +194,11 @@ foreach $file (keys %file_types) { } elsif ($type =~ /^(SH|PERL|TCL|MAKE|CONF-SH|RNC)$/) { $shell_comment = 1; $prefix = "# "; + } elsif ($type =~ /^PYTHON-BIN$/) { + $python_bin_comment = 1; + $start_comment = "############################################################################\n"; + $prefix = "# "; + $end_comment = "############################################################################\n" } elsif ($type =~ /^PYTHON$/) { $python_comment = 1; $start_comment = "############################################################################\n"; @@ -271,12 +277,15 @@ foreach $file (keys %file_types) { } else { $first = $_; } - } elsif ($python_comment) { - if (/^\#\!/) { + } elsif ($python_comment || $python_bin_comment) { + if ($python_bin_comment && /^\#\!/) { $before_copyright = "$_"; $_ = ; $_ = if $_ eq "#\n"; $_ = if $_ eq "############################################################################\n"; + } elsif ($python_comment && /^\#/) { + $_ = if $_ eq "#\n"; + $_ = if $_ eq "############################################################################\n"; } if (/^\#/) { if ($_ !~ /[Cc]opyright/) { @@ -593,7 +602,7 @@ foreach $file (keys %file_types) { } my ($start, $end); - if ($type =~ /^PYTHON$/) { + if ($type =~ /^PYTHON(|-BIN)$/) { ($start = $prefix) =~ s/\s*\n//; $end = "\n"; } elsif ($start_comment ne "") {