~ubuntu-security/ubuntu-cve-tracker/master

« back to all changes in this revision

Viewing changes to scripts/report-latest-usn-version

  • Committer: Steve Beattie
  • Date: 2019-02-19 06:18:27 UTC
  • Revision ID: sbeattie@ubuntu.com-20190219061827-oh57fzcfc1u9dlfk
The ubuntu-cve-tracker project has been converted to git.

Please use 'git clone https://git.launchpad.net/ubuntu-cve-tracker' to
get the converted tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# Author: Kees Cook <kees@ubuntu.com>
3
 
# Copyright (C) 2011 Canonical Ltd.
4
 
#
5
 
# Reports the version of the given package in the most recent USN for it
6
 
#
7
 
# Fetch the USN database first. Override location with --database
8
 
#  wget http://people.canonical.com/~ubuntu-security/usn/database.pickle
9
 
#
10
 
from __future__ import print_function
11
 
 
12
 
import cve_lib
13
 
import optparse
14
 
import sys
15
 
import usn_lib
16
 
from source_map import version_compare
17
 
from lp_lib import UCTLaunchpad
18
 
 
19
 
parser = optparse.OptionParser()
20
 
parser.add_option("-D", "--database", help="Specify location of USN data (default 'database.pickle')", default="database.pickle")
21
 
parser.add_option("-r", "--release", help="Specify comma-separated list of which release to limit the search to (default is all)")
22
 
parser.add_option("-d", "--debug", dest="debug", help="Report additional debugging while processing", action='store_true')
23
 
parser.add_option("-g", "--use-glitchdb", dest="use_glitches", help="use kernel version glitchdb as fallback for last USN", action='store_true', default=False)
24
 
(opt, args) = parser.parse_args()
25
 
 
26
 
uctlp = UCTLaunchpad(opt)
27
 
 
28
 
releases = None
29
 
if opt.release:
30
 
    releases = opt.release.split(',')
31
 
else:
32
 
    releases = [r for r in cve_lib.releases if cve_lib.is_active_release(r)]
33
 
 
34
 
usndb = usn_lib.USNdb(args, opt.database, releases, opt)
35
 
for pkg in args:
36
 
    for rel in releases:
37
 
        usns = usndb.get_usns(pkg, rel)
38
 
        # if there are no usns reported for this package, then report
39
 
        # the earliest version in this release. Usually this script is
40
 
        # used to report pending cves between the last USN and what was
41
 
        # just published.
42
 
        if not usns:
43
 
            if opt.debug:
44
 
                print('Could not find published USN, reporting earliest publication for %s/%s' % (pkg, rel), file=sys.stderr)
45
 
            if opt.use_glitches:
46
 
                if opt.debug:
47
 
                    print('Looking up glitch version for %s/%s' % (pkg, rel), file=sys.stderr)
48
 
                version = cve_lib.lookup_glitch_version(pkg, rel, '~')
49
 
                if version:
50
 
                    print(version)
51
 
                else:
52
 
                    print(uctlp.get_earliest_version(rel, pkg))
53
 
            else:
54
 
                print(uctlp.get_earliest_version(rel, pkg))
55
 
        else:
56
 
            print(usns[0])