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

« back to all changes in this revision

Viewing changes to scripts/pull-in-progress.py

  • 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
 
# Copyright 2008-2009 Canonical, Ltd.
3
 
# Author: Jamie Strandboge <jamie@canonical.com>
4
 
# License: GPLv3
5
 
#
6
 
#
7
 
import sys, os, os.path, re, urllib, tempfile
8
 
import optparse, glob
9
 
import cve_lib
10
 
 
11
 
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
12
 
from launchpadlib.credentials import Credentials
13
 
from launchpadlib.errors import HTTPError
14
 
 
15
 
print "DEPRECATED: please use:"
16
 
print "$ report-todo-sponsoring --status 'In Progress' --team ubuntu-security --has-patch"
17
 
sys.exit(0)
18
 
 
19
 
# Stolen from lpl_common.py from ubuntu-qa-tools
20
 
def connect():
21
 
    cachedir = os.path.expanduser('~/.launchpadlib/cache')
22
 
    if not os.path.exists(cachedir):
23
 
        os.makedirs(cachedir,0700)
24
 
 
25
 
    credfile = os.path.expanduser('~/.launchpadlib/credentials')
26
 
    try:
27
 
        credentials = Credentials()
28
 
        credentials.load(open(credfile))
29
 
        launchpad = Launchpad(credentials, EDGE_SERVICE_ROOT, cachedir)
30
 
    except:
31
 
        launchpad = Launchpad.get_token_and_login(sys.argv[0], EDGE_SERVICE_ROOT, cachedir)
32
 
        credfd = tempfile.NamedTemporaryFile(dir=os.path.dirname(credfile))
33
 
        launchpad.credentials.save(credfd)
34
 
        os.link(credfd.name, credfile)
35
 
        credfd.close()
36
 
    return launchpad
37
 
 
38
 
lp = connect()
39
 
 
40
 
parser = optparse.OptionParser()
41
 
parser.add_option("-u", "--update", dest="update", help="Update CVEs with released package versions", action='store_true')
42
 
parser.add_option("-v", "--verbose", dest="verbose", help="Report logic while processing USNs", action='store_true')
43
 
parser.add_option("-a", "--any", dest="any", help="Show any bugs with status NEW, CONFIRMED, TRIAGED, INPROGRESS, FIXCOMMITTED with a patch attached", action='store_true')
44
 
(opt, args) = parser.parse_args()
45
 
 
46
 
def get_cves(bug):
47
 
    cves = []
48
 
    if bug.cves != None:
49
 
        for c in bug.cves:
50
 
            cves.append("CVE-" + c.sequence)
51
 
 
52
 
    return cves
53
 
 
54
 
#
55
 
# This should be api-ified
56
 
# Need to figure out a way to get a list of bugs via an API query
57
 
#
58
 
from launchpadbugs.connector import ConnectBugList
59
 
BugList = ConnectBugList()
60
 
cve_lib.read_config()
61
 
BugList.authentication = cve_lib.config["plb_authentication"]
62
 
 
63
 
url="https://bugs.launchpad.net/~ubuntu-security/+bugs?field.searchtext=&orderby=-importance&field.status%3Alist=INPROGRESS&assignee_option=any&field.assignee=&field.bug_reporter=&field.bug_supervisor=&field.bug_commenter=&field.subscriber=&field.status_upstream-empty-marker=1&field.omit_dupes.used=&field.has_patch.used=&field.has_patch=on&field.has_cve.used=&field.tag=&field.tags_combinator=ANY&search=Search"
64
 
if opt.any:
65
 
    url="https://bugs.launchpad.net/~ubuntu-security/+bugs?field.searchtext=&orderby=-importance&field.status%3Alist=NEW&field.status%3Alist=CONFIRMED&field.status%3Alist=TRIAGED&field.status%3Alist=INPROGRESS&field.status%3Alist=FIXCOMMITTED&assignee_option=any&field.assignee=&field.bug_reporter=&field.bug_supervisor=&field.bug_commenter=&field.subscriber=ubuntu-security&field.status_upstream-empty-marker=1&field.omit_dupes.used=&field.omit_dupes=on&field.has_patch.used=&field.has_patch=on&field.has_cve.used=&field.tag=&field.tags_combinator=ANY&search=Search"
66
 
#
67
 
# end should be api-ified section
68
 
#
69
 
 
70
 
for info in BugList(url):
71
 
    num = info.bugnumber
72
 
    bug = lp.bugs[num]
73
 
 
74
 
    bug_url = "http://launchpad.net/bugs/%s" % (num)
75
 
    bug_cves = get_cves(bug)
76
 
 
77
 
    #print "Checking: %s" % (num)
78
 
    for task in bug.bug_tasks:
79
 
        #if task.status != "In Progress":
80
 
        #    continue
81
 
 
82
 
        if not ' (' in task.bug_target_name:
83
 
            #print "Skipping target name=%s" % (task.bug_target_name)
84
 
            continue
85
 
        pkg, target = task.bug_target_name.split(' (',1)
86
 
        target = target.split(')')[0]
87
 
        if ' ' in target:
88
 
            target, targeted_to = target.split(' ',1)
89
 
 
90
 
        if target and target.lower() != 'ubuntu':
91
 
            #print 'skipping target "%s" (%s)' % (target, pkg)
92
 
            continue
93
 
        if task.status in ['Fix Released', 'Invalid', "Won't Fix"]:
94
 
            #print 'skipping (pkg:%s status:%s)' % (pkg, task.status)
95
 
            continue
96
 
 
97
 
        if not re.match(r'^[a-z0-9][a-z0-9+\.\-]+$', pkg):
98
 
            print >>sys.stderr, "Bad package name '%s'" % (pkg)
99
 
            continue
100
 
 
101
 
        has_patch = False
102
 
        for a in bug.attachments:
103
 
            if a.type.lower() == "patch":
104
 
                has_patch = True
105
 
                break
106
 
 
107
 
        if has_patch:
108
 
            print "%s:\n  %s" % (pkg, bug_url)
109
 
            if opt.verbose:
110
 
                print "  %s" % (bug.title)
111
 
 
112
 
            if len(bug_cves) > 0:
113
 
                print "  CVES:",
114
 
                for c in bug_cves:
115
 
                    print "%s" % (c),
116
 
                    filename = "%s/%s" % (cve_lib.active_dir, c)
117
 
                    if opt.update and os.path.exists(filename):
118
 
                        cve_lib.add_patch(filename, pkg, bug_url, type)
119
 
                print ""
120
 
            print ""
121
 
            break
122