3 8Pe&@sddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z dZ ddl mZmZmZmZmZmZddZdad d Zd d Zd dZdddZddZddZdS))print_functionN) defaultdictzdnssec-coverage)dnskey eventlistkeydictkeyeventkeyzoneutilscOst||tjddS)N)printsysexit)argskwargsr/usr/lib/python3.6/coverage.pyfatals rTcOsJd|kr|d}|jddnd}tr,dan |r8td|rFt||dS)zuoutput text, adding a vertical space this is *not* the first first section being printed since a call to vreset()skipNTF)pop _firstliner )rrrrrroutput'srcCsdadS)zreset vertical spacingTN)rrrrrvreset8src Cs|j}yt|Stk r$YnXtjd}|j|}|sJtd||j\}}t|}|j}|jdrx|dS|jdr|dS|jdr|dS|jd r|d S|jd r|d S|jd r|dS|jdr|Std|dS)z convert a formatted time (e.g., 1y, 6mo, 15mi, etc) into seconds :param s: String with some text representing a time interval :return: Integer with the number of seconds in the time interval z([0-9][0-9]*)\s*([A-Za-z]*)zCannot parse %syi3moi'wi: diQhiZmi<szInvalid suffix %sN) stripint ValueErrorrecompilematchgroupslower startswith)rrmnZunitrrr parse_timeAs6           r,cCs|}| s(tjj| s(tj|tj rtjd}|s>tjj}xB|jtjD]2}tjj ||}tjj|rztj|tjrzPd}qLW|S)a1 find the location of a specified command. if a default is supplied and it works, we use it; otherwise we search PATH for a match. :param command: string with a command to look for in the path :param default: default location to use :return: detected location for the desired command PATHN) ospathisfileaccessX_OKenvirondefpathsplitpathsepjoin)ZcommanddefaultZfpathr/Z directoryrrrset_pathks$ r9c 0CsDtdtjjtjdd}tjtddd}|j dt dddFd |j d d dt ddd|j ddt ddd|j ddt ddd|j ddt ddd|j ddd t d!dd|j d"d#|t d$d d|j d%d&t d'd(dd)|j d*d+d,d-d.d/|j d0d1d,d-d2d/|j d3d4d5d,d-d6d/|j d7d8d9tj d:|j }|j rJ|jrJtd;n*|j sZ|jrn|j rfdkrtd?d@dA|jD|_y|jrt|j}||_Wntk rYnXy|jrt|j}||_Wntk r YnXy|jr(t|j}||_Wntk r@YnXy<|jr||j}t|j}|dBkrnd|_ntj||_Wntk rYnX|jr|jr|S|jr*|jr*y:t|jdB|j|j}|jp|j|_|jp|j|_Wn4tk r(}ztdC|j|WYdd}~XnX|js@tdDdE|_|S)Gz8Read command line arguments, set global 'args' structureznamed-compilezoneZsbinz: checks future zDNSKEY coverage for a zone) descriptionzone*Nzzone(s) to checkz%(default: all zones in the directory))typenargsr8helpz-Kr/.z&a directory containing keys to processdir)destr8r=r?metavarz-ffilenamezzone master filefile)rBr=r?rCz-mmaxttlzthe longest TTL in the zone(s)timez-dkeyttlzthe DNSKEY TTLz-rresignZ1944000z:the RRSIG refresh interval in seconds [default: 22.5 days]z-c compilezonezpath to 'named-compilezone'z-l checklimit0zDLength of time to check for DNSSEC coverage [default: 0 (unlimited)])rBr=r8r?rCz-zno_ksk store_trueFz#Only check zone-signing keys (ZSKs))rBactionr8r?z-kno_zskz"Only check key-signing keys (KSKs)z-Dz--debugZ debug_modezTurn on debugging outputz-vz --versionversion)rOrQz)ERROR: -z and -k cannot be used together.ZKSKZZSKr z)ERROR: -f can only be used with one zone.cSs4g|],}t|dkr,|ddkr,|ddn|qS)r r@NrR)len).0xrrr szparse_args..rz"Unable to load zone data from %s: zWARNING: Maximum TTL value was not specified. Using 1 week (604800 seconds); re-run with the -m option to get more accurate results.i: z5zone(s) to check(default: all zones in the directory)) r9r.r/r7r prefixargparseArgumentParserprog add_argumentstrrQ parse_argsrPrMrkeytyperDrSr;rFr,r"rHrIrKrGrrJ Exceptionr r) rJparserrr*kr)Zlimr;errrr]s                       "r]c(Cspt}tdyt|j|j|jd}Wn2tk rX}ztdt|WYdd}~XnXx<|D]4}|j t |j r|j t q`|j t |j |jq`Wt dty t|}Wn2tk r}ztdt|WYdd}~XnXd}|js|jd|j|jt sXd}nJxH|jD]>}y|j||j|jt s6d}Wnt d|YnXqWtj|rfd nd dS) Nz;PHASE 1--Loading keys to check for internal timing problems)r/ZzonesrHz'ERROR: Unable to build key dictionary: z9PHASE 2--Scanning future key events for coverage failuresz#ERROR: Unable to build event list: FTz&ERROR: Coverage check failed for zone r r)r]r rr/r;rHr_rr\Z check_prepubrsepZ check_postpubrFrIrrZcoverager^rKr r )rZkdrbkeyZelisterrorsr;rrrmains:"    "   rf)N)Z __future__rr.r rXZglobr#rGZcalendarpprint collectionsrrZZiscrrrrrr rrrrr,r9r]rfrrrr s&    * x