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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# Copyright 2013, Kees Cook <kees@ubuntu.com>
# License: GPLv3
#
# Attempt to generate a report about things in pMRE status.
#
import sys, datetime
import simplejson as json

try:
    from urllib.parse import quote
    from urllib.request import urlopen
except ImportError:
    from urllib import quote, urlopen

try:
    import lpl_common
except ImportError:
    print >>sys.stderr, "lpl_common.py seems to be missing. Please create a symlink from $UQT/common/lpl_common.py to $UCT/scripts/"
    sys.exit(1)

import warnings
warnings.filterwarnings('ignore', 'apt API not stable yet', FutureWarning)
import apt

BASE_ERRORS_URL = 'https://errors.ubuntu.com/api/1.0/'


year, mon, day = [int(x) for x in sys.argv[1].split('-')]
after = datetime.datetime(year, mon, day)

lp = lpl_common.connect()
ubuntu = lp.distributions['ubuntu']
archive, group, ppa = lpl_common.get_archive("ubuntu", lp)

for pkg in sys.argv[2:]:

    for relname in ['precise','quantal','raring']:
        found = {}
        security = set()
        release = None

        rel = ubuntu.getSeries(name_or_version=relname)
        spph = archive.getPublishedSources(distro_series=rel, source_name=pkg, exact_match=True)

        for ph in spph:
            # First, record any release or security versions.
            if ph.pocket == "Security":
                security.add(ph.source_package_version)
            if ph.pocket == "Release" and ph.status == "Published":
                release = ph

        for ph in spph:
            # Not in Updates? Then we don't care.
            if ph.pocket != "Updates":
                continue
            # Same version was in Security? Then we don't care.
            if ph.source_package_version in security:
                #print >>sys.stderr, "Ignoring %s" % (ph.source_package_version)
                continue
            date = ph.date_published.replace(tzinfo=None)
            if date < after:
                continue
            datestr = date.strftime("%Y-%m-%d")
            index = datestr + "." + ph.source_package_version
            found[index] = ph

        print "    %s, %s updates: %d" % (pkg, relname, len(found))
        prior = release
        for index in sorted(found):
            ph = found[index]
            new_version = ph.source_package_version
            previous_version = prior.source_package_version
            prior = ph

            print "        %s %s" % (ph.date_published.strftime("%Y-%m-%d"),
                                     new_version)
            #print "            prior: %s" % (previous_version)
            url = '%spackage-version-new-buckets/?format=json&' % \
                    (BASE_ERRORS_URL) + \
                    'package=%s&previous_version=%s&new_version=%s' % \
                    (quote(pkg), quote(previous_version), quote(new_version))
            report = urlopen(url)
            if report.getcode() != 200:
                raise IndexError, url
            data = json.load(report)
            if 'error_message' in data.keys():
                raise IndexError, url
            count = len(data['objects'])
            #print url
            print "            error report count: %d" % (count)