summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjoern <bjoern@asyme.(none)>2009-07-31 17:56:14 +0200
committerbjoern <bjoern@asyme.(none)>2009-07-31 17:56:14 +0200
commitdbca4a3812e6ae5df1249aad409b3a7cb97035a1 (patch)
tree960b2fcfe8cf69bdc5f3171ec9a9ad64c85c094d
parentBump to alpha release ;) (diff)
downloadkernel-check-dbca4a3812e6ae5df1249aad409b3a7cb97035a1.tar.gz
kernel-check-dbca4a3812e6ae5df1249aad409b3a7cb97035a1.tar.bz2
kernel-check-dbca4a3812e6ae5df1249aad409b3a7cb97035a1.zip
Clean code, fix some small bugs
-rw-r--r--.gitignore1
-rw-r--r--TODO1
-rwxr-xr-xcollector.py27
-rwxr-xr-xkernel-check.py8
-rwxr-xr-xkernellib.py50
5 files changed, 42 insertions, 45 deletions
diff --git a/.gitignore b/.gitignore
index 3be6893..97ee5c5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*pyc
*~
+*#
tmp
out
diff --git a/TODO b/TODO
index 49b2516..f2909f7 100644
--- a/TODO
+++ b/TODO
@@ -14,3 +14,4 @@ Todo
- Write a proper documentation
- Implement DTD
- Remove unused code and find better ways
+- Check lookaround of 'grp_all' \ No newline at end of file
diff --git a/collector.py b/collector.py
index e7edcc8..d817024 100755
--- a/collector.py
+++ b/collector.py
@@ -15,8 +15,8 @@ def main(argv):
'Main function'
try:
- opts, args = getopt.getopt(argv, 'd:fh:st:v',
- ['delay=', 'force', 'help', 'skip', 'tree=', 'verbose'])
+ opts, args = getopt.getopt(argv, 'd:fh:sv',
+ ['delay=', 'force', 'help', 'skip', 'verbose'])
except getopt.GetoptError:
usage()
@@ -30,10 +30,6 @@ def main(argv):
usage()
elif opt in ('-s', '--skip'):
lib.SKIP = True
- elif opt in ('-t', '--tree'):
- if os.access(os.path.dirname(arg) , os.W_OK) and \
- os.path.isdir(arg):
- lib.TREE = arg
elif opt in ('-v', '--verbose'):
lib.VERBOSE = True
@@ -44,21 +40,21 @@ def main(argv):
print 'Reading available genpatches...'
try:
read_patches = lib.read_genpatch_file(lib.FOLDER['out'])
- except:
+ except IOError:
read_patches = list()
print 'Parsing genpatches from portage...'
- found_patches = lib.parse_genpatch_list(lib.TREE)
+ found_patches = lib.parse_genpatch_list(lib.PORTDIR)
- new_items = 0
+ new_patches = 0
for item in found_patches:
if item not in read_patches:
read_patches.append(item)
- new_items += 1
+ new_patches += 1
- if (new_items):
+ if (new_patches):
lib.write_genpatch_file(lib.FOLDER['out'], read_patches)
- print 'Added %i new genpatches!' % new_items
+ print 'Added %i new genpatches!' % new_patches
print '\nReceiving the latest xml file from the nvd...'
lib.receive_nvd_recent(lib.FOLDER['nvd'])
@@ -85,6 +81,7 @@ def main(argv):
vul = lib.parse_bugzilla_dict(lib.FOLDER['bug'], item)
vul = lib.search_nvd_dict(nvd_dict, vul)
lib.write_cve_file(lib.FOLDER['out'], vul)
+
created_files += 1
time.sleep(lib.DELAY)
@@ -97,9 +94,8 @@ def main(argv):
print '%s' % e.value
except lib.NvdEntryError, e:
- #print '\n[%s] No Nvd Entry' % item
- #print '%s' % e.value
- created_files += 1
+ print '\n[%s] No Nvd Entry' % item
+ print '%s' % e.value
except lib.CveDuplicateError, e:
print '\n[%s] CVE Duplicate' % item
@@ -115,7 +111,6 @@ def usage():
print ' -d, --delay [ticks] add delay to xml file creation'
print ' -f, --force force update of xml files'
print ' -h, --help display help information'
- print ' -t, --tree [dir] set the portage path'
print ' -s, --skip skip update of prior nvd files'
print ' -v, --verbose display debugging information'
sys.exit()
diff --git a/kernel-check.py b/kernel-check.py
index 5b3a8f8..3736fd3 100755
--- a/kernel-check.py
+++ b/kernel-check.py
@@ -32,10 +32,10 @@ def main(argv):
portage.output.nocolor()
elif opt in ('-r', '--report'):
return
- # TODO report(arg)
+ #TODO report(arg)
elif opt in ('-s', '--show'):
return
- # TODO show_bugid(arg)
+ #TODO show_bugid(arg)
elif opt in ('-v', '--verbose'):
lib.VERBOSE = True
@@ -43,7 +43,7 @@ def main(argv):
kernel = lib.extract_version(os.uname()[2])
best = lib.best_version(kernel.source)
- if kernel is not None:
+ if lib.Kernel is not None:
info('Kernel version: %s' % (color('GOOD', '%s-%s' %
(kernel.version, kernel.revision))))
info('Kernel sources: %s' % color('GOOD', kernel.source))
@@ -109,7 +109,7 @@ def main(argv):
if kernel == best:
info('Your kernel is up to date!')
else:
- info('Upgrading your kernel to %s does improve your security' %
+ info('Upgrading your kernel to %s does not improve your security' %
color('GOOD', best.version + '-' + best.revision))
diff --git a/kernellib.py b/kernellib.py
index 0d3b235..1985f7a 100755
--- a/kernellib.py
+++ b/kernellib.py
@@ -24,7 +24,6 @@ ARCHES = [
BUGORDER = ['bugid', 'reporter', 'reported', 'status', 'arch', 'affected']
CVEORDER = ['cve', 'published', 'desc', 'severity', 'vector', 'score', 'refs']
-#TODO Check lookaround of 'grp_all'
REGEX = {
'bugzilla' : re.compile(r'(?<=bug.cgi\?id=)\d*'),
'gp_version' : re.compile(r'(?<=K_GENPATCHES_VER\=\").+(?=\")'),
@@ -66,11 +65,11 @@ GENTOO_KERNEL = [
VERSION = '0.5.4'
NOCVE = 'GENERIC-MAP-NOMATCH'
CVES = dict()
+PORTDIR = portage.settings['PORTDIR']
VERBOSE = False
FORCE = False
SKIP = False
DELAY = 0
-TREE = '/usr/portage' #FIXME Use python api / path != /usr/portage ?
FOLDER = {
'tmp' : 'tmp',
'out' : 'out',
@@ -307,6 +306,7 @@ def interval_to_xml(interval, root):
node.set('inclusive', str(getattr(interval, item + '_i')).lower())
+#TODO collapse
def interval_from_xml(root):
'Returns an interval from xml'
@@ -339,7 +339,7 @@ def is_in_interval(interval, kernel):
version = kernel.version #TODO Use revision, source
- #TODO: raise exception
+ #TODO raise exception
if version == None:
return False
@@ -712,7 +712,6 @@ def write_cve_file(directory, vul):
root = et.Element('vulnerability')
bugroot = et.SubElement(root, 'bug')
-
for element in BUGORDER:
if element == 'affected':
affectedroot = et.SubElement(bugroot, 'affected')
@@ -780,9 +779,8 @@ def from_whiteboard(whiteboard):
wb['lower'] = vers1
wb['upper'] = vers1
- if not REGEX['wb_version'].match(vers1):
- raise InvalidWhiteboardError(whiteboard)
- elif comp2 or vers2:
+ #FIXME Check comp2, ver2
+ if not REGEX['wb_version'].match(vers1) or comp2 or ver2:
raise InvalidWhiteboardError(whiteboard)
else:
for (char, version) in ((comp1, vers1), (comp2, vers2)):
@@ -804,6 +802,7 @@ def from_whiteboard(whiteboard):
if version and not REGEX['wb_version'].match(version):
raise InvalidWhiteboardError(whiteboard)
+ #FIXME
affected.append(Interval(name, wb['lower'], wb['upper'],
wb['lower_inc'], wb['upper_inc'],
wb['expand']))
@@ -812,6 +811,7 @@ def from_whiteboard(whiteboard):
return affected
+#TODO Use Exceptions
def extract_version(release):
'Extracts revision, source and version out of a release tag'
@@ -851,17 +851,18 @@ def extract_version(release):
#TODO Rework
def best_version(source):
- kernel = 'sys-kernel/' + source
+ #FIXME Description
porttree = portage.db[portage.root]['porttree']
- bestmatch = porttree.dep_bestmatch(kernel)
- bestmatch = bestmatch[11:].replace('-sources','')
- split = bestmatch.split('-')
- best = extract_version(split[1] + '-' + split[0] + '-' + split[2])
+ bestmatch = porttree.dep_bestmatch('sys-kernel/%s' % source)
+
+ split = bestmatch[11:].replace('-sources','').split('-')
+ best = extract_version('%s-%s-%s' % (split[1], split[0], split[2]))
return best
+#TODO Remove debug; use Exceptions
def receive_file(directory, path, xml_file,
max_age = datetime.timedelta(0, 59*60)):
'Generic download function'
@@ -892,22 +893,22 @@ def receive_file(directory, path, xml_file,
def receive_nvd_recent(directory):
'Download the latest CVEs file from the National Vulnerability Database'
- path = 'http://nvd.nist.gov/download/'
+ url = 'http://nvd.nist.gov/download/'
- receive_file(directory, path, 'nvdcve-recent.xml')
+ receive_file(directory, url, 'nvdcve-recent.xml')
def receive_nvd_all(directory):
'Download all earlier CVEs files from the National Vulnerability Database'
- path = 'http://nvd.nist.gov/download/'
+ url = 'http://nvd.nist.gov/download/'
year = datetime.datetime.now().year
if year < 2002 or year > 2020:
year = 2020
for i in xrange(2002, year + 1):
- receive_file(directory, path, 'nvdcve-' + str(i) + '.xml',
+ receive_file(directory, url, 'nvdcve-%s.xml' % str(i),
max_age = datetime.timedelta(1))
@@ -915,25 +916,24 @@ def receive_bugzilla_list(directory):
'Download a list containing all Bugzilla kernel bugs'
status = ['NEW', 'ASSIGNED', 'REOPENED', 'RESOLVED', 'VERIFIED', 'CLOSED']
- resolution = ['FIXED', 'LATER', 'CANTFIX', 'TEST-REQUEST', 'UPSTREAM',
- '---'] #FIXME Remove CANTFIX ?
+ resolution = ['FIXED', 'LATER', 'TEST-REQUEST', 'UPSTREAM', '---']
- path = ['https://bugs.gentoo.org/buglist.cgi?',
+ url = ['https://bugs.gentoo.org/buglist.cgi?',
'query_format=advanced&component=Kernel']
for i in status:
- path.append('&bug_status=' + i)
+ url.append('&bug_status=' + i)
for i in resolution:
- path.append('&resolution=' + i)
- path.append('#')
+ url.append('&resolution=' + i)
+ url.append('#')
- receive_file(directory, ''.join(path), 'bugzilla.xml')
+ receive_file(directory, ''.join(url), 'bugzilla.xml')
def receive_bugzilla_bug(directory, bugid):
'Download the xml file of a particular Bugzilla kernel bug'
- path = 'https://bugs.gentoo.org/show_bug.cgi?ctype=xml&id='
+ url = 'https://bugs.gentoo.org/show_bug.cgi?ctype=xml&id='
- receive_file(directory, path, bugid)
+ receive_file(directory, url, bugid)