Merge ~techalchemy/ubuntu-security-tools:feature/python3-migration into ubuntu-security-tools:master
- Git
- lp:~techalchemy/ubuntu-security-tools
- feature/python3-migration
- Merge into master
Status: | Needs review |
---|---|
Proposed branch: | ~techalchemy/ubuntu-security-tools:feature/python3-migration |
Merge into: | ubuntu-security-tools:master |
Diff against target: |
2788 lines (+994/-686) 39 files modified
audits/pk-list (+12/-10) audits/test/data/encryption/ex_twisted.py (+1/-0) audits/test/test-mir-code-audit.py (+2/-1) audits/uaudit (+24/-15) build-tools/buildlog-compare (+18/-14) build-tools/diff-reorder (+5/-3) build-tools/umt (+105/-102) bzr-tools/plugins/uct-check_syntax.py (+10/-3) bzr-tools/plugins/uct-check_syntax_full.py (+11/-3) p-l-p/bug-status.py (+30/-23) p-l-p/cookies-sql2txt.py (+23/-18) p-l-p/dump-bug.py (+37/-30) p-l-p/in-english.py (+28/-21) p-l-p/is-cache.py (+25/-18) p-l-p/is-private.py (+48/-20) p-l-p/is-support.py (+21/-15) p-l-p/not-a-bug.py (+56/-28) p-l-p/not-private.py (+4/-3) p-l-p/not-security-in-dups.py (+11/-8) p-l-p/not-security-without-comment.py (+48/-20) p-l-p/not-security.py (+49/-20) p-l-p/reassign.py (+24/-22) p-l-p/requires-trojaned-account.py (+2/-1) p-l-p/set-package.py (+3/-2) p-l-p/sub-security.py (+20/-13) p-l-p/tag.py (+3/-2) p-l-p/unsub-in-dups.py (+5/-4) package-tools/debcompare (+28/-23) repo-tools/count-hardened-pkgs (+74/-56) repo-tools/count-hash-sources (+65/-52) repo-tools/for-archive-tools/has-execstack (+30/-15) repo-tools/for-archive-tools/has-symbols (+30/-15) repo-tools/packages-support-status (+61/-52) repo-tools/universe-binaries-with-sources-in-main.py (+7/-3) snaps/coverity-ubuntu-security/files/bin/refresh-auth-key (+2/-1) utilities/build_failures.py (+20/-14) utilities/ceviche (+40/-25) utilities/maildir2mbox.py (+10/-9) utilities/mugshot (+2/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alex Murray | Pending | ||
Review via email: mp+378297@code.launchpad.net |
Commit message
Add support for python 3 across UST
- Add general compatibility for python 3 across UST
- Code convention & minor performance cleanup
- Safer file handle management
- str/bytes consciousness at the filesystem layer
Description of the change
Add python 3 support and minor implementation tweaks described below
- Begin implementing context managers around file handles
- Begin moving unguarded execution blocks to `if __name__ == '__main__'
blocks in case code is ever used as a library (i.e. imported)
- Change print statements to functions
- Use `contextlib.
ensure connections are closed
- Add alternative config parser using `ConfigParser` by adding a dummy
section header when loading config files to avoid `configobj`
- Prefer to decompress remote gzipped content in memory to avoid writing
to disk
- `yaml.safe_load` and `yaml.safe.dump` instead of `load` and `dump
- ceede68... by Dan Ryan
-
syntax fixes
Signed-off-by: Dan Ryan <email address hidden>
Unmerged commits
- ceede68... by Dan Ryan
-
syntax fixes
Signed-off-by: Dan Ryan <email address hidden>
- 41f83d0... by Dan Ryan
-
Merge branch 'master' into feature/
python3- migration - 16ad204... by Dan Ryan
-
Add support for python 3 across UST
- Begin implementing context managers around file handles
- Begin moving unguarded execution blocks to `if __name__ == '__main__'
blocks
- Change print statements to functions
- Use `contextlib.closing` context manager around `urlopen` calls to
ensure connections are closed
- Add alternative config parser using `ConfigParser` by adding a dummy
section header when loading config files to avoid `configobj`
- Prefer to decompress remote gzipped content in memory to avoid writing
to disk
- `yaml.safe_load` and `yaml.safe.dump` instead of `load` and `dump`Signed-off-by: Dan Ryan <email address hidden>
Preview Diff
1 | diff --git a/audits/pk-list b/audits/pk-list | |||
2 | index 48857b5..8faa81a 100755 | |||
3 | --- a/audits/pk-list | |||
4 | +++ b/audits/pk-list | |||
5 | @@ -1,4 +1,4 @@ | |||
7 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
8 | 2 | 2 | ||
9 | 3 | # Author: Jamie Strandboge <jamie@ubuntu.com> | 3 | # Author: Jamie Strandboge <jamie@ubuntu.com> |
10 | 4 | # Copyright 2012 Canonical Ltd. | 4 | # Copyright 2012 Canonical Ltd. |
11 | @@ -13,7 +13,7 @@ | |||
12 | 13 | # TODO: Drop privs | 13 | # TODO: Drop privs |
13 | 14 | # TODO: add dbus reporting | 14 | # TODO: add dbus reporting |
14 | 15 | 15 | ||
16 | 16 | from __future__ import print_function | 16 | from __future__ import absolute_import, print_function |
17 | 17 | 17 | ||
18 | 18 | import glob | 18 | import glob |
19 | 19 | import optparse | 19 | import optparse |
20 | @@ -71,12 +71,12 @@ def get_merged_mapping(default_mapping, package_mapping, local_mapping): | |||
21 | 71 | pat = re.compile(r'%s' % k) | 71 | pat = re.compile(r'%s' % k) |
22 | 72 | for i in merged.keys(): | 72 | for i in merged.keys(): |
23 | 73 | if pat.search(i): | 73 | if pat.search(i): |
25 | 74 | if i not in merged.keys(): | 74 | if i not in merged: |
26 | 75 | continue | 75 | continue |
27 | 76 | merged[i]['overrides']['package'] = package_mapping[k] | 76 | merged[i]['overrides']['package'] = package_mapping[k] |
28 | 77 | #print "%s: %s" % (k, merged[i]['overrides']['package']) | 77 | #print "%s: %s" % (k, merged[i]['overrides']['package']) |
29 | 78 | else: | 78 | else: |
31 | 79 | if k not in merged.keys(): | 79 | if k not in merged: |
32 | 80 | continue | 80 | continue |
33 | 81 | merged[k]['overrides']['package'] = package_mapping[k] | 81 | merged[k]['overrides']['package'] = package_mapping[k] |
34 | 82 | #print "%s: %s" % (k, merged[k]['overrides']['package']) | 82 | #print "%s: %s" % (k, merged[k]['overrides']['package']) |
35 | @@ -221,10 +221,10 @@ class PKOverridesHandler(): | |||
36 | 221 | entries[key] = value | 221 | entries[key] = value |
37 | 222 | _debug(entries) | 222 | _debug(entries) |
38 | 223 | 223 | ||
40 | 224 | if "action" not in entries.keys(): | 224 | if "action" not in entries: |
41 | 225 | _warn("No action for '%s'. Skipping" % (section)) | 225 | _warn("No action for '%s'. Skipping" % (section)) |
42 | 226 | continue | 226 | continue |
44 | 227 | elif "identity" not in entries.keys(): | 227 | elif "identity" not in entries: |
45 | 228 | _warn("No identity for '%s'. Skipping" % (section)) | 228 | _warn("No identity for '%s'. Skipping" % (section)) |
46 | 229 | continue | 229 | continue |
47 | 230 | 230 | ||
48 | @@ -260,7 +260,7 @@ class PKActionsHandler(xml.sax.handler.ContentHandler): | |||
49 | 260 | def startElement(self, name, attrs): | 260 | def startElement(self, name, attrs): |
50 | 261 | _debug("PKActionsHandler.startElement()") | 261 | _debug("PKActionsHandler.startElement()") |
51 | 262 | if name == "action": | 262 | if name == "action": |
53 | 263 | if 'id' in attrs.keys(): | 263 | if 'id' in attrs: |
54 | 264 | self.curr_action = attrs['id'] | 264 | self.curr_action = attrs['id'] |
55 | 265 | self.mapping[self.curr_action] = dict() | 265 | self.mapping[self.curr_action] = dict() |
56 | 266 | self.in_action = True | 266 | self.in_action = True |
57 | @@ -276,11 +276,11 @@ class PKActionsHandler(xml.sax.handler.ContentHandler): | |||
58 | 276 | return | 276 | return |
59 | 277 | 277 | ||
60 | 278 | if re.search(r'_?description', name): | 278 | if re.search(r'_?description', name): |
62 | 279 | if 'xml:lang' not in attrs.keys(): # skip translated strings | 279 | if 'xml:lang' not in attrs: # skip translated strings |
63 | 280 | self.in_description = True | 280 | self.in_description = True |
64 | 281 | self.mapping[self.curr_action]['description'] = "" | 281 | self.mapping[self.curr_action]['description'] = "" |
65 | 282 | elif re.search(r'_?message', name): | 282 | elif re.search(r'_?message', name): |
67 | 283 | if 'xml:lang' not in attrs.keys(): # skip translated strings | 283 | if 'xml:lang' not in attrs: # skip translated strings |
68 | 284 | self.in_message = True | 284 | self.in_message = True |
69 | 285 | self.mapping[self.curr_action]['message'] = "" | 285 | self.mapping[self.curr_action]['message'] = "" |
70 | 286 | elif name == "defaults": | 286 | elif name == "defaults": |
71 | @@ -353,7 +353,9 @@ class PKActionsHandler(xml.sax.handler.ContentHandler): | |||
72 | 353 | 353 | ||
73 | 354 | cleaned_lines = [] | 354 | cleaned_lines = [] |
74 | 355 | skipped_doctype = False | 355 | skipped_doctype = False |
76 | 356 | for line in open(f).readlines(): | 356 | with open(f, "r") as fh: |
77 | 357 | lines = fh.readlines() | ||
78 | 358 | for line in lines: | ||
79 | 357 | if line.startswith("<policyconfig>"): | 359 | if line.startswith("<policyconfig>"): |
80 | 358 | skipped_doctype = True | 360 | skipped_doctype = True |
81 | 359 | if not skipped_doctype: | 361 | if not skipped_doctype: |
82 | diff --git a/audits/test/data/encryption/ex_twisted.py b/audits/test/data/encryption/ex_twisted.py | |||
83 | index 891ca40..6a112a9 100644 | |||
84 | --- a/audits/test/data/encryption/ex_twisted.py | |||
85 | +++ b/audits/test/data/encryption/ex_twisted.py | |||
86 | @@ -1,2 +1,3 @@ | |||
87 | 1 | from __future__ import absolute_import, print_function | ||
88 | 1 | from twisted.internet import reactor, ssl | 2 | from twisted.internet import reactor, ssl |
89 | 2 | from twisted.internet.ssl import ClientContextFactory | 3 | from twisted.internet.ssl import ClientContextFactory |
90 | diff --git a/audits/test/test-mir-code-audit.py b/audits/test/test-mir-code-audit.py | |||
91 | index 4e6d548..73d8b6b 100755 | |||
92 | --- a/audits/test/test-mir-code-audit.py | |||
93 | +++ b/audits/test/test-mir-code-audit.py | |||
94 | @@ -147,7 +147,8 @@ class T(unittest.TestCase): | |||
95 | 147 | for line in report.splitlines(): | 147 | for line in report.splitlines(): |
96 | 148 | if '%s:' % f in line: | 148 | if '%s:' % f in line: |
97 | 149 | content += pat.sub('<path>', line) + "\n" | 149 | content += pat.sub('<path>', line) + "\n" |
99 | 150 | open(tmp, 'w').write(content) | 150 | with open(tmp, 'w') as fh: |
100 | 151 | fh.write(content) | ||
101 | 151 | 152 | ||
102 | 152 | # now compare each test result | 153 | # now compare each test result |
103 | 153 | results = glob.glob("%s/*.result" % self.tmpdir) | 154 | results = glob.glob("%s/*.result" % self.tmpdir) |
104 | diff --git a/audits/uaudit b/audits/uaudit | |||
105 | index 2ef95cf..1da183b 100755 | |||
106 | --- a/audits/uaudit | |||
107 | +++ b/audits/uaudit | |||
108 | @@ -1,4 +1,4 @@ | |||
110 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
111 | 2 | 2 | ||
112 | 3 | # Author: Jamie Strandboge <jamie@ubuntu.com> | 3 | # Author: Jamie Strandboge <jamie@ubuntu.com> |
113 | 4 | # Copyright 2012 Canonical Ltd. | 4 | # Copyright 2012 Canonical Ltd. |
114 | @@ -16,7 +16,8 @@ | |||
115 | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
116 | 17 | # | 17 | # |
117 | 18 | 18 | ||
119 | 19 | from __future__ import print_function | 19 | from __future__ import absolute_import, print_function |
120 | 20 | |||
121 | 20 | from pathlib import Path | 21 | from pathlib import Path |
122 | 21 | import glob | 22 | import glob |
123 | 22 | import optparse | 23 | import optparse |
124 | @@ -28,6 +29,11 @@ import sys | |||
125 | 28 | import tempfile | 29 | import tempfile |
126 | 29 | import json | 30 | import json |
127 | 30 | 31 | ||
128 | 32 | if sys.version_info[0] == 2: | ||
129 | 33 | raw_input = raw_input | ||
130 | 34 | else: | ||
131 | 35 | raw_input = input | ||
132 | 36 | |||
133 | 31 | DEBUGGING = False | 37 | DEBUGGING = False |
134 | 32 | ust = {} | 38 | ust = {} |
135 | 33 | 39 | ||
136 | @@ -125,13 +131,14 @@ def parse_package_details(): | |||
137 | 125 | global ust | 131 | global ust |
138 | 126 | details = {} | 132 | details = {} |
139 | 127 | 133 | ||
140 | 134 | header = [] | ||
141 | 128 | try: | 135 | try: |
143 | 129 | changelog = open('debian/changelog', 'r') | 136 | with open("debian/changelog", "r") as fh: |
144 | 137 | # Extract info from the first line of the changelog | ||
145 | 138 | header = fh.readline().split() | ||
146 | 130 | except Exception: | 139 | except Exception: |
147 | 131 | error("Could not open debian/changelog. Aborting.") | 140 | error("Could not open debian/changelog. Aborting.") |
148 | 132 | 141 | ||
149 | 133 | # Extract info from the first line of the changelog | ||
150 | 134 | header = changelog.readline().split() | ||
151 | 135 | details['package'] = header[0] | 142 | details['package'] = header[0] |
152 | 136 | details['version'] = header[1].strip('()') | 143 | details['version'] = header[1].strip('()') |
153 | 137 | 144 | ||
154 | @@ -186,7 +193,7 @@ def find_build_log(pkg, ver): | |||
155 | 186 | latest = None | 193 | latest = None |
156 | 187 | modified = None | 194 | modified = None |
157 | 188 | for log in glob.glob(ust['pkgbuild_logs'] + '/*%s_*' % (pkg)): | 195 | for log in glob.glob(ust['pkgbuild_logs'] + '/*%s_*' % (pkg)): |
159 | 189 | with open(log) as log_file: | 196 | with open(log, "r") as log_file: |
160 | 190 | line = log_file.readline() | 197 | line = log_file.readline() |
161 | 191 | if not line.startswith("Automatic build of"): | 198 | if not line.startswith("Automatic build of"): |
162 | 192 | # Skip the first three lines of the file for newer sbuild | 199 | # Skip the first three lines of the file for newer sbuild |
163 | @@ -213,8 +220,10 @@ def load_ust_config(config_file): | |||
164 | 213 | 220 | ||
165 | 214 | config = {} | 221 | config = {} |
166 | 215 | # no python-configobj in python3 yet, so read what we need ourselves | 222 | # no python-configobj in python3 yet, so read what we need ourselves |
169 | 216 | for line in open(config_file, 'r').readlines(): | 223 | with open(config_file, "r") as fh: |
170 | 217 | line.strip() | 224 | lines = fh.readlines() |
171 | 225 | for line in lines: | ||
172 | 226 | line = line.strip() | ||
173 | 218 | if line.startswith('#'): | 227 | if line.startswith('#'): |
174 | 219 | continue | 228 | continue |
175 | 220 | if '=' not in line: | 229 | if '=' not in line: |
176 | @@ -264,7 +273,7 @@ def query_user_consent_to_install_tool(tool): | |||
177 | 264 | 273 | ||
178 | 265 | while True: | 274 | while True: |
179 | 266 | sys.stdout.write(question) | 275 | sys.stdout.write(question) |
181 | 267 | choice = input().lower() | 276 | choice = raw_input().lower() |
182 | 268 | if choice in valid_answers: | 277 | if choice in valid_answers: |
183 | 269 | return valid_answers[choice] | 278 | return valid_answers[choice] |
184 | 270 | else: | 279 | else: |
185 | @@ -623,8 +632,8 @@ def cov_analyze(covdir): | |||
186 | 623 | return | 632 | return |
187 | 624 | 633 | ||
188 | 625 | # parse auth token for host and port | 634 | # parse auth token for host and port |
191 | 626 | fp = open(cov_auth_key, 'r') | 635 | with open(cov_auth_key, 'r') as fp: |
192 | 627 | token = json.load(fp) | 636 | token = json.load(fp) |
193 | 628 | host = token['comments']['host'] | 637 | host = token['comments']['host'] |
194 | 629 | port = token['comments']['port'] | 638 | port = token['comments']['port'] |
195 | 630 | project = details['package'] | 639 | project = details['package'] |
196 | @@ -1013,13 +1022,13 @@ if __name__ == "__main__": | |||
197 | 1013 | if not os.path.exists(txt): | 1022 | if not os.path.exists(txt): |
198 | 1014 | msg("Creating %s" % txt) | 1023 | msg("Creating %s" % txt) |
199 | 1015 | # replace variables in file | 1024 | # replace variables in file |
201 | 1016 | s = open(base).read() | 1025 | with open(base, "r") as fh: |
202 | 1026 | s = fh.read() | ||
203 | 1017 | s = s.replace('$package', package) | 1027 | s = s.replace('$package', package) |
204 | 1018 | s = s.replace('$version', details['version']) | 1028 | s = s.replace('$version', details['version']) |
205 | 1019 | s = s.replace('$release', details['release']) | 1029 | s = s.replace('$release', details['release']) |
209 | 1020 | f = open(txt, 'w') | 1030 | with open(txt, "w") as f: |
210 | 1021 | f.write(s) | 1031 | f.write(s) |
208 | 1022 | f.close() | ||
211 | 1023 | else: | 1032 | else: |
212 | 1024 | warn("Could not find %s template to copy" % base) | 1033 | warn("Could not find %s template to copy" % base) |
213 | 1025 | 1034 | ||
214 | diff --git a/build-tools/buildlog-compare b/build-tools/buildlog-compare | |||
215 | index 6225e69..697e3c1 100755 | |||
216 | --- a/build-tools/buildlog-compare | |||
217 | +++ b/build-tools/buildlog-compare | |||
218 | @@ -1,15 +1,18 @@ | |||
220 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
221 | 2 | # Copyright (C) 2007-2018 Canonical, Ltd. | 2 | # Copyright (C) 2007-2018 Canonical, Ltd. |
222 | 3 | # Author: Kees Cook <kees@ubuntu.com> | 3 | # Author: Kees Cook <kees@ubuntu.com> |
223 | 4 | # Jamie Strandboge <jamie@canonical.com> | 4 | # Jamie Strandboge <jamie@canonical.com> |
224 | 5 | # Marc Deslauriers <marc.deslauriers@canonical.com> | 5 | # Marc Deslauriers <marc.deslauriers@canonical.com> |
225 | 6 | # License: GPLv3 | 6 | # License: GPLv3 |
226 | 7 | from __future__ import absolute_import, print_function | ||
227 | 7 | import sys, subprocess, tempfile, re, os | 8 | import sys, subprocess, tempfile, re, os |
228 | 8 | import optparse | 9 | import optparse |
229 | 9 | 10 | ||
230 | 10 | def pull_build_log(filename): | 11 | def pull_build_log(filename): |
231 | 11 | sep = '\nChecking correctness of source dependencies...\n' | 12 | sep = '\nChecking correctness of source dependencies...\n' |
233 | 12 | log = file(filename).read() | 13 | log = "" |
234 | 14 | with open(filename, "r") as fh: | ||
235 | 15 | log = fh.read() | ||
236 | 13 | if sep in log: | 16 | if sep in log: |
237 | 14 | log = log.split(sep,1)[1] | 17 | log = log.split(sep,1)[1] |
238 | 15 | # log = sep.join(log.split(sep)[:-1])+"\n" | 18 | # log = sep.join(log.split(sep)[:-1])+"\n" |
239 | @@ -345,15 +348,16 @@ newlog = re.sub('\[[ 0-9]{4}/[ 0-9]{4}\] Linking', '[XXXX/XXXX] Linking', newlog | |||
240 | 345 | oldlog = re.sub('-DBUILD_DATETIME=...?[0-9]{4}-[0-9]{2}-[0-9]{2}T1?\d:[0-5]\d:[0-5]\d...? ', '-DBUILD_DATETIME=0000-00-00T00:00:00 ', oldlog) | 348 | oldlog = re.sub('-DBUILD_DATETIME=...?[0-9]{4}-[0-9]{2}-[0-9]{2}T1?\d:[0-5]\d:[0-5]\d...? ', '-DBUILD_DATETIME=0000-00-00T00:00:00 ', oldlog) |
241 | 346 | newlog = re.sub('-DBUILD_DATETIME=...?[0-9]{4}-[0-9]{2}-[0-9]{2}T1?\d:[0-5]\d:[0-5]\d...? ', '-DBUILD_DATETIME=0000-00-00T00:00:00 ', newlog) | 349 | newlog = re.sub('-DBUILD_DATETIME=...?[0-9]{4}-[0-9]{2}-[0-9]{2}T1?\d:[0-5]\d:[0-5]\d...? ', '-DBUILD_DATETIME=0000-00-00T00:00:00 ', newlog) |
242 | 347 | 350 | ||
255 | 348 | # Write out the files for diffing | 351 | # Write out the files for diffing, use context managers to clean up temporary |
256 | 349 | oldfile = tempfile.NamedTemporaryFile(prefix='buildlog-') | 352 | # file handles & avoid leaking handles at interpreter exit |
257 | 350 | write_log(oldfile, oldlog, opt.deparallel, pkg) | 353 | with tempfile.NamedTemporaryFile(prefix='buildlog-', mode="w+") as oldfile: |
258 | 351 | 354 | write_log(oldfile, oldlog, opt.deparallel, pkg) | |
259 | 352 | newfile = tempfile.NamedTemporaryFile(prefix='buildlog-') | 355 | oldfile.flush() |
260 | 353 | write_log(newfile, newlog, opt.deparallel, pkg) | 356 | |
261 | 354 | 357 | with tempfile.NamedTemporaryFile(prefix='buildlog-', mode="w+") as newfile: | |
262 | 355 | # To debug, useful to do: | 358 | write_log(newfile, newlog, opt.deparallel, pkg) |
263 | 356 | #shutil.copy(oldfile.name, "/tmp/old") | 359 | newfile.flush() |
264 | 357 | #shutil.copy(newfile.name, "/tmp/new") | 360 | subprocess.call(['diff', '-ub', oldfile.name, newfile.name]) |
265 | 358 | 361 | # To debug, useful to do: | |
266 | 359 | subprocess.call(['diff', '-ub', oldfile.name, newfile.name]) | 362 | #shutil.copy(oldfile.name, "/tmp/old") |
267 | 363 | #shutil.copy(newfile.name, "/tmp/new") | ||
268 | diff --git a/build-tools/diff-reorder b/build-tools/diff-reorder | |||
269 | index ef641de..2a9232f 100755 | |||
270 | --- a/build-tools/diff-reorder | |||
271 | +++ b/build-tools/diff-reorder | |||
272 | @@ -1,4 +1,4 @@ | |||
274 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
275 | 2 | # This tool attempts to balance out +/- lines in the same or | 2 | # This tool attempts to balance out +/- lines in the same or |
276 | 3 | # adjacent diff chunks. When doing parallel builds, output | 3 | # adjacent diff chunks. When doing parallel builds, output |
277 | 4 | # frequently gets out of order, needlessly filling the diff | 4 | # frequently gets out of order, needlessly filling the diff |
278 | @@ -8,6 +8,8 @@ | |||
279 | 8 | # | 8 | # |
280 | 9 | # Copyright (C) 2009, Canonical Ltd. | 9 | # Copyright (C) 2009, Canonical Ltd. |
281 | 10 | # Author: Kees Cook <kees@ubuntu.com> | 10 | # Author: Kees Cook <kees@ubuntu.com> |
282 | 11 | from __future__ import absolute_import, print_function | ||
283 | 12 | |||
284 | 11 | import sys | 13 | import sys |
285 | 12 | 14 | ||
286 | 13 | def plus_minus_lines(hunk): | 15 | def plus_minus_lines(hunk): |
287 | @@ -99,7 +101,7 @@ class Hunk(object): | |||
288 | 99 | for line in self.lines: | 101 | for line in self.lines: |
289 | 100 | if line.startswith('@@') and self.is_empty(): | 102 | if line.startswith('@@') and self.is_empty(): |
290 | 101 | break | 103 | break |
292 | 102 | print prefix + line | 104 | print(prefix + line) |
293 | 103 | 105 | ||
294 | 104 | collector = "" | 106 | collector = "" |
295 | 105 | minus = 0 | 107 | minus = 0 |
296 | @@ -130,7 +132,7 @@ for line in sys.stdin: | |||
297 | 130 | plus = plus - 1 | 132 | plus = plus - 1 |
298 | 131 | else: | 133 | else: |
299 | 132 | # Broken patch! | 134 | # Broken patch! |
301 | 133 | raise ValueError, "Corrupted patch? '%s'" % (line.replace('\n','')) | 135 | raise ValueError("Corrupted patch? '%s'" % (line.replace('\n',''))) |
302 | 134 | if minus == 0 and plus == 0: | 136 | if minus == 0 and plus == 0: |
303 | 135 | # HUNK FINISHED | 137 | # HUNK FINISHED |
304 | 136 | counting = False | 138 | counting = False |
305 | diff --git a/build-tools/umt b/build-tools/umt | |||
306 | index 400294d..69fcb93 100755 | |||
307 | --- a/build-tools/umt | |||
308 | +++ b/build-tools/umt | |||
309 | @@ -1,4 +1,4 @@ | |||
311 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
312 | 2 | 2 | ||
313 | 3 | # Author: Marc Deslauriers <marc.deslauriers@ubuntu.com> | 3 | # Author: Marc Deslauriers <marc.deslauriers@ubuntu.com> |
314 | 4 | # Author: Kees Cook <kees@ubuntu.com> | 4 | # Author: Kees Cook <kees@ubuntu.com> |
315 | @@ -845,114 +845,119 @@ def cmd_compare_log(): | |||
316 | 845 | err("Could not find 'diff-reorder' (is '$UST' set?). Aborting.") | 845 | err("Could not find 'diff-reorder' (is '$UST' set?). Aborting.") |
317 | 846 | sys.exit(1) | 846 | sys.exit(1) |
318 | 847 | 847 | ||
328 | 848 | diff = tempfile.NamedTemporaryFile(suffix='.diff',prefix='umt_compare-log_') | 848 | with tempfile.NamedTemporaryFile( |
329 | 849 | diff.write(b"Log file line counts:\n") | 849 | suffix='.diff',prefix='umt_compare-log_', mode='w+b' |
330 | 850 | diff.flush() | 850 | ) as diff, tempfile.NamedTemporaryFile( |
331 | 851 | subprocess.call(['wc','-l','--',old_logfile],stdout=diff) | 851 | suffix='.diff', prefix='umt_compare-log_', mode='w+b' |
332 | 852 | subprocess.call(['wc','-l','--',new_logfile],stdout=diff) | 852 | ) as patches_diff: |
333 | 853 | diff.write(b"\n") | 853 | diff.write(b"Log file line counts:\n") |
334 | 854 | diff.flush() | 854 | diff.flush() |
335 | 855 | command = [buildlog_compare] | 855 | subprocess.check_call(['wc','-l','--',old_logfile], stdout=diff) |
336 | 856 | if opt.deparallel: | 856 | subprocess.check_call(['wc','-l','--',new_logfile], stdout=diff) |
337 | 857 | diff.write(b"\n") | ||
338 | 858 | diff.flush() | ||
339 | 859 | command = [buildlog_compare] | ||
340 | 860 | if opt.deparallel: | ||
341 | 861 | if opt.balance: | ||
342 | 862 | err("Skipping --balance with --deparallel") | ||
343 | 863 | else: | ||
344 | 864 | command.append("--deparallel") | ||
345 | 865 | command += [details['package'],details['base_version_prior'],old_logfile,details['base_version'],new_logfile] | ||
346 | 866 | |||
347 | 857 | if opt.balance: | 867 | if opt.balance: |
349 | 858 | err("Skipping --balance with --deparallel") | 868 | p1 = subprocess.Popen(command, stdout=subprocess.PIPE) |
350 | 869 | p2 = subprocess.Popen([diff_reorder], stdin=p1.stdout, stdout=subprocess.PIPE) | ||
351 | 870 | diff.write(p2.communicate()[0]) | ||
352 | 859 | else: | 871 | else: |
363 | 860 | command.append("--deparallel") | 872 | try: |
364 | 861 | command += [details['package'],details['base_version_prior'],old_logfile,details['base_version'],new_logfile] | 873 | subprocess.check_call(command, stdout=diff) |
365 | 862 | 874 | except subprocess.CalledProcessError as e: | |
366 | 863 | if opt.balance: | 875 | sys.exit(e.returncode) |
367 | 864 | p1 = subprocess.Popen(command, stdout=subprocess.PIPE) | 876 | diff.flush() |
358 | 865 | p2 = subprocess.Popen([diff_reorder], stdin=p1.stdout, stdout=subprocess.PIPE) | ||
359 | 866 | diff.write(p2.communicate()[0]) | ||
360 | 867 | else: | ||
361 | 868 | if subprocess.call(command,stdout=diff) != 0: | ||
362 | 869 | sys.exit(1) | ||
368 | 870 | 877 | ||
373 | 871 | diff.flush() | 878 | if opt.dump_to_stdout: |
374 | 872 | if opt.dump_to_stdout: | 879 | subprocess.call(['cat', diff.name]) |
375 | 873 | subprocess.call(['cat', diff.name]) | 880 | return |
372 | 874 | return | ||
376 | 875 | 881 | ||
382 | 876 | editor = os.getenv('EDITOR') or 'vi' | 882 | editor = os.getenv('EDITOR') or 'vi' |
383 | 877 | if editor.find('vi') >= 0: | 883 | if editor.find('vi') >= 0: |
384 | 878 | subprocess.call([editor,'+set syntax=diff', diff.name]) | 884 | subprocess.call([editor,'+set syntax=diff', diff.name]) |
385 | 879 | else: | 885 | else: |
386 | 880 | subprocess.call([editor, diff.name]) | 886 | subprocess.call([editor, diff.name]) |
387 | 881 | 887 | ||
393 | 882 | # Show what is happening to the patches in a build | 888 | # Show what is happening to the patches in a build |
394 | 883 | patches_diff = tempfile.NamedTemporaryFile(suffix='.diff',prefix='umt_compare-log_') | 889 | patches_diff.write(b"Listing of applied patch differences:\n") |
395 | 884 | patches_diff.write(b"Listing of applied patch differences:\n") | 890 | patches_diff.write(("%s\n%s\n" % (old_logfile, new_logfile)).encode()) |
396 | 885 | patches_diff.write(("%s\n%s\n" % (old_logfile, new_logfile)).encode()) | 891 | patches_diff.flush() |
392 | 886 | patches_diff.flush() | ||
397 | 887 | 892 | ||
412 | 888 | (rc, report) = runcmd(['what-patch']) | 893 | (rc, report) = runcmd(['what-patch']) |
413 | 889 | if rc != 0: | 894 | if rc != 0: |
414 | 890 | err("running 'what-patch':\n%s" % report) | 895 | err("running 'what-patch':\n%s" % report) |
415 | 891 | sys.exit(1) | 896 | sys.exit(1) |
416 | 892 | patch_system = report.strip() | 897 | patch_system = report.strip() |
417 | 893 | 898 | ||
418 | 894 | if patch_system == "quilt" or patch_system == "dpatch" or patch_system == "cdbs": | 899 | if patch_system == "quilt" or patch_system == "dpatch" or patch_system == "cdbs": |
419 | 895 | patch_list = [] | 900 | patch_list = [] |
420 | 896 | skip = False | 901 | skip = False |
421 | 897 | if patch_system == "cdbs": | 902 | if patch_system == "cdbs": |
422 | 898 | fn = "debian/patches" | 903 | fn = "debian/patches" |
423 | 899 | if not os.path.isdir(fn): | 904 | if not os.path.isdir(fn): |
424 | 900 | patches_diff.write(("Skipping checks for patch system '%s', missing '%s'" % (patch_system, fn)).encode()) | 905 | patches_diff.write(("Skipping checks for patch system '%s', missing '%s'" % (patch_system, fn)).encode()) |
425 | 901 | skip = True | 906 | skip = True |
426 | 907 | else: | ||
427 | 908 | for p in os.listdir(fn): | ||
428 | 909 | if p.endswith('.patch') or p.endswith('.diff'): | ||
429 | 910 | patch_list.append(".".join(p.split('.')[:-1])) | ||
430 | 911 | else: | ||
431 | 912 | patch_list.append(p) | ||
432 | 913 | patch_list.sort() | ||
433 | 902 | else: | 914 | else: |
443 | 903 | for p in os.listdir(fn): | 915 | if patch_system == "quilt": |
444 | 904 | if p.endswith('.patch') or p.endswith('.diff'): | 916 | fn = "debian/patches/series.in" |
445 | 905 | patch_list.append(".".join(p.split('.')[:-1])) | 917 | if not os.path.exists(fn): |
446 | 906 | else: | 918 | fn = "debian/patches/series" |
447 | 907 | patch_list.append(p) | 919 | elif patch_system == "dpatch": |
448 | 908 | patch_list.sort() | 920 | fn = "debian/patches/00list" |
449 | 909 | else: | 921 | |
441 | 910 | if patch_system == "quilt": | ||
442 | 911 | fn = "debian/patches/series.in" | ||
450 | 912 | if not os.path.exists(fn): | 922 | if not os.path.exists(fn): |
454 | 913 | fn = "debian/patches/series" | 923 | patches_diff.write(("Skipping checks for patch system '%s', missing '%s'" % (patch_system, fn)).encode()) |
455 | 914 | elif patch_system == "dpatch": | 924 | skip = True |
456 | 915 | fn = "debian/patches/00list" | 925 | else: |
457 | 926 | for p in open(fn).readlines(): | ||
458 | 927 | p = p.strip() | ||
459 | 928 | if p.startswith('#') or re.search(r'^\s*$', p): | ||
460 | 929 | continue | ||
461 | 930 | if p.endswith('.dpatch') or p.endswith('.patch') or p.endswith('.diff'): | ||
462 | 931 | patch_list.append(".".join(p.split('.')[:-1])) | ||
463 | 932 | else: | ||
464 | 933 | patch_list.append(p) | ||
465 | 934 | if not skip: | ||
466 | 935 | tmp = "" | ||
467 | 936 | for p in patch_list: | ||
468 | 937 | (rc, report) = runcmd(['egrep', p, diff.name]) | ||
469 | 916 | 938 | ||
486 | 917 | if not os.path.exists(fn): | 939 | tmp = "" |
487 | 918 | patches_diff.write(("Skipping checks for patch system '%s', missing '%s'" % (patch_system, fn)).encode()) | 940 | for line in report.splitlines(): |
488 | 919 | skip = True | 941 | if patch_system == "cdbs" and re.search(r'^[+-]patches: ', line): |
489 | 920 | else: | 942 | continue |
490 | 921 | for p in open(fn).readlines(): | 943 | if (line.startswith('-') or line.startswith('+')) and not re.search(r'^[+-] ', line): |
491 | 922 | p = p.strip() | 944 | if line.startswith('+revert'): |
492 | 923 | if p.startswith('#') or re.search(r'^\s*$', p): | 945 | tmp += "# UMT WARNING: This patch was reverted. This may be a problem.\n" |
493 | 924 | continue | 946 | tmp += "# UMT WARNING: Check debian/rules and/or README.source for details.\n" |
494 | 925 | if p.endswith('.dpatch') or p.endswith('.patch') or p.endswith('.diff'): | 947 | tmp += line + "\n" |
479 | 926 | patch_list.append(".".join(p.split('.')[:-1])) | ||
480 | 927 | else: | ||
481 | 928 | patch_list.append(p) | ||
482 | 929 | if not skip: | ||
483 | 930 | tmp = "" | ||
484 | 931 | for p in patch_list: | ||
485 | 932 | (rc, report) = runcmd(['egrep', p, diff.name]) | ||
495 | 933 | 948 | ||
499 | 934 | tmp = "" | 949 | if tmp == "": |
497 | 935 | for line in report.splitlines(): | ||
498 | 936 | if patch_system == "cdbs" and re.search(r'^[+-]patches: ', line): | ||
500 | 937 | continue | 950 | continue |
519 | 938 | if (line.startswith('-') or line.startswith('+')) and not re.search(r'^[+-] ', line): | 951 | else: |
520 | 939 | if line.startswith('+revert'): | 952 | patches_diff.write(("\n%s:" % (p)).encode()) |
521 | 940 | tmp += "# UMT WARNING: This patch was reverted. This may be a problem.\n" | 953 | patches_diff.write(tmp.encode()) |
522 | 941 | tmp += "# UMT WARNING: Check debian/rules and/or README.source for details.\n" | 954 | else: |
523 | 942 | tmp += line + "\n" | 955 | patches_diff.write(("Skipping checks for patch system '%s'" % (patch_system)).encode()) |
524 | 943 | 956 | patches_diff.flush() | |
525 | 944 | if tmp == "": | 957 | if editor.find('vi') >= 0: |
526 | 945 | continue | 958 | subprocess.call([editor,'+set syntax=diff', patches_diff.name]) |
527 | 946 | else: | 959 | else: |
528 | 947 | patches_diff.write(("\n%s:" % (p)).encode()) | 960 | subprocess.call([editor, patches_diff.name]) |
511 | 948 | patches_diff.write(tmp.encode()) | ||
512 | 949 | else: | ||
513 | 950 | patches_diff.write(("Skipping checks for patch system '%s'" % (patch_system)).encode()) | ||
514 | 951 | patches_diff.flush() | ||
515 | 952 | if editor.find('vi') >= 0: | ||
516 | 953 | subprocess.call([editor,'+set syntax=diff', patches_diff.name]) | ||
517 | 954 | else: | ||
518 | 955 | subprocess.call([editor, patches_diff.name]) | ||
529 | 956 | 961 | ||
530 | 957 | def cmd_compare_bin(): | 962 | def cmd_compare_bin(): |
531 | 958 | '''Compare binary debs with prior version''' | 963 | '''Compare binary debs with prior version''' |
532 | @@ -1352,10 +1357,8 @@ Acquire::Languages "none"; | |||
533 | 1352 | continue | 1357 | continue |
534 | 1353 | 1358 | ||
535 | 1354 | path = os.path.join(reports_dest, b + '_' + arch + '.txt') | 1359 | path = os.path.join(reports_dest, b + '_' + arch + '.txt') |
540 | 1355 | handle = open(path,"w+") | 1360 | with open(path,"w+") as handle: |
541 | 1356 | handle.write(report) | 1361 | handle.write(report) |
538 | 1357 | handle.flush() | ||
539 | 1358 | handle.close() | ||
542 | 1359 | 1362 | ||
543 | 1360 | if opt.edit: | 1363 | if opt.edit: |
544 | 1361 | editor = os.getenv('EDITOR') or 'vi' | 1364 | editor = os.getenv('EDITOR') or 'vi' |
545 | diff --git a/bzr-tools/plugins/uct-check_syntax.py b/bzr-tools/plugins/uct-check_syntax.py | |||
546 | index c22e3a7..5f7b56c 100644 | |||
547 | --- a/bzr-tools/plugins/uct-check_syntax.py | |||
548 | +++ b/bzr-tools/plugins/uct-check_syntax.py | |||
549 | @@ -1,13 +1,20 @@ | |||
551 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
552 | 2 | 2 | ||
554 | 3 | from __future__ import print_function | 3 | from __future__ import absolute_import, print_function |
555 | 4 | |||
556 | 5 | import sys | ||
557 | 4 | 6 | ||
558 | 5 | from bzrlib.branch import Branch | 7 | from bzrlib.branch import Branch |
559 | 6 | 8 | ||
560 | 9 | if sys.version_info[0] == 2: | ||
561 | 10 | raw_input = raw_input | ||
562 | 11 | else: | ||
563 | 12 | raw_input = input | ||
564 | 13 | |||
565 | 7 | def run_tests(local, master, old_revno, old_revid, new_revno, new_revid, tree_delta, new_tree): | 14 | def run_tests(local, master, old_revno, old_revid, new_revno, new_revid, tree_delta, new_tree): |
566 | 8 | # print(local, master, old_revno, old_revid, new_revno, new_revid, tree_delta, new_tree) | 15 | # print(local, master, old_revno, old_revid, new_revno, new_revid, tree_delta, new_tree) |
567 | 9 | import os | 16 | import os |
569 | 10 | if 'ubuntu-cve-tracker' in master.base and not os.environ.has_key('UCT_IGNORE_CHECK_SYNTAX'): | 17 | if 'ubuntu-cve-tracker' in master.base and 'UCT_IGNORE_CHECK_SYNTAX' not in os.environ: |
570 | 11 | import subprocess | 18 | import subprocess |
571 | 12 | print('') | 19 | print('') |
572 | 13 | 20 | ||
573 | diff --git a/bzr-tools/plugins/uct-check_syntax_full.py b/bzr-tools/plugins/uct-check_syntax_full.py | |||
574 | index a9e2d5c..14eaea0 100644 | |||
575 | --- a/bzr-tools/plugins/uct-check_syntax_full.py | |||
576 | +++ b/bzr-tools/plugins/uct-check_syntax_full.py | |||
577 | @@ -1,12 +1,20 @@ | |||
579 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
580 | 2 | from __future__ import absolute_import, print_function | ||
581 | 3 | import sys | ||
582 | 2 | from bzrlib.branch import Branch | 4 | from bzrlib.branch import Branch |
583 | 3 | 5 | ||
584 | 6 | if sys.version_info[0] == 2: | ||
585 | 7 | raw_input = raw_input | ||
586 | 8 | else: | ||
587 | 9 | raw_input = input | ||
588 | 10 | |||
589 | 11 | |||
590 | 4 | def run_tests(local, master, old_revno, old_revid, new_revno, new_revid, seven, eight): | 12 | def run_tests(local, master, old_revno, old_revid, new_revno, new_revid, seven, eight): |
591 | 5 | #print local, master, old_revno, old_revid, new_revno, new_revid, seven, eight | 13 | #print local, master, old_revno, old_revid, new_revno, new_revid, seven, eight |
592 | 6 | import os | 14 | import os |
594 | 7 | if 'ubuntu-cve-tracker' in master.base and not os.environ.has_key('UCT_IGNORE_CHECK_SYNTAX'): | 15 | if 'ubuntu-cve-tracker' in master.base and 'UCT_IGNORE_CHECK_SYNTAX' not in os.environ: |
595 | 8 | import subprocess | 16 | import subprocess |
597 | 9 | print '' | 17 | print('') |
598 | 10 | rc = subprocess.call(['./scripts/check-syntax','--verbose']) | 18 | rc = subprocess.call(['./scripts/check-syntax','--verbose']) |
599 | 11 | if rc != 0: | 19 | if rc != 0: |
600 | 12 | import sys | 20 | import sys |
601 | diff --git a/p-l-p/bug-status.py b/p-l-p/bug-status.py | |||
602 | index 16cbfbf..55c0bc9 100755 | |||
603 | --- a/p-l-p/bug-status.py | |||
604 | +++ b/p-l-p/bug-status.py | |||
605 | @@ -1,36 +1,43 @@ | |||
607 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
608 | 2 | # Copyright (C) 2007 Canonical, Ltd. Jamie Strandboge <jamie@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Jamie Strandboge <jamie@ubuntu.com> |
609 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
610 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
612 | 5 | import sys | 5 | from __future__ import absolute_import, print_function |
613 | 6 | |||
614 | 6 | import os | 7 | import os |
615 | 8 | import sys | ||
616 | 7 | import launchpadbugs.connector as Connector | 9 | import launchpadbugs.connector as Connector |
617 | 8 | 10 | ||
618 | 9 | Bug = Connector.ConnectBug() | ||
619 | 10 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | ||
620 | 11 | 11 | ||
623 | 12 | for num in sys.argv[1:]: | 12 | def print_bugs(): |
624 | 13 | bug = Bug(int(num)) | 13 | Bug = Connector.ConnectBug() |
625 | 14 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | ||
626 | 15 | |||
627 | 16 | for num in sys.argv[1:]: | ||
628 | 17 | bug = Bug(int(num)) | ||
629 | 18 | |||
630 | 19 | print(num + ": " + bug.title) | ||
631 | 20 | print(" URL: https://bugs.launchpad.net/bugs/" + num) | ||
632 | 21 | if bug.duplicate_of: | ||
633 | 22 | print(" Duplicate of " + str(bug.duplicate_of)) | ||
634 | 23 | print(" Status: " + bug.status + "\n") | ||
635 | 14 | 24 | ||
641 | 15 | print num + ": " + bug.title | 25 | if bug.private: |
642 | 16 | print " URL: https://bugs.launchpad.net/bugs/" + num | 26 | print(" Private: yes") |
643 | 17 | if bug.duplicate_of: | 27 | else: |
644 | 18 | print " Duplicate of " + str(bug.duplicate_of) | 28 | print(" Private: no") |
640 | 19 | print " Status: " + bug.status + "\n" | ||
645 | 20 | 29 | ||
650 | 21 | if bug.private: | 30 | if bug.security: |
651 | 22 | print " Private: yes" | 31 | print(" Security: yes") |
652 | 23 | else: | 32 | else: |
653 | 24 | print " Private: no" | 33 | print(" Security: no") |
654 | 25 | 34 | ||
659 | 26 | if bug.security: | 35 | print("\n Subscribers:") |
660 | 27 | print " Security: yes" | 36 | for s in bug.subscribers: |
661 | 28 | else: | 37 | print(" " + s) |
658 | 29 | print " Security: no" | ||
662 | 30 | 38 | ||
666 | 31 | print "\n Subscribers:" | 39 | print("\n--\n") |
664 | 32 | for s in bug.subscribers: | ||
665 | 33 | print " " + s | ||
667 | 34 | 40 | ||
668 | 35 | print "\n--\n" | ||
669 | 36 | 41 | ||
670 | 42 | if __name__ == "__main__": | ||
671 | 43 | print_bugs() | ||
672 | 37 | \ No newline at end of file | 44 | \ No newline at end of file |
673 | diff --git a/p-l-p/cookies-sql2txt.py b/p-l-p/cookies-sql2txt.py | |||
674 | index cc6347c..304ca01 100755 | |||
675 | --- a/p-l-p/cookies-sql2txt.py | |||
676 | +++ b/p-l-p/cookies-sql2txt.py | |||
677 | @@ -1,33 +1,38 @@ | |||
679 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
680 | 2 | # Extract.cookies.sqlite.txt-like file from FF3 sqlite3 cookies file. e.g.: | 2 | # Extract.cookies.sqlite.txt-like file from FF3 sqlite3 cookies file. e.g.: |
681 | 3 | # .cookies.sqlite-sql2txt ~/.mozilla/*/cookies.sqlite launchpad | 3 | # .cookies.sqlite-sql2txt ~/.mozilla/*/cookies.sqlite launchpad |
682 | 4 | # | 4 | # |
683 | 5 | # Copyright 2008 Kees Cook <kees@outflux.net> | 5 | # Copyright 2008 Kees Cook <kees@outflux.net> |
684 | 6 | # License: GPLv2 | 6 | # License: GPLv2 |
686 | 7 | import sys | 7 | from __future__ import absolute_import, print_function |
687 | 8 | import os | 8 | import os |
688 | 9 | import sys | ||
689 | 10 | # TODO: Migrate this to sqlite3 + argparse | ||
690 | 9 | from pysqlite2 import dbapi2 as sqlite | 11 | from pysqlite2 import dbapi2 as sqlite |
691 | 10 | 12 | ||
694 | 11 | def usage(): | 13 | def print_usage(): |
695 | 12 | print >>sys.stderr, "Usage: %s SQLITE3DB DOMAIN" | 14 | print("Usage: %s SQLITE3DB DOMAIN", file=sys.stderr) |
696 | 13 | sys.exit(1) | 15 | sys.exit(1) |
697 | 14 | 16 | ||
698 | 15 | try: | ||
699 | 16 | filename = sys.argv[1] | ||
700 | 17 | match = '%%%s%%' % sys.argv[2] | ||
701 | 18 | except: | ||
702 | 19 | usage() | ||
703 | 20 | 17 | ||
705 | 21 | con = sqlite.connect(filename) | 18 | def print_cookie_file(filename, match_param): |
706 | 19 | match = '%%%s%%' % match_param | ||
707 | 20 | con = sqlite.connect(filename) | ||
708 | 21 | |||
709 | 22 | cur = con.cursor() | ||
710 | 23 | cur.execute("select host, path, isSecure, expiry, name, value from moz.cookies.sqlite where host like ?", [match]) | ||
711 | 22 | 24 | ||
714 | 23 | cur = con.cursor() | 25 | ftstr = ["FALSE","TRUE"] |
713 | 24 | cur.execute("select host, path, isSecure, expiry, name, value from moz.cookies.sqlite where host like ?", [match]) | ||
715 | 25 | 26 | ||
717 | 26 | ftstr = ["FALSE","TRUE"] | 27 | print('# HTTP Cookie File') |
718 | 28 | for item in cur.fetchall(): | ||
719 | 29 | print("%s\t%s\t%s\t%s\t%s\t%s\t%s" % ( | ||
720 | 30 | item[0], ftstr[item[0].startswith('.')], item[1], | ||
721 | 31 | ftstr[item[2]], item[3], item[4], item[5])) | ||
722 | 27 | 32 | ||
723 | 28 | print '# HTTP Cookie File' | ||
724 | 29 | for item in cur.fetchall(): | ||
725 | 30 | print "%s\t%s\t%s\t%s\t%s\t%s\t%s" % ( | ||
726 | 31 | item[0], ftstr[item[0].startswith('.')], item[1], | ||
727 | 32 | ftstr[item[2]], item[3], item[4], item[5]) | ||
728 | 33 | 33 | ||
729 | 34 | if __name__ == "__main__": | ||
730 | 35 | try: | ||
731 | 36 | print_cookie_file(sys.argv[1], sys.argv[2]) | ||
732 | 37 | except Exception: | ||
733 | 38 | print_usage() | ||
734 | 34 | \ No newline at end of file | 39 | \ No newline at end of file |
735 | diff --git a/p-l-p/dump-bug.py b/p-l-p/dump-bug.py | |||
736 | index 8b7d8d6..bf2851a 100755 | |||
737 | --- a/p-l-p/dump-bug.py | |||
738 | +++ b/p-l-p/dump-bug.py | |||
739 | @@ -1,15 +1,16 @@ | |||
741 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
742 | 2 | # Copyright (C) 2007 Canonical, Ltd. Jamie Strandboge <jamie@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Jamie Strandboge <jamie@ubuntu.com> |
743 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
744 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
745 | 5 | from __future__ import absolute_import, print_function | ||
746 | 5 | import sys | 6 | import sys |
747 | 6 | import os | 7 | import os |
748 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
749 | 8 | 9 | ||
750 | 9 | 10 | ||
751 | 10 | def printDict(di, format="%-25s %s"): | 11 | def printDict(di, format="%-25s %s"): |
754 | 11 | for (key, val) in di.items(): | 12 | for key, val in di.items(): |
755 | 12 | print format % (str(key)+':', val) | 13 | print(format % (str(key)+':', val)) |
756 | 13 | 14 | ||
757 | 14 | def dumpObj(obj, maxlen=77, lindent=24, maxspew=600): | 15 | def dumpObj(obj, maxlen=77, lindent=24, maxspew=600): |
758 | 15 | """Print a nicely formatted overview of an object. | 16 | """Print a nicely formatted overview of an object. |
759 | @@ -79,7 +80,7 @@ def dumpObj(obj, maxlen=77, lindent=24, maxspew=600): | |||
760 | 79 | elif (isinstance(attr, types.MethodType) or | 80 | elif (isinstance(attr, types.MethodType) or |
761 | 80 | isinstance(attr, types.FunctionType)): | 81 | isinstance(attr, types.FunctionType)): |
762 | 81 | methods.append( (slot, attr) ) | 82 | methods.append( (slot, attr) ) |
764 | 82 | elif isinstance(attr, types.TypeType): | 83 | elif isinstance(attr, type): |
765 | 83 | classes.append( (slot, attr) ) | 84 | classes.append( (slot, attr) ) |
766 | 84 | else: | 85 | else: |
767 | 85 | attrs.append( (slot, attr) ) | 86 | attrs.append( (slot, attr) ) |
768 | @@ -109,57 +110,57 @@ def dumpObj(obj, maxlen=77, lindent=24, maxspew=600): | |||
769 | 109 | objclass = type(obj).__name__ | 110 | objclass = type(obj).__name__ |
770 | 110 | intro = "Instance of class '%s' as defined in module %s with id %d" % \ | 111 | intro = "Instance of class '%s' as defined in module %s with id %d" % \ |
771 | 111 | (objclass, objmodule, id(obj)) | 112 | (objclass, objmodule, id(obj)) |
773 | 112 | print '\n'.join(prettyPrint(intro, maxlen)) | 113 | print('\n'.join(prettyPrint(intro, maxlen))) |
774 | 113 | 114 | ||
775 | 114 | # Object's Docstring | 115 | # Object's Docstring |
776 | 115 | if objdoc is None: | 116 | if objdoc is None: |
777 | 116 | objdoc = str(objdoc) | 117 | objdoc = str(objdoc) |
778 | 117 | else: | 118 | else: |
779 | 118 | objdoc = ('"""' + objdoc.strip() + '"""') | 119 | objdoc = ('"""' + objdoc.strip() + '"""') |
782 | 119 | 120 | print() | |
783 | 120 | print prettyPrintCols( ('Documentation string:', | 121 | print(prettyPrintCols( ('Documentation string:', |
784 | 121 | truncstring(objdoc, maxspew)), | 122 | truncstring(objdoc, maxspew)), |
786 | 122 | normalwidths, ' ') | 123 | normalwidths, ' ')) |
787 | 123 | 124 | ||
788 | 124 | # Built-in methods | 125 | # Built-in methods |
789 | 125 | if builtins: | 126 | if builtins: |
790 | 126 | bi_str = delchars(str(builtins), "[']") or str(None) | 127 | bi_str = delchars(str(builtins), "[']") or str(None) |
793 | 127 | 128 | print() | |
794 | 128 | print prettyPrintCols( ('Built-in Methods:', | 129 | print(prettyPrintCols( ('Built-in Methods:', |
795 | 129 | truncstring(bi_str, maxspew)), | 130 | truncstring(bi_str, maxspew)), |
797 | 130 | normalwidths, ', ') | 131 | normalwidths, ', ')) |
798 | 131 | 132 | ||
799 | 132 | # Classes | 133 | # Classes |
800 | 133 | if classes: | 134 | if classes: |
803 | 134 | 135 | print() | |
804 | 135 | print 'Classes:' | 136 | print('Classes:') |
805 | 136 | for (classname, classtype) in classes: | 137 | for (classname, classtype) in classes: |
806 | 137 | classdoc = getattr(classtype, '__doc__', None) or '<No documentation>' | 138 | classdoc = getattr(classtype, '__doc__', None) or '<No documentation>' |
808 | 138 | print prettyPrintCols( ('', | 139 | print(prettyPrintCols( ('', |
809 | 139 | classname, | 140 | classname, |
810 | 140 | truncstring(classdoc, maxspew)), | 141 | truncstring(classdoc, maxspew)), |
812 | 141 | tabbedwidths, ' ') | 142 | tabbedwidths, ' ')) |
813 | 142 | 143 | ||
814 | 143 | # User methods | 144 | # User methods |
815 | 144 | if methods: | 145 | if methods: |
818 | 145 | 146 | print() | |
819 | 146 | print 'Methods:' | 147 | print('Methods:') |
820 | 147 | for (methodname, method) in methods: | 148 | for (methodname, method) in methods: |
821 | 148 | methoddoc = getattr(method, '__doc__', None) or '<No documentation>' | 149 | methoddoc = getattr(method, '__doc__', None) or '<No documentation>' |
823 | 149 | print prettyPrintCols( ('', | 150 | print(prettyPrintCols( ('', |
824 | 150 | methodname, | 151 | methodname, |
825 | 151 | truncstring(methoddoc, maxspew)), | 152 | truncstring(methoddoc, maxspew)), |
827 | 152 | tabbedwidths, ' ') | 153 | tabbedwidths, ' ')) |
828 | 153 | 154 | ||
829 | 154 | # Attributes | 155 | # Attributes |
830 | 155 | if attrs: | 156 | if attrs: |
833 | 156 | 157 | print() | |
834 | 157 | print 'Attributes:' | 158 | print('Attributes:') |
835 | 158 | for (attr, val) in attrs: | 159 | for (attr, val) in attrs: |
837 | 159 | print prettyPrintCols( ('', | 160 | print(prettyPrintCols( ('', |
838 | 160 | attr, | 161 | attr, |
839 | 161 | truncstring(str(val), maxspew)), | 162 | truncstring(str(val), maxspew)), |
841 | 162 | tabbedwidths, ' ') | 163 | tabbedwidths, ' ')) |
842 | 163 | 164 | ||
843 | 164 | def prettyPrintCols(strings, widths, split=' '): | 165 | def prettyPrintCols(strings, widths, split=' '): |
844 | 165 | """Pretty prints text in colums, with each string breaking at | 166 | """Pretty prints text in colums, with each string breaking at |
845 | @@ -168,7 +169,7 @@ def prettyPrintCols(strings, widths, split=' '): | |||
846 | 168 | 169 | ||
847 | 169 | assert len(strings) == len(widths) | 170 | assert len(strings) == len(widths) |
848 | 170 | 171 | ||
850 | 171 | strings = map(nukenewlines, strings) | 172 | strings = list(map(nukenewlines, strings)) |
851 | 172 | 173 | ||
852 | 173 | # pretty print each column | 174 | # pretty print each column |
853 | 174 | cols = [''] * len(strings) | 175 | cols = [''] * len(strings) |
854 | @@ -179,7 +180,7 @@ def prettyPrintCols(strings, widths, split=' '): | |||
855 | 179 | format = ''.join(["%%-%ds" % width for width in widths[0:-1]]) + "%s" | 180 | format = ''.join(["%%-%ds" % width for width in widths[0:-1]]) + "%s" |
856 | 180 | 181 | ||
857 | 181 | def formatline(*cols): | 182 | def formatline(*cols): |
859 | 182 | return format % tuple(map(lambda s: (s or ''), cols)) | 183 | return format % tuple([(s or '') for s in cols]) |
860 | 183 | 184 | ||
861 | 184 | # generate the formatted text | 185 | # generate the formatted text |
862 | 185 | return '\n'.join(map(formatline, *cols)) | 186 | return '\n'.join(map(formatline, *cols)) |
863 | @@ -226,11 +227,17 @@ def delchars(str, chars): | |||
864 | 226 | return str.translate(identity, chars) | 227 | return str.translate(identity, chars) |
865 | 227 | 228 | ||
866 | 228 | 229 | ||
869 | 229 | Bug = Connector.ConnectBug() | 230 | # TODO: Migrate this to argparse |
868 | 230 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | ||
870 | 231 | 231 | ||
873 | 232 | for num in sys.argv[1:]: | 232 | def print_bugs(*bugs): |
874 | 233 | bug = Bug(int(num)) | 233 | Bug = Connector.ConnectBug() |
875 | 234 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | ||
876 | 234 | 235 | ||
878 | 235 | dumpObj(bug, 1024, 24, 1024) | 236 | for num in bugs: |
879 | 237 | bug = Bug(int(num)) | ||
880 | 236 | 238 | ||
881 | 239 | dumpObj(bug, 1024, 24, 1024) | ||
882 | 240 | |||
883 | 241 | |||
884 | 242 | if __name__ == "__main__": | ||
885 | 243 | print_bugs(*sys.argv[1:]) | ||
886 | 237 | \ No newline at end of file | 244 | \ No newline at end of file |
887 | diff --git a/p-l-p/in-english.py b/p-l-p/in-english.py | |||
888 | index 8e56db0..ad75f5e 100755 | |||
889 | --- a/p-l-p/in-english.py | |||
890 | +++ b/p-l-p/in-english.py | |||
891 | @@ -1,30 +1,37 @@ | |||
893 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
894 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
895 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
896 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
898 | 5 | import sys | 5 | from __future__ import absolute_import, print_function |
899 | 6 | import os | 6 | import os |
900 | 7 | import sys | ||
901 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
902 | 8 | 9 | ||
903 | 9 | Bug = Connector.ConnectBug() | 10 | Bug = Connector.ConnectBug() |
904 | 10 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | 11 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') |
905 | 11 | 12 | ||
925 | 12 | for num in sys.argv[1:]: | 13 | |
926 | 13 | bug = Bug(num) | 14 | def reassign_bugs_to_bugs_queue(*bugs) |
927 | 14 | 15 | for num in bugs: | |
928 | 15 | try: | 16 | bug = Bug(num) |
929 | 16 | bug.subscribers.add("ubuntu-bugs") | 17 | |
930 | 17 | except: | 18 | try: |
931 | 18 | pass | 19 | bug.subscribers.add("ubuntu-bugs") |
932 | 19 | 20 | except: | |
933 | 20 | comment = Bug.NewComment(text='Thanks for taking the time to report this bug and helping to make Ubuntu better. Your bug report is more likely to get attention if it is made in English, since this is the language understood by the majority of Ubuntu developers. Additionally, please only mark a bug as "security" if it shows evidence of allowing attackers to cross privilege boundaries or to directly cause loss of data/privacy. Please feel free to report any other bugs you may find.', subject='') | 21 | pass |
934 | 21 | bug.comments.add(comment) | 22 | |
935 | 22 | bug.private = False | 23 | comment = Bug.NewComment(text='Thanks for taking the time to report this bug and helping to make Ubuntu better. Your bug report is more likely to get attention if it is made in English, since this is the language understood by the majority of Ubuntu developers. Additionally, please only mark a bug as "security" if it shows evidence of allowing attackers to cross privilege boundaries or to directly cause loss of data/privacy. Please feel free to report any other bugs you may find.', subject='') |
936 | 23 | bug.security = False | 24 | bug.comments.add(comment) |
937 | 24 | bug.status = 'Incomplete' | 25 | bug.private = False |
938 | 25 | 26 | bug.security = False | |
939 | 26 | try: | 27 | bug.status = 'Incomplete' |
940 | 27 | bug.subscribers.remove("ubuntu-security") | 28 | |
941 | 28 | except: | 29 | try: |
942 | 29 | pass | 30 | bug.subscribers.remove("ubuntu-security") |
943 | 30 | bug.commit(force_changes=True, ignore_lp_errors=False) | 31 | except: |
944 | 32 | pass | ||
945 | 33 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
946 | 34 | |||
947 | 35 | |||
948 | 36 | if __name__ == "__main__": | ||
949 | 37 | reassign_bugs_to_bugs_queue(*sys.argv[1:]) | ||
950 | 31 | \ No newline at end of file | 38 | \ No newline at end of file |
951 | diff --git a/p-l-p/is-cache.py b/p-l-p/is-cache.py | |||
952 | index 5aafacf..da75103 100755 | |||
953 | --- a/p-l-p/is-cache.py | |||
954 | +++ b/p-l-p/is-cache.py | |||
955 | @@ -1,29 +1,36 @@ | |||
957 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
958 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
959 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
960 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
961 | 5 | from __future__ import absolute_import, print_function | ||
962 | 5 | import sys, os | 6 | import sys, os |
963 | 6 | import launchpadbugs.connector as Connector | 7 | import launchpadbugs.connector as Connector |
964 | 7 | 8 | ||
965 | 8 | Bug = Connector.ConnectBug() | ||
966 | 9 | Bug.authentication = os.path.expanduser('~/.plb_cookies') | ||
967 | 10 | reply = '''Thanks for your report. We appreciate the difficulties you are facing, but this bug has already been reported. Please review the information and solution in bug 124373. We are marking this bug as a duplicate.''' | ||
968 | 11 | 9 | ||
972 | 12 | for num in sys.argv[1:]: | 10 | # TODO: Switch to argparse |
973 | 13 | print '%s ...' % (num) | 11 | def respond_to_duplicate_bugs(*bugs) |
974 | 14 | bug = Bug(num) | 12 | Bug = Connector.ConnectBug() |
975 | 13 | Bug.authentication = os.path.expanduser('~/.plb_cookies') | ||
976 | 14 | reply = '''Thanks for your report. We appreciate the difficulties you are facing, but this bug has already been reported. Please review the information and solution in bug 124373. We are marking this bug as a duplicate.''' | ||
977 | 15 | for bug in bugs: | ||
978 | 16 | print('%s ...' % (num)) | ||
979 | 17 | bug = Bug(num) | ||
980 | 15 | 18 | ||
983 | 16 | comment = Bug.NewComment(text=reply) | 19 | comment = Bug.NewComment(text=reply) |
984 | 17 | bug.comments.add(comment) | 20 | bug.comments.add(comment) |
985 | 18 | 21 | ||
993 | 19 | bug.status = 'Invalid' | 22 | bug.status = 'Invalid' |
994 | 20 | bug.private = False | 23 | bug.private = False |
995 | 21 | bug.security = False | 24 | bug.security = False |
996 | 22 | if not 'ubuntu-bugs' in bug.subscribers['directly']: | 25 | if not 'ubuntu-bugs' in bug.subscribers['directly']: |
997 | 23 | bug.subscribers.add("ubuntu-bugs") | 26 | bug.subscribers.add("ubuntu-bugs") |
998 | 24 | if 'ubuntu-security' in bug.subscribers['directly']: | 27 | if 'ubuntu-security' in bug.subscribers['directly']: |
999 | 25 | bug.subscribers.remove("ubuntu-security") | 28 | bug.subscribers.remove("ubuntu-security") |
1000 | 26 | 29 | ||
1002 | 27 | bug.duplicate_of = 124373 | 30 | bug.duplicate_of = 124373 |
1003 | 28 | 31 | ||
1005 | 29 | bug.commit(force_changes=True, ignore_lp_errors=False) | 32 | bug.commit(force_changes=True, ignore_lp_errors=False) |
1006 | 33 | |||
1007 | 34 | |||
1008 | 35 | if __name__ == "__main__": | ||
1009 | 36 | respond_to_duplicate_bugs(*sys.argv[1:]) | ||
1010 | 30 | \ No newline at end of file | 37 | \ No newline at end of file |
1011 | diff --git a/p-l-p/is-private.py b/p-l-p/is-private.py | |||
1012 | index d29045b..0333f51 100755 | |||
1013 | --- a/p-l-p/is-private.py | |||
1014 | +++ b/p-l-p/is-private.py | |||
1015 | @@ -1,33 +1,61 @@ | |||
1017 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1018 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1019 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1020 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1021 | 5 | # Change lp_user to self below... (3 times) | 5 | # Change lp_user to self below... (3 times) |
1023 | 6 | import sys | 6 | from __future__ import absolute_import, print_function |
1024 | 7 | import os | 7 | import os |
1025 | 8 | import sys | ||
1026 | 8 | import launchpadbugs.connector as Connector | 9 | import launchpadbugs.connector as Connector |
1027 | 9 | import configobj | ||
1028 | 10 | 10 | ||
1033 | 11 | config = configobj.ConfigObj(os.path.expanduser('~/.ubuntu-cve-tracker.conf')) | 11 | if sys.version_info[0] == 2: |
1034 | 12 | Bug = Connector.ConnectBug() | 12 | from ConfigParser import SafeConfigParser as ConfigParser |
1035 | 13 | Bug.authentication = os.path.join(config['plb_authentication']) | 13 | from cStringIO import StringIO |
1036 | 14 | lp_user = config['plb_user'] | 14 | else: |
1037 | 15 | from configparser import ConfigParser | ||
1038 | 16 | from io import StringIO | ||
1039 | 15 | 17 | ||
1043 | 16 | for num in sys.argv[1:]: | 18 | UCT_PATH = os.path.expanduser('~/.ubuntu-cve-tracker.conf') |
1041 | 17 | print '%s ... ' % (num) | ||
1042 | 18 | bug = Bug(num) | ||
1044 | 19 | 19 | ||
1045 | 20 | if not lp_user in bug.subscriptions: | ||
1046 | 21 | bug.subscribers.add(lp_user) | ||
1047 | 22 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1048 | 23 | 20 | ||
1051 | 24 | if bug.security: | 21 | def get_config(): |
1052 | 25 | bug.security = False | 22 | # replace configobj functionality to avoid the extra dependency |
1053 | 23 | config_content = StringIO() | ||
1054 | 24 | config_content.write("[dummy_section]\n") | ||
1055 | 25 | with open(UCT_PATH, "r") as fh: | ||
1056 | 26 | config_content.write(fh.read()) | ||
1057 | 27 | config_content.seek(0) | ||
1058 | 28 | parser = ConfigParser() | ||
1059 | 29 | read_file_func = getattr(parser, "read_file", getattr(parser, "readfp", None)) | ||
1060 | 30 | if read_file_func is not None: | ||
1061 | 31 | read_file_func(config_content) | ||
1062 | 32 | return {k: v for k, v in parser.items("dummy_section")} | ||
1063 | 33 | |||
1064 | 34 | |||
1065 | 35 | def make_bugs_private(*bugs): | ||
1066 | 36 | for num in bugs: | ||
1067 | 37 | config = get_config() | ||
1068 | 38 | Bug = Connector.ConnectBug() | ||
1069 | 39 | Bug.authentication = os.path.join(config['plb_authentication']) | ||
1070 | 40 | lp_user = config['plb_user'] | ||
1071 | 41 | print('%s ... ' % (num)) | ||
1072 | 42 | bug = Bug(num) | ||
1073 | 43 | |||
1074 | 44 | if not lp_user in bug.subscriptions: | ||
1075 | 45 | bug.subscribers.add(lp_user) | ||
1076 | 46 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1077 | 47 | |||
1078 | 48 | if bug.security: | ||
1079 | 49 | bug.security = False | ||
1080 | 50 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1081 | 51 | |||
1082 | 52 | bug = Bug(num) | ||
1083 | 53 | if 'ubuntu-security' in bug.subscriptions: | ||
1084 | 54 | bug.subscribers.remove("ubuntu-security") | ||
1085 | 55 | |||
1086 | 56 | bug.subscribers.remove(lp_user) | ||
1087 | 26 | bug.commit(force_changes=True, ignore_lp_errors=False) | 57 | bug.commit(force_changes=True, ignore_lp_errors=False) |
1088 | 27 | 58 | ||
1089 | 28 | bug = Bug(num) | ||
1090 | 29 | if 'ubuntu-security' in bug.subscriptions: | ||
1091 | 30 | bug.subscribers.remove("ubuntu-security") | ||
1092 | 31 | 59 | ||
1095 | 32 | bug.subscribers.remove(lp_user) | 60 | if __name__ == "__main__": |
1096 | 33 | bug.commit(force_changes=True, ignore_lp_errors=False) | 61 | make_bugs_private(*sys.argv[1:]) |
1097 | 34 | \ No newline at end of file | 62 | \ No newline at end of file |
1098 | diff --git a/p-l-p/is-support.py b/p-l-p/is-support.py | |||
1099 | index 0dd199f..e2b9eee 100755 | |||
1100 | --- a/p-l-p/is-support.py | |||
1101 | +++ b/p-l-p/is-support.py | |||
1102 | @@ -1,25 +1,31 @@ | |||
1104 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1105 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1106 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1107 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1109 | 5 | import sys | 5 | from __future__ import absolute_import, print_function |
1110 | 6 | import os | 6 | import os |
1111 | 7 | import sys | ||
1112 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1113 | 8 | 9 | ||
1116 | 9 | Bug = Connector.ConnectBug() | 10 | def close_non_bug_reports(*bugs): |
1117 | 10 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | 11 | Bug = Connector.ConnectBug() |
1118 | 12 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | ||
1119 | 13 | |||
1120 | 14 | for num in bugs: | ||
1121 | 15 | bug = Bug(num) | ||
1122 | 16 | |||
1123 | 17 | if 'ubuntu-bugs' not in bug.subscriptions: | ||
1124 | 18 | bug.subscribers.add("ubuntu-bugs") | ||
1125 | 11 | 19 | ||
1128 | 12 | for num in sys.argv[1:]: | 20 | comment = Bug.NewComment(text='Thanks for your comments. This does not appear to be a bug report and we are closing it. We appreciate the difficulties you are facing, but it would make more sense to raise your question in the support tracker. Please visit https://answers.launchpad.net/ubuntu/+addquestion', subject='') |
1129 | 13 | bug = Bug(num) | 21 | bug.comments.add(comment) |
1130 | 22 | bug.status = 'Invalid' | ||
1131 | 23 | bug.private = False | ||
1132 | 24 | bug.security = False | ||
1133 | 14 | 25 | ||
1136 | 15 | if 'ubuntu-bugs' not in bug.subscriptions: | 26 | bug.subscribers.remove("ubuntu-security") |
1137 | 16 | bug.subscribers.add("ubuntu-bugs") | 27 | bug.commit(force_changes=True, ignore_lp_errors=False) |
1138 | 17 | 28 | ||
1139 | 18 | comment = Bug.NewComment(text='Thanks for your comments. This does not appear to be a bug report and we are closing it. We appreciate the difficulties you are facing, but it would make more sense to raise your question in the support tracker. Please visit https://answers.launchpad.net/ubuntu/+addquestion', subject='') | ||
1140 | 19 | bug.comments.add(comment) | ||
1141 | 20 | bug.status = 'Invalid' | ||
1142 | 21 | bug.private = False | ||
1143 | 22 | bug.security = False | ||
1144 | 23 | 29 | ||
1147 | 24 | bug.subscribers.remove("ubuntu-security") | 30 | if __name__ == "__main__": |
1148 | 25 | bug.commit(force_changes=True, ignore_lp_errors=False) | 31 | close_non_bug_reports(*sys.argv[1:]) |
1149 | 26 | \ No newline at end of file | 32 | \ No newline at end of file |
1150 | diff --git a/p-l-p/not-a-bug.py b/p-l-p/not-a-bug.py | |||
1151 | index ad185ff..a7a30f9 100755 | |||
1152 | --- a/p-l-p/not-a-bug.py | |||
1153 | +++ b/p-l-p/not-a-bug.py | |||
1154 | @@ -1,41 +1,69 @@ | |||
1156 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1157 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1158 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1159 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1161 | 5 | import sys | 5 | from __future__ import absolute_import, print_function |
1162 | 6 | import os | 6 | import os |
1163 | 7 | import sys | ||
1164 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1165 | 8 | import configobj | ||
1166 | 9 | 9 | ||
1170 | 10 | config = configobj.ConfigObj(os.path.expanduser('~/.ubuntu-cve-tracker.conf')) | 10 | if sys.version_info[0] == 2: |
1171 | 11 | Bug = Connector.ConnectBug() | 11 | from ConfigParser import SafeConfigParser as ConfigParser |
1172 | 12 | Bug.authentication = os.path.join(config['plb_authentication']) | 12 | from cStringIO import StringIO |
1173 | 13 | else: | ||
1174 | 14 | from configparser import ConfigParser | ||
1175 | 15 | from io import StringIO | ||
1176 | 16 | |||
1177 | 17 | UCT_PATH = os.path.expanduser('~/.ubuntu-cve-tracker.conf') | ||
1178 | 18 | |||
1179 | 19 | |||
1180 | 20 | def get_config(): | ||
1181 | 21 | # Replace configobj functionality to avoid the extra dependency | ||
1182 | 22 | config_content = StringIO() | ||
1183 | 23 | config_content.write("[dummy_section]\n") | ||
1184 | 24 | with open(UCT_PATH, "r") as fh: | ||
1185 | 25 | config_content.write(fh.read()) | ||
1186 | 26 | config_content.seek(0) | ||
1187 | 27 | parser = ConfigParser() | ||
1188 | 28 | read_file_func = getattr(parser, "read_file", getattr(parser, "readfp", None)) | ||
1189 | 29 | if read_file_func is not None: | ||
1190 | 30 | read_file_func(config_content) | ||
1191 | 31 | return {k: v for k, v in parser.items("dummy_section")} | ||
1192 | 32 | |||
1193 | 33 | |||
1194 | 34 | def flag_non_bugs(*bugs): | ||
1195 | 35 | Bug = Connector.ConnectBug() | ||
1196 | 36 | Bug.authentication = os.path.join(get_config()['plb_authentication']) | ||
1197 | 37 | |||
1198 | 38 | for num in bugs: | ||
1199 | 39 | bug = Bug(num) | ||
1200 | 40 | |||
1201 | 41 | try: | ||
1202 | 42 | bug.subscribers.add("ubuntu-bugs") | ||
1203 | 43 | changed = True | ||
1204 | 44 | except: | ||
1205 | 45 | pass | ||
1206 | 13 | 46 | ||
1209 | 14 | for num in sys.argv[1:]: | 47 | comment = Bug.NewComment(text='''Thank you for using Ubuntu and taking the time to report a bug. Your report should contain, at a minimum, the following information so we can better find the source of the bug and work to resolve it. |
1208 | 15 | bug = Bug(num) | ||
1210 | 16 | 48 | ||
1216 | 17 | try: | 49 | Submitting the bug about the proper source package is essential. For help see https://wiki.ubuntu.com/Bugs/FindRightPackage . Additionally, in the report please include: |
1212 | 18 | bug.subscribers.add("ubuntu-bugs") | ||
1213 | 19 | changed = True | ||
1214 | 20 | except: | ||
1215 | 21 | pass | ||
1217 | 22 | 50 | ||
1219 | 23 | comment = Bug.NewComment(text='''Thank you for using Ubuntu and taking the time to report a bug. Your report should contain, at a minimum, the following information so we can better find the source of the bug and work to resolve it. | 51 | 1) The release of Ubuntu you are using, via 'cat /etc/lsb-release' or System -> About Ubuntu. |
1220 | 52 | 2) The version of the package you are using, via 'dpkg -l PKGNAME | cat' or by checking in Synaptic. | ||
1221 | 53 | 3) What happened and what you expected to happen. | ||
1222 | 24 | 54 | ||
1224 | 25 | Submitting the bug about the proper source package is essential. For help see https://wiki.ubuntu.com/Bugs/FindRightPackage . Additionally, in the report please include: | 55 | The Ubuntu community has also created debugging procedures for a wide variety of packages at https://wiki.ubuntu.com/DebuggingProcedures . Following the debugging instructions for the affected package will make your bug report much more complete. Thanks!''', subject='') |
1225 | 56 | bug.comments.add(comment) | ||
1226 | 57 | bug.status = 'Invalid' | ||
1227 | 58 | bug.private = False | ||
1228 | 59 | bug.security = False | ||
1229 | 26 | 60 | ||
1233 | 27 | 1) The release of Ubuntu you are using, via 'cat /etc/lsb-release' or System -> About Ubuntu. | 61 | try: |
1234 | 28 | 2) The version of the package you are using, via 'dpkg -l PKGNAME | cat' or by checking in Synaptic. | 62 | bug.subscribers.remove("ubuntu-security") |
1235 | 29 | 3) What happened and what you expected to happen. | 63 | except: |
1236 | 64 | pass | ||
1237 | 65 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1238 | 30 | 66 | ||
1239 | 31 | The Ubuntu community has also created debugging procedures for a wide variety of packages at https://wiki.ubuntu.com/DebuggingProcedures . Following the debugging instructions for the affected package will make your bug report much more complete. Thanks!''', subject='') | ||
1240 | 32 | bug.comments.add(comment) | ||
1241 | 33 | bug.status = 'Invalid' | ||
1242 | 34 | bug.private = False | ||
1243 | 35 | bug.security = False | ||
1244 | 36 | 67 | ||
1250 | 37 | try: | 68 | if __name__ == "__main__": |
1251 | 38 | bug.subscribers.remove("ubuntu-security") | 69 | flag_non_bugs(*sys.argv[1:]) |
1247 | 39 | except: | ||
1248 | 40 | pass | ||
1249 | 41 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1252 | 42 | \ No newline at end of file | 70 | \ No newline at end of file |
1253 | diff --git a/p-l-p/not-private.py b/p-l-p/not-private.py | |||
1254 | index 289052f..4abc231 100755 | |||
1255 | --- a/p-l-p/not-private.py | |||
1256 | +++ b/p-l-p/not-private.py | |||
1257 | @@ -1,13 +1,14 @@ | |||
1259 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1260 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1261 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1262 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1263 | 5 | from __future__ import absolute_import, print_function | ||
1264 | 5 | import sys | 6 | import sys |
1265 | 6 | import os | 7 | import os |
1266 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1267 | 8 | 9 | ||
1270 | 9 | print "This script is obsoleted by launchpadlib/not-private. Please use it instead." | 10 | print("This script is obsoleted by launchpadlib/not-private. Please use it instead.") |
1271 | 10 | print "Continuing..." | 11 | print("Continuing...") |
1272 | 11 | 12 | ||
1273 | 12 | Bug = Connector.ConnectBug() | 13 | Bug = Connector.ConnectBug() |
1274 | 13 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | 14 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') |
1275 | diff --git a/p-l-p/not-security-in-dups.py b/p-l-p/not-security-in-dups.py | |||
1276 | index 4046c74..e9a1ced 100755 | |||
1277 | --- a/p-l-p/not-security-in-dups.py | |||
1278 | +++ b/p-l-p/not-security-in-dups.py | |||
1279 | @@ -1,7 +1,8 @@ | |||
1281 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1282 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1283 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1284 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1285 | 5 | from __future__ import absolute_import, print_function | ||
1286 | 5 | import sys | 6 | import sys |
1287 | 6 | import os | 7 | import os |
1288 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1289 | @@ -10,7 +11,7 @@ Bug = Connector.ConnectBug() | |||
1290 | 10 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') | 11 | Bug.authentication = os.path.join(os.environ['HOME'], '.cookies.sqlite') |
1291 | 11 | 12 | ||
1292 | 12 | def not_security(num): | 13 | def not_security(num): |
1294 | 13 | print '%s ...' % (num), | 14 | print('%s ...' % (num), end=' ') |
1295 | 14 | bug = Bug(num) | 15 | bug = Bug(num) |
1296 | 15 | 16 | ||
1297 | 16 | changed = False | 17 | changed = False |
1298 | @@ -28,13 +29,15 @@ def not_security(num): | |||
1299 | 28 | changed = True | 29 | changed = True |
1300 | 29 | if changed: | 30 | if changed: |
1301 | 30 | bug.commit(force_changes=True, ignore_lp_errors=False) | 31 | bug.commit(force_changes=True, ignore_lp_errors=False) |
1303 | 31 | print 'updated' | 32 | print('updated') |
1304 | 32 | else: | 33 | else: |
1306 | 33 | print 'skipped' | 34 | print('skipped') |
1307 | 34 | return bug | 35 | return bug |
1308 | 35 | 36 | ||
1309 | 36 | for num in sys.argv[1:]: | ||
1310 | 37 | bug = not_security(num) | ||
1311 | 38 | 37 | ||
1314 | 39 | for num in bug.duplicates: | 38 | if __name__ == "__main__": |
1315 | 40 | not_security(num) | 39 | for num in sys.argv[1:]: |
1316 | 40 | bug = not_security(num) | ||
1317 | 41 | |||
1318 | 42 | for num in bug.duplicates: | ||
1319 | 43 | not_security(num) | ||
1320 | diff --git a/p-l-p/not-security-without-comment.py b/p-l-p/not-security-without-comment.py | |||
1321 | index e890308..3dad01b 100755 | |||
1322 | --- a/p-l-p/not-security-without-comment.py | |||
1323 | +++ b/p-l-p/not-security-without-comment.py | |||
1324 | @@ -1,29 +1,57 @@ | |||
1326 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1327 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1328 | 3 | # License: GPLv3 | 3 | # License: GPLv3 |
1330 | 4 | import sys | 4 | from __future__ import absolute_import, print_function |
1331 | 5 | import os | 5 | import os |
1332 | 6 | import sys | ||
1333 | 6 | import launchpadbugs.connector as Connector | 7 | import launchpadbugs.connector as Connector |
1334 | 7 | import configobj | ||
1335 | 8 | 8 | ||
1339 | 9 | config = configobj.ConfigObj(os.path.expanduser('~/.ubuntu-cve-tracker.conf')) | 9 | if sys.version_info[0] == 2: |
1340 | 10 | Bug = Connector.ConnectBug() | 10 | from ConfigParser import SafeConfigParser as ConfigParser |
1341 | 11 | Bug.authentication = os.path.join(config['plb_authentication']) | 11 | from cStringIO import StringIO |
1342 | 12 | else: | ||
1343 | 13 | from configparser import ConfigParser | ||
1344 | 14 | from io import StringIO | ||
1345 | 15 | |||
1346 | 16 | UCT_PATH = os.path.expanduser('~/.ubuntu-cve-tracker.conf') | ||
1347 | 17 | |||
1348 | 18 | |||
1349 | 19 | def get_config(): | ||
1350 | 20 | config_content = StringIO() | ||
1351 | 21 | config_content.write("[dummy_section]\n") | ||
1352 | 22 | with open(UCT_PATH, "r") as fh: | ||
1353 | 23 | config_content.write(fh.read()) | ||
1354 | 24 | config_content.seek(0) | ||
1355 | 25 | parser = ConfigParser() | ||
1356 | 26 | read_file_func = getattr(parser, "read_file", getattr(parser, "readfp", None)) | ||
1357 | 27 | if read_file_func is not None: | ||
1358 | 28 | read_file_func(config_content) | ||
1359 | 29 | return {k: v for k, v in parser.items("dummy_section")} | ||
1360 | 30 | |||
1361 | 31 | |||
1362 | 32 | def remove_security_without_comment(*bugs): | ||
1363 | 33 | Bug = Connector.ConnectBug() | ||
1364 | 34 | config = get_config() | ||
1365 | 35 | Bug.authentication = os.path.join(config['plb_authentication']) | ||
1366 | 36 | |||
1367 | 37 | for num in bugs: | ||
1368 | 38 | print('%s ...' % (num)) | ||
1369 | 39 | bug = Bug(num) | ||
1370 | 40 | |||
1371 | 41 | bug.private = False | ||
1372 | 42 | bug.security = False | ||
1373 | 12 | 43 | ||
1377 | 13 | for num in sys.argv[1:]: | 44 | try: |
1378 | 14 | print '%s ...' % (num) | 45 | bug.subscribers.add("ubuntu-bugs") |
1379 | 15 | bug = Bug(num) | 46 | except: |
1380 | 47 | print("ubuntu-bugs already subscribed", file=sys.stderr) | ||
1381 | 16 | 48 | ||
1384 | 17 | bug.private = False | 49 | try: |
1385 | 18 | bug.security = False | 50 | bug.subscribers.remove("ubuntu-security") |
1386 | 51 | except: | ||
1387 | 52 | pass | ||
1388 | 53 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1389 | 19 | 54 | ||
1390 | 20 | try: | ||
1391 | 21 | bug.subscribers.add("ubuntu-bugs") | ||
1392 | 22 | except: | ||
1393 | 23 | print >>sys.stderr, "ubuntu-bugs already subscribed" | ||
1394 | 24 | 55 | ||
1400 | 25 | try: | 56 | if __name__ == "__main__": |
1401 | 26 | bug.subscribers.remove("ubuntu-security") | 57 | remove_security_without_comment(*sys.argv[1:]) |
1397 | 27 | except: | ||
1398 | 28 | pass | ||
1399 | 29 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1402 | 30 | \ No newline at end of file | 58 | \ No newline at end of file |
1403 | diff --git a/p-l-p/not-security.py b/p-l-p/not-security.py | |||
1404 | index 4108e82..c909518 100755 | |||
1405 | --- a/p-l-p/not-security.py | |||
1406 | +++ b/p-l-p/not-security.py | |||
1407 | @@ -1,31 +1,60 @@ | |||
1409 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1410 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1411 | 3 | # License: GPLv3 | 3 | # License: GPLv3 |
1412 | 4 | from __future__ import absolute_import, print_function | ||
1413 | 4 | import sys | 5 | import sys |
1414 | 5 | import os | 6 | import os |
1415 | 6 | import launchpadbugs.connector as Connector | 7 | import launchpadbugs.connector as Connector |
1416 | 7 | import configobj | ||
1417 | 8 | 8 | ||
1421 | 9 | config = configobj.ConfigObj(os.path.expanduser('~/.ubuntu-cve-tracker.conf')) | 9 | if sys.version_info[0] == 2: |
1422 | 10 | Bug = Connector.ConnectBug() | 10 | from ConfigParser import SafeConfigParser as ConfigParser |
1423 | 11 | Bug.authentication = os.path.join(config['plb_authentication']) | 11 | from cStringIO import StringIO |
1424 | 12 | else: | ||
1425 | 13 | from configparser import ConfigParser | ||
1426 | 14 | from io import StringIO | ||
1427 | 12 | 15 | ||
1430 | 13 | for num in sys.argv[1:]: | 16 | UCT_PATH = os.path.expanduser('~/.ubuntu-cve-tracker.conf') |
1429 | 14 | bug = Bug(num) | ||
1431 | 15 | 17 | ||
1432 | 16 | comment = Bug.NewComment(text='Thanks for taking the time to report this bug and helping to make Ubuntu better. We appreciate the difficulties you are facing, but this appears to be a "regular" (non-security) bug. I have unmarked it as a security issue since this bug does not show evidence of allowing attackers to cross privilege boundaries nor directly cause loss of data/privacy. Please feel free to report any other bugs you may find.', subject='') | ||
1433 | 17 | bug.comments.add(comment) | ||
1434 | 18 | bug.private = False | ||
1435 | 19 | bug.security = False | ||
1436 | 20 | 18 | ||
1441 | 21 | try: | 19 | def get_config(): |
1442 | 22 | bug.subscribers.add("ubuntu-bugs") | 20 | # replace configobj functionality to avoid extra dependency |
1443 | 23 | except: | 21 | config_content = StringIO() |
1444 | 24 | pass | 22 | config_content.write("[dummy_section]\n") |
1445 | 23 | with open(UCT_PATH, "r") as fh: | ||
1446 | 24 | config_content.write(fh.read()) | ||
1447 | 25 | config_content.seek(0) | ||
1448 | 26 | parser = ConfigParser() | ||
1449 | 27 | read_file_func = getattr(parser, "read_file", getattr(parser, "readfp", None)) | ||
1450 | 28 | if read_file_func is not None: | ||
1451 | 29 | read_file_func(config_content) | ||
1452 | 30 | return {k: v for k, v in parser.items("dummy_section")} | ||
1453 | 25 | 31 | ||
1454 | 26 | try: | ||
1455 | 27 | bug.subscribtions.remove("ubuntu-security") | ||
1456 | 28 | except: | ||
1457 | 29 | pass | ||
1458 | 30 | 32 | ||
1460 | 31 | bug.commit(force_changes=True, ignore_lp_errors=False) | 33 | def remove_security(*bugs): |
1461 | 34 | Bug = Connector.ConnectBug() | ||
1462 | 35 | config = get_config() | ||
1463 | 36 | Bug.authentication = os.path.join(config['plb_authentication']) | ||
1464 | 37 | |||
1465 | 38 | for num in bugs: | ||
1466 | 39 | bug = Bug(num) | ||
1467 | 40 | |||
1468 | 41 | comment = Bug.NewComment(text='Thanks for taking the time to report this bug and helping to make Ubuntu better. We appreciate the difficulties you are facing, but this appears to be a "regular" (non-security) bug. I have unmarked it as a security issue since this bug does not show evidence of allowing attackers to cross privilege boundaries nor directly cause loss of data/privacy. Please feel free to report any other bugs you may find.', subject='') | ||
1469 | 42 | bug.comments.add(comment) | ||
1470 | 43 | bug.private = False | ||
1471 | 44 | bug.security = False | ||
1472 | 45 | |||
1473 | 46 | try: | ||
1474 | 47 | bug.subscribers.add("ubuntu-bugs") | ||
1475 | 48 | except: | ||
1476 | 49 | pass | ||
1477 | 50 | |||
1478 | 51 | try: | ||
1479 | 52 | bug.subscribtions.remove("ubuntu-security") | ||
1480 | 53 | except: | ||
1481 | 54 | pass | ||
1482 | 55 | |||
1483 | 56 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1484 | 57 | |||
1485 | 58 | |||
1486 | 59 | if __name__ == "__main__": | ||
1487 | 60 | remove_security(*sys.argv[1:]) | ||
1488 | 32 | \ No newline at end of file | 61 | \ No newline at end of file |
1489 | diff --git a/p-l-p/reassign.py b/p-l-p/reassign.py | |||
1490 | index d2d18f3..6690cec 100755 | |||
1491 | --- a/p-l-p/reassign.py | |||
1492 | +++ b/p-l-p/reassign.py | |||
1493 | @@ -1,7 +1,8 @@ | |||
1495 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1496 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1497 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1498 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1499 | 5 | from __future__ import absolute_import, print_function | ||
1500 | 5 | import sys | 6 | import sys |
1501 | 6 | import os, os | 7 | import os, os |
1502 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1503 | @@ -22,26 +23,27 @@ if assignee == 'None': | |||
1504 | 22 | assignee = None | 23 | assignee = None |
1505 | 23 | 24 | ||
1506 | 24 | for num in sys.argv[5:]: | 25 | for num in sys.argv[5:]: |
1508 | 25 | bug = Bug(num) | 26 | bug = Bug(num) |
1509 | 26 | 27 | ||
1529 | 27 | for info in bug.get_infotable(): | 28 | for info in bug.get_infotable(): |
1530 | 28 | if info.target and info.target.lower() != 'ubuntu': | 29 | if info.target and info.target.lower() != 'ubuntu': |
1531 | 29 | print 'skipping target "%s"' % (info.target) | 30 | print('skipping target "%s"' % (info.target)) |
1532 | 30 | continue | 31 | continue |
1533 | 31 | if info.targeted_to == 'Intrepid' or info.targeted_to == None or info.status == 'Fix Released' or info.status == 'Incomplete' or info.status == 'Invalid': | 32 | if info.targeted_to == 'Intrepid' or info.targeted_to == None or info.status == 'Fix Released' or info.status == 'Incomplete' or info.status == 'Invalid': |
1534 | 32 | print 'skipping (targeted_to:%s status:%s)' % (info.targeted_to,info.status) | 33 | print('skipping (targeted_to:%s status:%s)' % (info.targeted_to,info.status)) |
1535 | 33 | continue | 34 | continue |
1536 | 34 | if info.affects == pkg: | 35 | if info.affects == pkg: |
1537 | 35 | if status != "-" and info.status != status: | 36 | if status != "-" and info.status != status: |
1538 | 36 | print '%s: status => %s' % (info.targeted_to,status) | 37 | print('%s: status => %s' % (info.targeted_to,status)) |
1539 | 37 | info.status = status | 38 | info.status = status |
1540 | 38 | if importance != "-" and info.importance != importance: | 39 | if importance != "-" and info.importance != importance: |
1541 | 39 | print '%s: status => %s' % (info.targeted_to,importance) | 40 | print('%s: status => %s' % (info.targeted_to,importance)) |
1542 | 40 | info.importance = importance | 41 | info.importance = importance |
1543 | 41 | if assignee != "-" and info.assignee != assignee: | 42 | if assignee != "-" and info.assignee != assignee: |
1544 | 42 | print '%s: assignee => %s' % (info.targeted_to,assignee) | 43 | print('%s: assignee => %s' % (info.targeted_to,assignee)) |
1545 | 43 | info.assignee = assignee | 44 | info.assignee = assignee |
1546 | 44 | else: | 45 | else: |
1547 | 45 | print 'skipping affects "%s"' % (info.affects) | 46 | print('skipping affects "%s"' % (info.affects)) |
1548 | 47 | |||
1549 | 48 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1550 | 46 | 49 | ||
1551 | 47 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1552 | diff --git a/p-l-p/requires-trojaned-account.py b/p-l-p/requires-trojaned-account.py | |||
1553 | index 3619b04..0970eee 100755 | |||
1554 | --- a/p-l-p/requires-trojaned-account.py | |||
1555 | +++ b/p-l-p/requires-trojaned-account.py | |||
1556 | @@ -1,7 +1,8 @@ | |||
1558 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1559 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1560 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1561 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1562 | 5 | from __future__ import absolute_import, print_function | ||
1563 | 5 | import sys, os | 6 | import sys, os |
1564 | 6 | import launchpadbugs.connector as Connector | 7 | import launchpadbugs.connector as Connector |
1565 | 7 | 8 | ||
1566 | diff --git a/p-l-p/set-package.py b/p-l-p/set-package.py | |||
1567 | index def815c..1a62e14 100755 | |||
1568 | --- a/p-l-p/set-package.py | |||
1569 | +++ b/p-l-p/set-package.py | |||
1570 | @@ -1,4 +1,5 @@ | |||
1572 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1573 | 2 | from __future__ import absolute_import, print_function | ||
1574 | 2 | import sys, os | 3 | import sys, os |
1575 | 3 | import launchpadbugs.connector as Connector | 4 | import launchpadbugs.connector as Connector |
1576 | 4 | 5 | ||
1577 | @@ -6,7 +7,7 @@ Bug = Connector.ConnectBug() | |||
1578 | 6 | Bug.authentication = os.path.expanduser('~/.plb_cookies') | 7 | Bug.authentication = os.path.expanduser('~/.plb_cookies') |
1579 | 7 | 8 | ||
1580 | 8 | if len(sys.argv) < 2: | 9 | if len(sys.argv) < 2: |
1582 | 9 | print 'Usage: set-package.py PKG bug [bug ...]' | 10 | print('Usage: set-package.py PKG bug [bug ...]') |
1583 | 10 | sys.exit(1) | 11 | sys.exit(1) |
1584 | 11 | 12 | ||
1585 | 12 | pkg = sys.argv[1] | 13 | pkg = sys.argv[1] |
1586 | diff --git a/p-l-p/sub-security.py b/p-l-p/sub-security.py | |||
1587 | index decca39..5259438 100755 | |||
1588 | --- a/p-l-p/sub-security.py | |||
1589 | +++ b/p-l-p/sub-security.py | |||
1590 | @@ -1,26 +1,33 @@ | |||
1592 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1593 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1594 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1595 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1596 | 5 | # Change 'keescook' to self below... (3 times) | 5 | # Change 'keescook' to self below... (3 times) |
1597 | 6 | from __future__ import absolute_import, print_function | ||
1598 | 6 | import sys, os | 7 | import sys, os |
1599 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1600 | 8 | 9 | ||
1601 | 9 | Bug = Connector.ConnectBug() | 10 | Bug = Connector.ConnectBug() |
1602 | 10 | Bug.authentication = os.path.expanduser('~/.plb_cookies') | 11 | Bug.authentication = os.path.expanduser('~/.plb_cookies') |
1603 | 11 | 12 | ||
1604 | 12 | for num in sys.argv[1:]: | ||
1605 | 13 | print '%s ... ' % (num) | ||
1606 | 14 | try: | ||
1607 | 15 | bug = Bug(num) | ||
1608 | 16 | except: | ||
1609 | 17 | print 'private' | ||
1610 | 18 | continue | ||
1611 | 19 | 13 | ||
1614 | 20 | if not bug.security: | 14 | def subscribe_ubuntu_security(*bugs) |
1615 | 21 | continue | 15 | for num in bugs: |
1616 | 16 | print('%s ... ' % (num)) | ||
1617 | 17 | try: | ||
1618 | 18 | bug = Bug(num) | ||
1619 | 19 | except: | ||
1620 | 20 | print('private') | ||
1621 | 21 | continue | ||
1622 | 22 | 22 | ||
1625 | 23 | if not 'ubuntu-security' in bug.subscriptions['directly']: | 23 | if not bug.security: |
1626 | 24 | bug.subscribers.add("ubuntu-security") | 24 | continue |
1627 | 25 | 25 | ||
1629 | 26 | bug.commit(force_changes=True, ignore_lp_errors=False) | 26 | if not 'ubuntu-security' in bug.subscriptions['directly']: |
1630 | 27 | bug.subscribers.add("ubuntu-security") | ||
1631 | 28 | |||
1632 | 29 | bug.commit(force_changes=True, ignore_lp_errors=False) | ||
1633 | 30 | |||
1634 | 31 | |||
1635 | 32 | if __name__ == "__main__": | ||
1636 | 33 | subscribe_ubuntu_security(*sys.argv[1:]) | ||
1637 | 27 | \ No newline at end of file | 34 | \ No newline at end of file |
1638 | diff --git a/p-l-p/tag.py b/p-l-p/tag.py | |||
1639 | index 466e46b..2a59136 100755 | |||
1640 | --- a/p-l-p/tag.py | |||
1641 | +++ b/p-l-p/tag.py | |||
1642 | @@ -2,6 +2,7 @@ | |||
1643 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1644 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1645 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1646 | 5 | from __future__ import absolute_import, print_function | ||
1647 | 5 | import sys, os | 6 | import sys, os |
1648 | 6 | import launchpadbugs.connector as Connector | 7 | import launchpadbugs.connector as Connector |
1649 | 7 | 8 | ||
1650 | @@ -9,14 +10,14 @@ Bug = Connector.ConnectBug() | |||
1651 | 9 | Bug.authentication = os.path.expanduser('~/.plb_cookies') | 10 | Bug.authentication = os.path.expanduser('~/.plb_cookies') |
1652 | 10 | 11 | ||
1653 | 11 | if len(sys.argv) < 3: | 12 | if len(sys.argv) < 3: |
1655 | 12 | print 'Usage: tag.py [+|-]TAG bug [bug ...]' | 13 | print('Usage: tag.py [+|-]TAG bug [bug ...]') |
1656 | 13 | sys.exit(1) | 14 | sys.exit(1) |
1657 | 14 | 15 | ||
1658 | 15 | tag = sys.argv[1] | 16 | tag = sys.argv[1] |
1659 | 16 | state = tag[0] | 17 | state = tag[0] |
1660 | 17 | tag = tag[1:] | 18 | tag = tag[1:] |
1661 | 18 | if state not in ['-','+']: | 19 | if state not in ['-','+']: |
1663 | 19 | print 'Tag must start with - or +' | 20 | print('Tag must start with - or +') |
1664 | 20 | sys.exit(1) | 21 | sys.exit(1) |
1665 | 21 | 22 | ||
1666 | 22 | for num in sys.argv[2:]: | 23 | for num in sys.argv[2:]: |
1667 | diff --git a/p-l-p/unsub-in-dups.py b/p-l-p/unsub-in-dups.py | |||
1668 | index 24a2d97..cc6eb4c 100755 | |||
1669 | --- a/p-l-p/unsub-in-dups.py | |||
1670 | +++ b/p-l-p/unsub-in-dups.py | |||
1671 | @@ -1,8 +1,9 @@ | |||
1673 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
1674 | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> | 2 | # Copyright (C) 2007 Canonical, Ltd. Kees Cook <kees@ubuntu.com> |
1675 | 3 | # License: GPLv2 | 3 | # License: GPLv2 |
1676 | 4 | # Change the cookie path below... | 4 | # Change the cookie path below... |
1677 | 5 | # Change 'keescook' below... (twice) | 5 | # Change 'keescook' below... (twice) |
1678 | 6 | from __future__ import absolute_import, print_function | ||
1679 | 6 | import sys, os | 7 | import sys, os |
1680 | 7 | import launchpadbugs.connector as Connector | 8 | import launchpadbugs.connector as Connector |
1681 | 8 | 9 | ||
1682 | @@ -12,7 +13,7 @@ Bug = Connector.ConnectBug() | |||
1683 | 12 | Bug.authentication = os.path.expanduser('~/.plb_cookies') | 13 | Bug.authentication = os.path.expanduser('~/.plb_cookies') |
1684 | 13 | 14 | ||
1685 | 14 | def not_security(num): | 15 | def not_security(num): |
1687 | 15 | print '%s ...' % (num), | 16 | print('%s ...' % (num), end=' ') |
1688 | 16 | bug = Bug(num) | 17 | bug = Bug(num) |
1689 | 17 | 18 | ||
1690 | 18 | changed = False | 19 | changed = False |
1691 | @@ -22,9 +23,9 @@ def not_security(num): | |||
1692 | 22 | 23 | ||
1693 | 23 | if changed: | 24 | if changed: |
1694 | 24 | bug.commit(force_changes=True, ignore_lp_errors=False) | 25 | bug.commit(force_changes=True, ignore_lp_errors=False) |
1696 | 25 | print 'updated' | 26 | print('updated') |
1697 | 26 | else: | 27 | else: |
1699 | 27 | print 'skipped' | 28 | print('skipped') |
1700 | 28 | return bug | 29 | return bug |
1701 | 29 | 30 | ||
1702 | 30 | for num in sys.argv[2:]: | 31 | for num in sys.argv[2:]: |
1703 | diff --git a/package-tools/debcompare b/package-tools/debcompare | |||
1704 | index 5a3eac7..21e5538 100755 | |||
1705 | --- a/package-tools/debcompare | |||
1706 | +++ b/package-tools/debcompare | |||
1707 | @@ -1,4 +1,4 @@ | |||
1709 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
1710 | 2 | 2 | ||
1711 | 3 | # Name: debcompare | 3 | # Name: debcompare |
1712 | 4 | # Description: Compares different versions of binary packages | 4 | # Description: Compares different versions of binary packages |
1713 | @@ -16,7 +16,7 @@ | |||
1714 | 16 | # | 16 | # |
1715 | 17 | # License: GPLv3 | 17 | # License: GPLv3 |
1716 | 18 | # | 18 | # |
1718 | 19 | from __future__ import print_function | 19 | from __future__ import absolute_import, print_function |
1719 | 20 | 20 | ||
1720 | 21 | import difflib | 21 | import difflib |
1721 | 22 | import os | 22 | import os |
1722 | @@ -82,10 +82,9 @@ class DebFile: | |||
1723 | 82 | '''Gets the symbols of the file specified''' | 82 | '''Gets the symbols of the file specified''' |
1724 | 83 | 83 | ||
1725 | 84 | symbols = [] | 84 | symbols = [] |
1727 | 85 | report = subprocess.check_output(["nm", "-DC", filename]) | 85 | report = subprocess.check_output(["nm", "-DC", filename], universal_newlines=True) |
1728 | 86 | 86 | ||
1729 | 87 | for line in report.splitlines(): | 87 | for line in report.splitlines(): |
1730 | 88 | line = line.decode() | ||
1731 | 89 | if line[0] == ' ': | 88 | if line[0] == ' ': |
1732 | 90 | # no address prefix, just take everything | 89 | # no address prefix, just take everything |
1733 | 91 | symbol_entry = line.strip().split(maxsplit=2)[0:] | 90 | symbol_entry = line.strip().split(maxsplit=2)[0:] |
1734 | @@ -652,29 +651,35 @@ def compare_debs(old_deb, new_deb): | |||
1735 | 652 | new_deb.jarfiles, new_deb.files_dir) | 651 | new_deb.jarfiles, new_deb.files_dir) |
1736 | 653 | 652 | ||
1737 | 654 | 653 | ||
1741 | 655 | if len(sys.argv) < 3: | 654 | if __name__ == "__main__": |
1742 | 656 | print_usage() | 655 | # * Code that is unguarded by this check will run if the file is ever |
1743 | 657 | sys.exit(1) | 656 | # * used in an import statement, even if we only plan to use or import |
1744 | 657 | # * one function from this file. Guarding code behind this check means | ||
1745 | 658 | # * it only runs when the file is invoked directly (i.e. ./myfile.py) | ||
1746 | 659 | # * or via the interpreter, i.e. python myfile.py | ||
1747 | 660 | if len(sys.argv) < 3: | ||
1748 | 661 | print_usage() | ||
1749 | 662 | sys.exit(1) | ||
1750 | 658 | 663 | ||
1753 | 659 | oldfile = os.path.abspath(sys.argv[1]) | 664 | oldfile = os.path.abspath(sys.argv[1]) |
1754 | 660 | newfile = os.path.abspath(sys.argv[2]) | 665 | newfile = os.path.abspath(sys.argv[2]) |
1755 | 661 | 666 | ||
1759 | 662 | if not os.path.isfile(oldfile) or not os.path.isfile(newfile): | 667 | if not os.path.isfile(oldfile) or not os.path.isfile(newfile): |
1760 | 663 | print_usage() | 668 | print_usage() |
1761 | 664 | sys.exit(1) | 669 | sys.exit(1) |
1762 | 665 | 670 | ||
1764 | 666 | check_required_tools() | 671 | check_required_tools() |
1765 | 667 | 672 | ||
1768 | 668 | old_deb = DebFile(oldfile) | 673 | old_deb = DebFile(oldfile) |
1769 | 669 | new_deb = DebFile(newfile) | 674 | new_deb = DebFile(newfile) |
1770 | 670 | 675 | ||
1772 | 671 | compare_debs(old_deb, new_deb) | 676 | compare_debs(old_deb, new_deb) |
1773 | 672 | 677 | ||
1779 | 673 | # Clean up temp dirs | 678 | # Clean up temp dirs |
1780 | 674 | if old_deb.temp_dir and os.path.exists(old_deb.temp_dir): | 679 | if old_deb.temp_dir and os.path.exists(old_deb.temp_dir): |
1781 | 675 | shutil.rmtree(old_deb.temp_dir, ignore_errors=True) | 680 | shutil.rmtree(old_deb.temp_dir, ignore_errors=True) |
1782 | 676 | if new_deb.temp_dir and os.path.exists(new_deb.temp_dir): | 681 | if new_deb.temp_dir and os.path.exists(new_deb.temp_dir): |
1783 | 677 | shutil.rmtree(new_deb.temp_dir, ignore_errors=True) | 682 | shutil.rmtree(new_deb.temp_dir, ignore_errors=True) |
1784 | 678 | 683 | ||
1787 | 679 | print("\n\n--------------") | 684 | print("\n\n--------------") |
1788 | 680 | print("End of report.") | 685 | print("End of report.") |
1789 | diff --git a/repo-tools/count-hardened-pkgs b/repo-tools/count-hardened-pkgs | |||
1790 | index 60d860a..f5b75cf 100755 | |||
1791 | --- a/repo-tools/count-hardened-pkgs | |||
1792 | +++ b/repo-tools/count-hardened-pkgs | |||
1793 | @@ -1,9 +1,13 @@ | |||
1795 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
1796 | 2 | # 2012, Kees Cook <kees@debian.org> | 2 | # 2012, Kees Cook <kees@debian.org> |
1797 | 3 | 3 | ||
1798 | 4 | from __future__ import absolute_import, print_function | ||
1799 | 4 | import time, tempfile, shutil, sys, os, stat, glob | 5 | import time, tempfile, shutil, sys, os, stat, glob |
1802 | 5 | import cPickle as pickle | 6 | import subprocess |
1803 | 6 | from subprocess import * | 7 | if sys.version_info[0] == 2: |
1804 | 8 | import cPickle as pickle | ||
1805 | 9 | else: | ||
1806 | 10 | import pickle | ||
1807 | 7 | 11 | ||
1808 | 8 | count_names = ['elf', 'fortify', 'stackprotector', 'relro', 'bindnow', 'pie'] | 12 | count_names = ['elf', 'fortify', 'stackprotector', 'relro', 'bindnow', 'pie'] |
1809 | 9 | run_time = time.strftime("%Y%m%d") | 13 | run_time = time.strftime("%Y%m%d") |
1810 | @@ -23,26 +27,26 @@ class Archive(): | |||
1811 | 23 | else: | 27 | else: |
1812 | 24 | components = [component] | 28 | components = [component] |
1813 | 25 | 29 | ||
1815 | 26 | print "Loading %s ..." % (release) | 30 | print("Loading %s ..." % (release)) |
1816 | 27 | for component in components: | 31 | for component in components: |
1818 | 28 | print "\t%s ..." % (component) | 32 | print("\t%s ..." % (component)) |
1819 | 29 | packages = os.path.join(base, 'dists', release, component, | 33 | packages = os.path.join(base, 'dists', release, component, |
1820 | 30 | 'binary-%s' % (arch), 'Packages') | 34 | 'binary-%s' % (arch), 'Packages') |
1821 | 31 | packages_xz = packages + ".xz" | 35 | packages_xz = packages + ".xz" |
1822 | 32 | packages_bz2 = packages + ".bz2" | 36 | packages_bz2 = packages + ".bz2" |
1823 | 33 | packages_gz = packages + ".gz" | 37 | packages_gz = packages + ".gz" |
1824 | 34 | if os.path.exists(packages): | 38 | if os.path.exists(packages): |
1826 | 35 | cat = Popen(["cat", packages], stdout=PIPE) | 39 | cat = subprocess.Popen(["cat", packages], stdout=subprocess.PIPE) |
1827 | 36 | elif os.path.exists(packages_xz): | 40 | elif os.path.exists(packages_xz): |
1829 | 37 | cat = Popen(["xzcat", packages_xz], stdout=PIPE) | 41 | cat = subprocess.Popen(["xzcat", packages_xz], stdout=subprocess.PIPE) |
1830 | 38 | elif os.path.exists(packages_bz2): | 42 | elif os.path.exists(packages_bz2): |
1832 | 39 | cat = Popen(["bzcat", packages_bz2], stdout=PIPE) | 43 | cat = subprocess.Popen(["bzcat", packages_bz2], stdout=subprocess.PIPE) |
1833 | 40 | elif os.path.exists(packages_gz): | 44 | elif os.path.exists(packages_gz): |
1835 | 41 | cat = Popen(["zcat", packages_gz], stdout=PIPE) | 45 | cat = subprocess.Popen(["zcat", packages_gz], stdout=subprocess.PIPE) |
1836 | 42 | else: | 46 | else: |
1840 | 43 | raise ValueError, "Missing %s*" % (packages) | 47 | raise ValueError("Missing %s*" % (packages)) |
1841 | 44 | p = Popen(["grep-dctrl", "-s", "Package,Source,Filename", "."], | 48 | p = subprocess.Popen(["grep-dctrl", "-s", "Package,Source,Filename", "."], |
1842 | 45 | stdin=cat.stdout, stdout=PIPE) | 49 | stdin=cat.stdout, stdout=subprocess.PIPE) |
1843 | 46 | 50 | ||
1844 | 47 | pkg = "" | 51 | pkg = "" |
1845 | 48 | src = "" | 52 | src = "" |
1846 | @@ -62,7 +66,7 @@ class Archive(): | |||
1847 | 62 | self.srcs[src].setdefault(pkg, line.split(' ')[1]) | 66 | self.srcs[src].setdefault(pkg, line.split(' ')[1]) |
1848 | 63 | cat.wait() | 67 | cat.wait() |
1849 | 64 | if cat.returncode != 0: | 68 | if cat.returncode != 0: |
1851 | 65 | raise ValueError, "cat %s: %d" % (packges, cat.returncode) | 69 | raise ValueError("cat %s: %d" % (packges, cat.returncode)) |
1852 | 66 | 70 | ||
1853 | 67 | def sources(self): | 71 | def sources(self): |
1854 | 68 | return sorted(self.srcs) | 72 | return sorted(self.srcs) |
1855 | @@ -77,7 +81,7 @@ class HardeningReporter(): | |||
1856 | 77 | def __init__(self, cachedir): | 81 | def __init__(self, cachedir): |
1857 | 78 | # Load version cache. | 82 | # Load version cache. |
1858 | 79 | self.pickle = os.path.join(cachedir, 'cache.pickle') | 83 | self.pickle = os.path.join(cachedir, 'cache.pickle') |
1860 | 80 | print "Loading package cache ..." | 84 | print("Loading package cache ...") |
1861 | 81 | try: | 85 | try: |
1862 | 82 | self.seen = pickle.load(open(self.pickle, "rb")) | 86 | self.seen = pickle.load(open(self.pickle, "rb")) |
1863 | 83 | except: | 87 | except: |
1864 | @@ -132,9 +136,15 @@ class HardeningReporter(): | |||
1865 | 132 | tmpdir = tempfile.mkdtemp(prefix='unpack-%s-%s-' % (src, pkg)) | 136 | tmpdir = tempfile.mkdtemp(prefix='unpack-%s-%s-' % (src, pkg)) |
1866 | 133 | 137 | ||
1867 | 134 | # Unpack. | 138 | # Unpack. |
1871 | 135 | print "\t\tUnpacking into %s ..." % (tmpdir) | 139 | print("\t\tUnpacking into %s ..." % (tmpdir)) |
1872 | 136 | if call(['dpkg-deb', '-x', deb, tmpdir]) != 0: | 140 | try: |
1873 | 137 | print >> sys.stderr, "Could not unpack '%s'!?" % (deb) | 141 | # XXX: subprocess.call is less preferable compared with check_call |
1874 | 142 | # XXX: when we are only interested in handling failure cases and | ||
1875 | 143 | # XXX: not specific outputs and return codes -- by default we can | ||
1876 | 144 | # XXX: do nothing, this does relevant checks for us | ||
1877 | 145 | subprocess.check_call(['dpkg-deb', '-x', deb, tmpdir]) | ||
1878 | 146 | except subprocess.CalledProcessError: | ||
1879 | 147 | print("Could not unpack '%s'!?" % (deb), file=sys.stderr) | ||
1880 | 138 | # Force this package to be ignored. | 148 | # Force this package to be ignored. |
1881 | 139 | seen[src][pkg]['counts']['elf'] = 0 | 149 | seen[src][pkg]['counts']['elf'] = 0 |
1882 | 140 | return seen[src][pkg]['counts'] | 150 | return seen[src][pkg]['counts'] |
1883 | @@ -164,7 +174,7 @@ class HardeningReporter(): | |||
1884 | 164 | if len(elfs) > 0: | 174 | if len(elfs) > 0: |
1885 | 165 | #print elfs | 175 | #print elfs |
1886 | 166 | badpie = 0 | 176 | badpie = 0 |
1888 | 167 | p = Popen(['hardening-check'] + elfs, stdout=PIPE) | 177 | p = subprocess.Popen(['hardening-check'] + elfs, stdout=subprocess.PIPE) |
1889 | 168 | for line in p.stdout: | 178 | for line in p.stdout: |
1890 | 169 | if 'Position Independent Executable: ' in line: | 179 | if 'Position Independent Executable: ' in line: |
1891 | 170 | if ': yes' in line: | 180 | if ': yes' in line: |
1892 | @@ -194,7 +204,7 @@ class HardeningReporter(): | |||
1893 | 194 | shutil.rmtree(tmpdir, ignore_errors=False) | 204 | shutil.rmtree(tmpdir, ignore_errors=False) |
1894 | 195 | except: | 205 | except: |
1895 | 196 | # Fix insane unpacks. | 206 | # Fix insane unpacks. |
1897 | 197 | call(['chmod', '-R', 'u+rwx', tmpdir]) | 207 | subprocess.check_call(['chmod', '-R', 'u+rwx', tmpdir]) |
1898 | 198 | shutil.rmtree(tmpdir, ignore_errors=True) | 208 | shutil.rmtree(tmpdir, ignore_errors=True) |
1899 | 199 | 209 | ||
1900 | 200 | # Finished scanning this src/pkg combo, store it. | 210 | # Finished scanning this src/pkg combo, store it. |
1901 | @@ -207,7 +217,7 @@ class HardeningReporter(): | |||
1902 | 207 | class CacheArchive(): | 217 | class CacheArchive(): |
1903 | 208 | def __init__(self, srcs, reporter): | 218 | def __init__(self, srcs, reporter): |
1904 | 209 | self.cache, self.mapping = reporter.cache() | 219 | self.cache, self.mapping = reporter.cache() |
1906 | 210 | print "Mapping source packages ..." | 220 | print("Mapping source packages ...") |
1907 | 211 | self.bins = [x.strip() for x in open(srcs, "r").readlines()] | 221 | self.bins = [x.strip() for x in open(srcs, "r").readlines()] |
1908 | 212 | self.srcs = dict() | 222 | self.srcs = dict() |
1909 | 213 | for pkg in self.bins: | 223 | for pkg in self.bins: |
1910 | @@ -225,22 +235,6 @@ class CacheArchive(): | |||
1911 | 225 | return self.cache[src][pkg]['filename'] | 235 | return self.cache[src][pkg]['filename'] |
1912 | 226 | 236 | ||
1913 | 227 | 237 | ||
1914 | 228 | release = None | ||
1915 | 229 | arch = None | ||
1916 | 230 | component = None | ||
1917 | 231 | try: | ||
1918 | 232 | output = sys.argv[1] | ||
1919 | 233 | mirror = sys.argv[2] | ||
1920 | 234 | if len(sys.argv) > 3: | ||
1921 | 235 | release = sys.argv[3] | ||
1922 | 236 | arch = sys.argv[4] | ||
1923 | 237 | if len(sys.argv) > 5: | ||
1924 | 238 | component = sys.argv[5] | ||
1925 | 239 | except: | ||
1926 | 240 | print 'Usage: %s OUTDIR [BINPKGLIST|MIRROR RELEASE ARCH [COMPONENT]]' % (sys.argv[0]) | ||
1927 | 241 | print 'Example: %s /tmp/info /var/cache/mirrors/debian unstable amd64 main' % (sys.argv[0]) | ||
1928 | 242 | sys.exit(1) | ||
1929 | 243 | |||
1930 | 244 | def scan_archive(reporter, archive): | 238 | def scan_archive(reporter, archive): |
1931 | 245 | # The master package feature counts | 239 | # The master package feature counts |
1932 | 246 | counts = dict() | 240 | counts = dict() |
1933 | @@ -252,15 +246,15 @@ def scan_archive(reporter, archive): | |||
1934 | 252 | src_counts.setdefault('elf', 0) | 246 | src_counts.setdefault('elf', 0) |
1935 | 253 | badpie = 0 | 247 | badpie = 0 |
1936 | 254 | 248 | ||
1938 | 255 | print "Source: %s ..." % (src) | 249 | print("Source: %s ..." % (src)) |
1939 | 256 | for pkg in archive.binary_packages(src): | 250 | for pkg in archive.binary_packages(src): |
1940 | 257 | deb = archive.package_path(src, pkg) | 251 | deb = archive.package_path(src, pkg) |
1942 | 258 | print "\t%s (%s) ..." % (pkg, deb) | 252 | print("\t%s (%s) ..." % (pkg, deb)) |
1943 | 259 | bin_counts = reporter.examine(src, pkg, deb) | 253 | bin_counts = reporter.examine(src, pkg, deb) |
1944 | 260 | if bin_counts['elf'] == 0: | 254 | if bin_counts['elf'] == 0: |
1945 | 261 | # Ignore this deb. | 255 | # Ignore this deb. |
1946 | 262 | continue | 256 | continue |
1948 | 263 | print "\t\t%s" % (repr(bin_counts)) | 257 | print("\t\t%s" % (repr(bin_counts))) |
1949 | 264 | 258 | ||
1950 | 265 | # If we have a binary package with ELF and no PIE, | 259 | # If we have a binary package with ELF and no PIE, |
1951 | 266 | # this means a non-PIE executable was found. | 260 | # this means a non-PIE executable was found. |
1952 | @@ -278,7 +272,7 @@ def scan_archive(reporter, archive): | |||
1953 | 278 | src_counts.setdefault('pie', 0) | 272 | src_counts.setdefault('pie', 0) |
1954 | 279 | src_counts['pie'] = 0 | 273 | src_counts['pie'] = 0 |
1955 | 280 | 274 | ||
1957 | 281 | print "\t%s" % (repr(src_counts)) | 275 | print("\t%s" % (repr(src_counts))) |
1958 | 282 | 276 | ||
1959 | 283 | # If at least 1 binary's ELF has the option, count it as in source, | 277 | # If at least 1 binary's ELF has the option, count it as in source, |
1960 | 284 | # except for PIE, which is handled above as lacking non-PIE. | 278 | # except for PIE, which is handled above as lacking non-PIE. |
1961 | @@ -286,23 +280,47 @@ def scan_archive(reporter, archive): | |||
1962 | 286 | for name in count_names: | 280 | for name in count_names: |
1963 | 287 | if src_counts[name] > 0: | 281 | if src_counts[name] > 0: |
1964 | 288 | counts[name] += 1 | 282 | counts[name] += 1 |
1966 | 289 | print "%s\n" % (repr(counts)) | 283 | print("%s\n" % (repr(counts))) |
1967 | 290 | 284 | ||
1968 | 291 | return counts | 285 | return counts |
1969 | 292 | 286 | ||
1970 | 293 | 287 | ||
1986 | 294 | reporter = HardeningReporter(output) | 288 | if __name__ == "__main__": |
1987 | 295 | 289 | # * Code that is unguarded by this check will run if the file is ever | |
1988 | 296 | if release == None: | 290 | # * used in an import statement, even if we only plan to use or import |
1989 | 297 | archive = CacheArchive(mirror, reporter) | 291 | # * one function from this file. Guarding code behind this check means |
1990 | 298 | else: | 292 | # * it only runs when the file is invoked directly (i.e. ./myfile.py) |
1991 | 299 | print "Loading archive ..." | 293 | # * or via the interpreter, i.e. python myfile.py |
1992 | 300 | archive = Archive(mirror, release, arch, component) | 294 | release = None |
1993 | 301 | 295 | arch = None | |
1994 | 302 | counts = scan_archive(reporter, archive) | 296 | component = None |
1995 | 303 | 297 | # TODO: switch to argparse | |
1996 | 304 | # Append graph data. | 298 | try: |
1997 | 305 | for name in counts: | 299 | output = sys.argv[1] |
1998 | 306 | report = open(os.path.join(output, '%s.data' % (name)), "a") | 300 | mirror = sys.argv[2] |
1999 | 307 | report.write('%s %d\n' % (run_time, counts[name])) | 301 | if len(sys.argv) > 3: |
2000 | 308 | report.close() | 302 | release = sys.argv[3] |
2001 | 303 | arch = sys.argv[4] | ||
2002 | 304 | if len(sys.argv) > 5: | ||
2003 | 305 | component = sys.argv[5] | ||
2004 | 306 | except: | ||
2005 | 307 | print('Usage: %s OUTDIR [BINPKGLIST|MIRROR RELEASE ARCH [COMPONENT]]' % (sys.argv[0])) | ||
2006 | 308 | print('Example: %s /tmp/info /var/cache/mirrors/debian unstable amd64 main' % (sys.argv[0])) | ||
2007 | 309 | sys.exit(1) | ||
2008 | 310 | |||
2009 | 311 | reporter = HardeningReporter(output) | ||
2010 | 312 | |||
2011 | 313 | if release == None: | ||
2012 | 314 | archive = CacheArchive(mirror, reporter) | ||
2013 | 315 | else: | ||
2014 | 316 | print("Loading archive ...") | ||
2015 | 317 | archive = Archive(mirror, release, arch, component) | ||
2016 | 318 | |||
2017 | 319 | counts = scan_archive(reporter, archive) | ||
2018 | 320 | |||
2019 | 321 | # Append graph data. | ||
2020 | 322 | for name in counts: | ||
2021 | 323 | # * Open files in context managers to make sure file handles are | ||
2022 | 324 | # * closed properly before the process is cleaned up | ||
2023 | 325 | with open(os.path.join(output, '%s.data' % (name)), "a") as report: | ||
2024 | 326 | report.write('%s %d\n' % (run_time, counts[name])) | ||
2025 | diff --git a/repo-tools/count-hash-sources b/repo-tools/count-hash-sources | |||
2026 | index 48e6c2d..de5fbf4 100755 | |||
2027 | --- a/repo-tools/count-hash-sources | |||
2028 | +++ b/repo-tools/count-hash-sources | |||
2029 | @@ -1,12 +1,20 @@ | |||
2031 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
2032 | 2 | 2 | ||
2033 | 3 | from __future__ import absolute_import, print_function | ||
2034 | 3 | import deb822 # from python-debian | 4 | import deb822 # from python-debian |
2035 | 4 | import gzip | ||
2036 | 5 | import argparse | 5 | import argparse |
2037 | 6 | import contextlib | ||
2038 | 7 | import gzip | ||
2039 | 8 | import io | ||
2040 | 6 | import os | 9 | import os |
2041 | 7 | import re | 10 | import re |
2042 | 8 | import sys | 11 | import sys |
2044 | 9 | import urllib2 | 12 | |
2045 | 13 | if sys.version_info[0] == 2: | ||
2046 | 14 | from urllib2 import urlopen | ||
2047 | 15 | else: | ||
2048 | 16 | from urllib.request import urlopen | ||
2049 | 17 | |||
2050 | 10 | 18 | ||
2051 | 11 | components = ['main', 'multiverse', 'restricted', 'universe'] | 19 | components = ['main', 'multiverse', 'restricted', 'universe'] |
2052 | 12 | default_releases = ['precise', 'trusty', 'xenial', 'bionic', 'cosmic', 'disco'] | 20 | default_releases = ['precise', 'trusty', 'xenial', 'bionic', 'cosmic', 'disco'] |
2053 | @@ -16,22 +24,23 @@ def count_md5only_sources(sources_list): | |||
2054 | 16 | md5only = 0 | 24 | md5only = 0 |
2055 | 17 | sha1only = 0 | 25 | sha1only = 0 |
2056 | 18 | langpack = 0 | 26 | langpack = 0 |
2069 | 19 | for src in deb822.Sources.iter_paragraphs(file(sources_list)): | 27 | with open(sources_list, "r") as sources_handle: |
2070 | 20 | count += 1 | 28 | for src in deb822.Sources.iter_paragraphs(sources_handle): |
2071 | 21 | if not src.has_key('Checksums-Sha256'): | 29 | count += 1 |
2072 | 22 | sha1only += 1 | 30 | if 'Checksums-Sha256' not in src: |
2073 | 23 | if not src.has_key('Checksums-Sha1'): | 31 | sha1only += 1 |
2074 | 24 | if re.match("language-pack-.*", src['Package']): | 32 | if 'Checksums-Sha1' not in src: |
2075 | 25 | langpack += 1 | 33 | if re.match("language-pack-.*", src['Package']): |
2076 | 26 | else: | 34 | langpack += 1 |
2077 | 27 | md5only += 1 | 35 | else: |
2078 | 28 | #print src['Package'] | 36 | md5only += 1 |
2079 | 29 | if not src.has_key('Files'): | 37 | #print src['Package'] |
2080 | 30 | print "Bizarre, src package '%s' has no Files section" %(src['Package']) | 38 | if 'Files' not in src: |
2081 | 39 | print("Bizarre, src package '%s' has no Files section" %(src['Package'])) | ||
2082 | 31 | return (count, md5only, sha1only, langpack) | 40 | return (count, md5only, sha1only, langpack) |
2083 | 32 | 41 | ||
2084 | 33 | def download_release_files(release): | 42 | def download_release_files(release): |
2086 | 34 | print "Downloading release files for %s" % release | 43 | print("Downloading release files for %s" % release) |
2087 | 35 | 44 | ||
2088 | 36 | for component in components: | 45 | for component in components: |
2089 | 37 | 46 | ||
2090 | @@ -42,39 +51,43 @@ def download_release_files(release): | |||
2091 | 42 | continue | 51 | continue |
2092 | 43 | 52 | ||
2093 | 44 | url= "http://archive.ubuntu.com/ubuntu/dists/%s/%s/source/Sources.gz" % (release, component) | 53 | url= "http://archive.ubuntu.com/ubuntu/dists/%s/%s/source/Sources.gz" % (release, component) |
2130 | 45 | print "Downloading %s..." % url | 54 | print("Downloading %s..." % url) |
2131 | 46 | 55 | ||
2132 | 47 | # Download it | 56 | # * Download compressed contents and write it to a buffer |
2133 | 48 | open_url = urllib2.urlopen(url) | 57 | compressed_contents = io.BytesIO() |
2134 | 49 | output = open('Sources.gz','wb') | 58 | with contextlib.closing(urlopen(url)) as response: |
2135 | 50 | output.write(open_url.read()) | 59 | compressed_contents.write(response.read()) |
2136 | 51 | output.close() | 60 | compressed_contents.seek(0) |
2137 | 52 | 61 | ||
2138 | 53 | # Now uncompress it | 62 | # * Now lets unzip the buffer, decode it, clean up line endings and |
2139 | 54 | f_in = gzip.open('Sources.gz', 'rb') | 63 | # * write to a target file |
2140 | 55 | f_out = open(file_name, 'wb') | 64 | with gzip.GzipFile(fileobj=compressed_contents, mode="rb") as f_in: |
2141 | 56 | f_out.writelines(f_in) | 65 | with open(file_name, "w") as f_out: |
2142 | 57 | f_out.close() | 66 | f_out.write(f_in.read().decode("utf-8").replace(r"\r\n", r"\n")) |
2143 | 58 | f_in.close() | 67 | |
2144 | 59 | 68 | print("Download completed.") | |
2145 | 60 | os.unlink('Sources.gz') | 69 | |
2146 | 61 | 70 | ||
2147 | 62 | print "Download completed." | 71 | if __name__ == "__main__": |
2148 | 63 | 72 | # * Code that is unguarded by this check will run if the file is ever | |
2149 | 64 | parser = argparse.ArgumentParser(description='Finds source packages with md5 only hash sums') | 73 | # * used in an import statement, even if we only plan to use or import |
2150 | 65 | parser.add_argument('-r', '--release', action='append', help="find sources in a specific release") | 74 | # * one function from this file. Guarding code behind this check means |
2151 | 66 | args = parser.parse_args() | 75 | # * it only runs when the file is invoked directly (i.e. ./myfile.py) |
2152 | 67 | 76 | # * or via the interpreter, i.e. python myfile.py | |
2153 | 68 | if args.release: | 77 | parser = argparse.ArgumentParser(description='Finds source packages with md5 only hash sums') |
2154 | 69 | releases = args.release | 78 | parser.add_argument('-r', '--release', action='append', help="find sources in a specific release") |
2155 | 70 | else: | 79 | args = parser.parse_args() |
2156 | 71 | releases = default_releases | 80 | |
2157 | 72 | 81 | if args.release: | |
2158 | 73 | for release in releases: | 82 | releases = args.release |
2159 | 74 | download_release_files(release) | 83 | else: |
2160 | 75 | 84 | releases = default_releases | |
2161 | 76 | for release in releases: | 85 | |
2162 | 77 | for component in components: | 86 | for release in releases: |
2163 | 78 | (total, md5only, sha1only, langpack) = count_md5only_sources("%s-sources-%s" %(release, component)) | 87 | download_release_files(release) |
2164 | 79 | print "%s %s: \ttotal: %d \tmd5only: %d\tsha1only: %d\tlangpacks: %d" %(release, component, total, md5only, sha1only, langpack) | 88 | |
2165 | 80 | 89 | for release in releases: | |
2166 | 90 | for component in components: | ||
2167 | 91 | total, md5only, sha1only, langpack = count_md5only_sources("%s-sources-%s" %(release, component)) | ||
2168 | 92 | print("%s %s: \ttotal: %d \tmd5only: %d\tsha1only: %d\tlangpacks: %d" %(release, component, total, md5only, sha1only, langpack)) | ||
2169 | 93 | print() | ||
2170 | diff --git a/repo-tools/for-archive-tools/has-execstack b/repo-tools/for-archive-tools/has-execstack | |||
2171 | index 4d53338..8453f2b 100755 | |||
2172 | --- a/repo-tools/for-archive-tools/has-execstack | |||
2173 | +++ b/repo-tools/for-archive-tools/has-execstack | |||
2174 | @@ -1,27 +1,42 @@ | |||
2176 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
2177 | 2 | # Copyright 2009 Canonical, Ltd | 2 | # Copyright 2009 Canonical, Ltd |
2178 | 3 | # Author: Kees Cook <kees@ubuntu.com> | 3 | # Author: Kees Cook <kees@ubuntu.com> |
2179 | 4 | # License: GPLv3 | 4 | # License: GPLv3 |
2180 | 5 | # | 5 | # |
2181 | 6 | # Expects to be run via "unpack-search" within "for-archive" | 6 | # Expects to be run via "unpack-search" within "for-archive" |
2182 | 7 | # Checks only ELF files for execstack, and reports anything non-exec or unknown | 7 | # Checks only ELF files for execstack, and reports anything non-exec or unknown |
2184 | 8 | import sys, subprocess | 8 | from __future__ import absolute_import, print_function |
2185 | 9 | import os | ||
2186 | 10 | import subprocess | ||
2187 | 11 | import sys | ||
2188 | 9 | files = sys.argv[1:] | 12 | files = sys.argv[1:] |
2189 | 10 | if files[0] == '--': | 13 | if files[0] == '--': |
2190 | 11 | files.pop(0) | 14 | files.pop(0) |
2191 | 12 | if files[0] == '--': | 15 | if files[0] == '--': |
2192 | 13 | files.pop(0) | 16 | files.pop(0) |
2205 | 14 | devnull = open('/dev/null','w') | 17 | # * Here we use a context manager again to make sure the handle is closed |
2206 | 15 | for f in files: | 18 | with open('/dev/null','w') as devnull: |
2207 | 16 | #print >>sys.stderr, f | 19 | for f in files: |
2208 | 17 | try: | 20 | if not os.path.exists(f) and os.path.isfile(f): |
2209 | 18 | ok = (open(f).read(4) == '\x7fELF') | 21 | continue |
2210 | 19 | except: | 22 | with open(f, "rb") as fh: |
2211 | 20 | continue | 23 | try: |
2212 | 21 | if ok: | 24 | ok = f.read(4) == b"\x7fELF" |
2213 | 22 | out = subprocess.Popen(['execstack','-q',f],stdout=subprocess.PIPE,stderr=devnull).communicate()[0] | 25 | except Exception: |
2202 | 23 | for line in out.splitlines(): | ||
2203 | 24 | line = line.strip() | ||
2204 | 25 | if line.startswith('- '): | ||
2214 | 26 | continue | 26 | continue |
2216 | 27 | print line | 27 | if ok: |
2217 | 28 | # * the .communicate() call returns a 2-tuple (stdout, stderr), so | ||
2218 | 29 | # * we are implicitly throwing away stderr by assigning it to _ | ||
2219 | 30 | # * which is ignored in python | ||
2220 | 31 | # * Note that we are using 'universal_newlines=True' which actually | ||
2221 | 32 | # * tells the interpreter to give back unicode output rather than | ||
2222 | 33 | # * bytes, so we will be equipped for moving back and forth between | ||
2223 | 34 | # * python 2 and python 3 | ||
2224 | 35 | out, _ = subprocess.Popen( | ||
2225 | 36 | ['execstack','-q',f], stdout=subprocess.PIPE, stderr=devnull, | ||
2226 | 37 | universal_newlines=True | ||
2227 | 38 | ).communicate() | ||
2228 | 39 | for line in out.splitlines(): | ||
2229 | 40 | line = line.strip() | ||
2230 | 41 | if not line.startswith('- '): | ||
2231 | 42 | print(line) | ||
2232 | diff --git a/repo-tools/for-archive-tools/has-symbols b/repo-tools/for-archive-tools/has-symbols | |||
2233 | index a48402c..a62af89 100755 | |||
2234 | --- a/repo-tools/for-archive-tools/has-symbols | |||
2235 | +++ b/repo-tools/for-archive-tools/has-symbols | |||
2236 | @@ -1,12 +1,15 @@ | |||
2238 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
2239 | 2 | # Copyright 2009 Canonical, Ltd | 2 | # Copyright 2009 Canonical, Ltd |
2240 | 3 | # Author: Kees Cook <kees@ubuntu.com> | 3 | # Author: Kees Cook <kees@ubuntu.com> |
2241 | 4 | # License: GPLv3 | 4 | # License: GPLv3 |
2242 | 5 | # | 5 | # |
2243 | 6 | # Expects to be run via "unpack-search" within "for-archive" | 6 | # Expects to be run via "unpack-search" within "for-archive" |
2244 | 7 | # Checks only ELF files for symbols, and reports anything referencing these symbols | 7 | # Checks only ELF files for symbols, and reports anything referencing these symbols |
2246 | 8 | import sys, subprocess | 8 | from __future__ import absolute_import, print_function |
2247 | 9 | import os | ||
2248 | 9 | import re | 10 | import re |
2249 | 11 | import subprocess | ||
2250 | 12 | import sys | ||
2251 | 10 | 13 | ||
2252 | 11 | symrx = re.compile(r'\*UND\*.*(_ZNSt6chrono12system_clock3nowEv|_ZNSt6chrono12steady_clock3nowEv)') | 14 | symrx = re.compile(r'\*UND\*.*(_ZNSt6chrono12system_clock3nowEv|_ZNSt6chrono12steady_clock3nowEv)') |
2253 | 12 | #symrx = re.compile(r'\*UND\*.*(__fprintf_chk|__progname_full)') | 15 | #symrx = re.compile(r'\*UND\*.*(__fprintf_chk|__progname_full)') |
2254 | @@ -16,17 +19,29 @@ if files[0] == '--': | |||
2255 | 16 | files.pop(0) | 19 | files.pop(0) |
2256 | 17 | if files[0] == '--': | 20 | if files[0] == '--': |
2257 | 18 | files.pop(0) | 21 | files.pop(0) |
2270 | 19 | devnull = open('/dev/null','w') | 22 | # * Here we use a context manager again to make sure the handle is closed |
2271 | 20 | for f in files: | 23 | with open('/dev/null','w') as devnull: |
2272 | 21 | #print >>sys.stderr, f | 24 | for f in files: |
2273 | 22 | try: | 25 | if not os.path.exists(f) and os.path.isfile(f): |
2274 | 23 | ok = (open(f).read(4) == '\x7fELF') | 26 | continue |
2275 | 24 | except: | 27 | with open(f, "rb") as fh: |
2276 | 25 | continue | 28 | try: |
2277 | 26 | if ok: | 29 | ok = f.read(4) == b"\x7fELF" |
2278 | 27 | out = subprocess.Popen(['objdump','-T',f],stdout=subprocess.PIPE,stderr=devnull).communicate()[0] | 30 | except Exception: |
2267 | 28 | for line in out.splitlines(): | ||
2268 | 29 | line = line.strip() | ||
2269 | 30 | if not symrx.search(line): | ||
2279 | 31 | continue | 31 | continue |
2281 | 32 | print line | 32 | if ok: |
2282 | 33 | # * the .communicate() call returns a 2-tuple (stdout, stderr), so | ||
2283 | 34 | # * we are implicitly throwing away stderr by assigning it to _ | ||
2284 | 35 | # * which is ignored in python | ||
2285 | 36 | # * Note that we are using 'universal_newlines=True' which actually | ||
2286 | 37 | # * tells the interpreter to give back unicode output rather than | ||
2287 | 38 | # * bytes, so we will be equipped for moving back and forth between | ||
2288 | 39 | # * python 2 and python 3 | ||
2289 | 40 | out, _ = subprocess.Popen( | ||
2290 | 41 | ['objdump', '-T' ,f], stdout=subprocess.PIPE, stderr=devnull, | ||
2291 | 42 | universal_newlines=True | ||
2292 | 43 | ).communicate() | ||
2293 | 44 | for line in out.splitlines(): | ||
2294 | 45 | line = line.strip() | ||
2295 | 46 | if symrx.search(line): | ||
2296 | 47 | print(line) | ||
2297 | 33 | \ No newline at end of file | 48 | \ No newline at end of file |
2298 | diff --git a/repo-tools/packages-support-status b/repo-tools/packages-support-status | |||
2299 | index 9817a80..c0082f6 100755 | |||
2300 | --- a/repo-tools/packages-support-status | |||
2301 | +++ b/repo-tools/packages-support-status | |||
2302 | @@ -1,4 +1,4 @@ | |||
2304 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
2305 | 2 | 2 | ||
2306 | 3 | # Author: Marc Deslauriers <marc.deslauriers@ubuntu.com> | 3 | # Author: Marc Deslauriers <marc.deslauriers@ubuntu.com> |
2307 | 4 | # Copyright (C) 2012 Canonical Ltd. | 4 | # Copyright (C) 2012 Canonical Ltd. |
2308 | @@ -12,17 +12,23 @@ | |||
2309 | 12 | # | 12 | # |
2310 | 13 | # You can download the Release files for i386 with the --download command. | 13 | # You can download the Release files for i386 with the --download command. |
2311 | 14 | # | 14 | # |
2313 | 15 | from __future__ import print_function | 15 | from __future__ import absolute_import, print_function |
2314 | 16 | 16 | ||
2315 | 17 | import contextlib | ||
2316 | 18 | import io | ||
2317 | 17 | import gzip | 19 | import gzip |
2318 | 18 | import os | 20 | import os |
2319 | 19 | import re | 21 | import re |
2320 | 20 | import sys | 22 | import sys |
2321 | 21 | import urllib.error | ||
2322 | 22 | import urllib.parse | ||
2323 | 23 | import urllib.request | ||
2324 | 24 | from optparse import OptionParser | 23 | from optparse import OptionParser |
2325 | 25 | 24 | ||
2326 | 25 | if sys.version_info[0] == 2: | ||
2327 | 26 | from urllib2 import urlopen | ||
2328 | 27 | else: | ||
2329 | 28 | from urllib.request import urlopen | ||
2330 | 29 | |||
2331 | 30 | # TODO: Switch to argparse | ||
2332 | 31 | |||
2333 | 26 | components = ['main', 'multiverse', 'restricted', 'universe'] | 32 | components = ['main', 'multiverse', 'restricted', 'universe'] |
2334 | 27 | 33 | ||
2335 | 28 | def parse_package_files(): | 34 | def parse_package_files(): |
2336 | @@ -84,56 +90,59 @@ def download_release_files(release): | |||
2337 | 84 | url= "http://archive.ubuntu.com/ubuntu/dists/%s/%s/binary-i386/Packages.gz" % (release, component) | 90 | url= "http://archive.ubuntu.com/ubuntu/dists/%s/%s/binary-i386/Packages.gz" % (release, component) |
2338 | 85 | print("Downloading %s..." % url) | 91 | print("Downloading %s..." % url) |
2339 | 86 | 92 | ||
2355 | 87 | # Download it | 93 | # * Download compressed contents and write it to a buffer |
2356 | 88 | open_url = urllib.request.urlopen(url) | 94 | compressed_contents = io.BytesIO() |
2357 | 89 | output = open('Packages.gz', 'wb') | 95 | with contextlib.closing(urlopen(url)) as response: |
2358 | 90 | output.write(open_url.read()) | 96 | compressed_contents.write(response.read()) |
2359 | 91 | output.close() | 97 | compressed_contents.seek(0) |
2360 | 92 | 98 | ||
2361 | 93 | # Now uncompress it | 99 | # * Now lets unzip the buffer, decode it, clean up line endings and |
2362 | 94 | f_in = gzip.open('Packages.gz', 'rb') | 100 | # * write to a target file |
2363 | 95 | f_out = open(file_name, 'wb') | 101 | with gzip.GzipFile(fileobj=compressed_contents, mode="rb") as f_in: |
2364 | 96 | f_out.writelines(f_in) | 102 | with open(file_name, "w") as f_out: |
2365 | 97 | f_out.close() | 103 | f_out.write(f_in.read().decode("utf-8").replace(r"\r\n", r"\n")) |
2351 | 98 | f_in.close() | ||
2352 | 99 | |||
2353 | 100 | os.unlink('Packages.gz') | ||
2354 | 101 | |||
2366 | 102 | print("Download completed.") | 104 | print("Download completed.") |
2367 | 103 | 105 | ||
2368 | 104 | def print_package(package, component, supported): | 106 | def print_package(package, component, supported): |
2369 | 105 | print("%-50s %-12s %s" % (package, component, supported)) | 107 | print("%-50s %-12s %s" % (package, component, supported)) |
2370 | 106 | 108 | ||
2403 | 107 | parser = OptionParser() | 109 | |
2404 | 108 | parser.add_option("", "--show-unsupported", | 110 | if __name__ == "__main__": |
2405 | 109 | action="append_const", dest="filter", | 111 | # * Code that is unguarded by this check will run if the file is ever |
2406 | 110 | const="Unsupported", help="Show unsupported packages") | 112 | # * used in an import statement, even if we only plan to use or import |
2407 | 111 | parser.add_option("", "--show-18m", | 113 | # * one function from this file. Guarding code behind this check means |
2408 | 112 | action="append_const", dest="filter", | 114 | # * it only runs when the file is invoked directly (i.e. ./myfile.py) |
2409 | 113 | const="18m", help="Show 18m supported packages") | 115 | # * or via the interpreter, i.e. python myfile.py |
2410 | 114 | parser.add_option("", "--show-3y", | 116 | parser = OptionParser() |
2411 | 115 | action="append_const", dest="filter", | 117 | parser.add_option("", "--show-unsupported", |
2412 | 116 | const="3y", help="Show 3y supported packages") | 118 | action="append_const", dest="filter", |
2413 | 117 | parser.add_option("", "--show-5y", | 119 | const="Unsupported", help="Show unsupported packages") |
2414 | 118 | action="append_const", dest="filter", | 120 | parser.add_option("", "--show-18m", |
2415 | 119 | const="5y", help="Show 5y supported packages") | 121 | action="append_const", dest="filter", |
2416 | 120 | parser.add_option("", "--download", metavar="RELEASE", | 122 | const="18m", help="Show 18m supported packages") |
2417 | 121 | action="store", dest="download", | 123 | parser.add_option("", "--show-3y", |
2418 | 122 | help="Download release files for RELEASE in current directory") | 124 | action="append_const", dest="filter", |
2419 | 123 | 125 | const="3y", help="Show 3y supported packages") | |
2420 | 124 | (options, args) = parser.parse_args() | 126 | parser.add_option("", "--show-5y", |
2421 | 125 | 127 | action="append_const", dest="filter", | |
2422 | 126 | if options.download: | 128 | const="5y", help="Show 5y supported packages") |
2423 | 127 | download_release_files(options.download) | 129 | parser.add_option("", "--download", metavar="RELEASE", |
2424 | 128 | sys.exit(0) | 130 | action="store", dest="download", |
2425 | 129 | 131 | help="Download release files for RELEASE in current directory") | |
2426 | 130 | packages = parse_package_files() | 132 | |
2427 | 131 | all_packages = sorted(packages.keys()) | 133 | (options, args) = parser.parse_args() |
2428 | 132 | for package in all_packages: | 134 | |
2429 | 133 | 135 | if options.download: | |
2430 | 134 | if options.filter: | 136 | download_release_files(options.download) |
2431 | 135 | if packages[package]['supported'] not in options.filter: | 137 | sys.exit(0) |
2432 | 136 | continue | 138 | |
2433 | 137 | 139 | packages = parse_package_files() | |
2434 | 138 | print_package(package, packages[package]['component'], packages[package]['supported']) | 140 | all_packages = sorted(packages.keys()) |
2435 | 141 | for package in all_packages: | ||
2436 | 142 | |||
2437 | 143 | if options.filter: | ||
2438 | 144 | if packages[package]['supported'] not in options.filter: | ||
2439 | 145 | continue | ||
2440 | 146 | |||
2441 | 147 | print_package(package, packages[package]['component'], packages[package]['supported']) | ||
2442 | 139 | 148 | ||
2443 | diff --git a/repo-tools/universe-binaries-with-sources-in-main.py b/repo-tools/universe-binaries-with-sources-in-main.py | |||
2444 | index 8c76793..ccd1a03 100755 | |||
2445 | --- a/repo-tools/universe-binaries-with-sources-in-main.py | |||
2446 | +++ b/repo-tools/universe-binaries-with-sources-in-main.py | |||
2447 | @@ -1,10 +1,12 @@ | |||
2449 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
2450 | 2 | 2 | ||
2451 | 3 | from __future__ import absolute_import, print_function | ||
2452 | 3 | packages = "./universe/binary-i386/Packages" | 4 | packages = "./universe/binary-i386/Packages" |
2453 | 4 | sources = "./main/source/Sources" | 5 | sources = "./main/source/Sources" |
2454 | 5 | 6 | ||
2455 | 6 | # Get all the binaries in universe | 7 | # Get all the binaries in universe |
2457 | 7 | lines = open(packages).readlines() | 8 | with open(packages, "r") as fh: |
2458 | 9 | lines = fh.readlines() | ||
2459 | 8 | bins = {} | 10 | bins = {} |
2460 | 9 | for line in lines: | 11 | for line in lines: |
2461 | 10 | line = line.strip() | 12 | line = line.strip() |
2462 | @@ -12,6 +14,8 @@ for line in lines: | |||
2463 | 12 | bins[line.split()[1]] = True | 14 | bins[line.split()[1]] = True |
2464 | 13 | 15 | ||
2465 | 14 | # then see if one of these binaries matches the Binary line in sources from main | 16 | # then see if one of these binaries matches the Binary line in sources from main |
2466 | 17 | with open(sources, "r") as fh: | ||
2467 | 18 | lines = fh.readlines() | ||
2468 | 15 | lines = open(sources).readlines() | 19 | lines = open(sources).readlines() |
2469 | 16 | srcs = {} | 20 | srcs = {} |
2470 | 17 | src = None | 21 | src = None |
2471 | @@ -23,4 +27,4 @@ for line in lines: | |||
2472 | 23 | for b in line.partition(' ')[2].split(','): | 27 | for b in line.partition(' ')[2].split(','): |
2473 | 24 | b = b.strip() | 28 | b = b.strip() |
2474 | 25 | if b in bins: | 29 | if b in bins: |
2476 | 26 | print "%s (src: %s)" % (b, src) | 30 | print("%s (src: %s)" % (b, src)) |
2477 | diff --git a/snaps/coverity-ubuntu-security/files/bin/refresh-auth-key b/snaps/coverity-ubuntu-security/files/bin/refresh-auth-key | |||
2478 | index 88ac51a..9f6cf3c 100755 | |||
2479 | --- a/snaps/coverity-ubuntu-security/files/bin/refresh-auth-key | |||
2480 | +++ b/snaps/coverity-ubuntu-security/files/bin/refresh-auth-key | |||
2481 | @@ -1,5 +1,6 @@ | |||
2483 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
2484 | 2 | 2 | ||
2485 | 3 | from __future__ import absolute_import, print_function | ||
2486 | 3 | import json | 4 | import json |
2487 | 4 | import os | 5 | import os |
2488 | 5 | import subprocess | 6 | import subprocess |
2489 | diff --git a/utilities/build_failures.py b/utilities/build_failures.py | |||
2490 | index 18a2896..d4df8cc 100755 | |||
2491 | --- a/utilities/build_failures.py | |||
2492 | +++ b/utilities/build_failures.py | |||
2493 | @@ -1,4 +1,4 @@ | |||
2495 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/env python3 |
2496 | 2 | 2 | ||
2497 | 3 | # This is a start of a script that looks for build failures on the | 3 | # This is a start of a script that looks for build failures on the |
2498 | 4 | # yaml version of the excuses page from | 4 | # yaml version of the excuses page from |
2499 | @@ -8,20 +8,26 @@ | |||
2500 | 8 | # In particular, we're looking for failures due to gcc -pie by default | 8 | # In particular, we're looking for failures due to gcc -pie by default |
2501 | 9 | # on amd64, where a build will succeed on i386 but fail on amd64 | 9 | # on amd64, where a build will succeed on i386 but fail on amd64 |
2502 | 10 | 10 | ||
2504 | 11 | from yaml import load, dump | 11 | from __future__ import absolute_import, print_function |
2505 | 12 | from yaml import safe_load, safe_dump | ||
2506 | 12 | 13 | ||
2507 | 13 | with open("update_excuses.yaml") as f: | ||
2508 | 14 | data = load(f) | ||
2509 | 15 | 14 | ||
2511 | 16 | source_entries = data['sources'] | 15 | def check_builds(): |
2512 | 16 | with open("update_excuses.yaml", "r") as f: | ||
2513 | 17 | data = safe_load(f) | ||
2514 | 17 | 18 | ||
2524 | 18 | for s in source_entries: | 19 | source_entries = data['sources'] |
2516 | 19 | if 'missing-builds' in s.keys(): | ||
2517 | 20 | arches = s['missing-builds']['on-architectures'] | ||
2518 | 21 | if 'amd64' in arches and not 'i386' in arches: | ||
2519 | 22 | for excuse in s['excuses']: | ||
2520 | 23 | if excuse.startswith("missing build on") and '>amd64<' in excuse: | ||
2521 | 24 | url = excuse.split('"')[1] | ||
2522 | 25 | print('%s: %s' % (s['source'], url)) | ||
2523 | 26 | #print('%s' %s) | ||
2525 | 27 | 20 | ||
2526 | 21 | for s in source_entries: | ||
2527 | 22 | if 'missing-builds' in s: | ||
2528 | 23 | arches = s['missing-builds']['on-architectures'] | ||
2529 | 24 | if 'amd64' in arches and 'i386' not in arches: | ||
2530 | 25 | for excuse in s['excuses']: | ||
2531 | 26 | if excuse.startswith("missing build on") and '>amd64<' in excuse: | ||
2532 | 27 | url = excuse.split('"')[1] | ||
2533 | 28 | print('%s: %s' % (s['source'], url)) | ||
2534 | 29 | #print('%s' %s) | ||
2535 | 30 | |||
2536 | 31 | |||
2537 | 32 | if __name__ == "__main__": | ||
2538 | 33 | check_builds() | ||
2539 | 28 | \ No newline at end of file | 34 | \ No newline at end of file |
2540 | diff --git a/utilities/ceviche b/utilities/ceviche | |||
2541 | index 546482b..4f7e3c5 100755 | |||
2542 | --- a/utilities/ceviche | |||
2543 | +++ b/utilities/ceviche | |||
2544 | @@ -1,4 +1,4 @@ | |||
2546 | 1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python3 |
2547 | 2 | 2 | ||
2548 | 3 | # Author: Paulo Flabiano Smorigo <pfsmorigo@canonical.com> | 3 | # Author: Paulo Flabiano Smorigo <pfsmorigo@canonical.com> |
2549 | 4 | # Copyright (C) 2020 Canonical Ltd. | 4 | # Copyright (C) 2020 Canonical Ltd. |
2550 | @@ -7,17 +7,26 @@ | |||
2551 | 7 | # Public License, Version 2 or later. See http://www.gnu.org/copyleft/gpl.html | 7 | # Public License, Version 2 or later. See http://www.gnu.org/copyleft/gpl.html |
2552 | 8 | # for details. | 8 | # for details. |
2553 | 9 | 9 | ||
2554 | 10 | from __future__ import absolute_import, print_function | ||
2555 | 11 | import contextlib | ||
2556 | 10 | import curses | 12 | import curses |
2557 | 13 | import glob | ||
2558 | 11 | import json | 14 | import json |
2559 | 12 | import optparse | 15 | import optparse |
2560 | 13 | import os | 16 | import os |
2561 | 14 | import pickle | ||
2562 | 15 | import re | 17 | import re |
2563 | 16 | import subprocess | 18 | import subprocess |
2564 | 17 | import sys | 19 | import sys |
2565 | 18 | import time | 20 | import time |
2568 | 19 | import urllib2 | 21 | |
2569 | 20 | import glob | 22 | if sys.version_info[0] == 2: |
2570 | 23 | from urllib2 import urlopen | ||
2571 | 24 | import cPickle as pickle | ||
2572 | 25 | raw_input = raw_input | ||
2573 | 26 | else: | ||
2574 | 27 | from urllib.request import urlopen | ||
2575 | 28 | import pickle | ||
2576 | 29 | raw_input = input | ||
2577 | 21 | 30 | ||
2578 | 22 | # cve_lib may not be in PYTHONPATH so try harder to find it | 31 | # cve_lib may not be in PYTHONPATH so try harder to find it |
2579 | 23 | try: | 32 | try: |
2580 | @@ -155,8 +164,11 @@ def main_screen(stdscr, opt, args): | |||
2581 | 155 | colors.append(["high", 197, -1]) | 164 | colors.append(["high", 197, -1]) |
2582 | 156 | colors.append(["critical", 197, -1]) | 165 | colors.append(["critical", 197, -1]) |
2583 | 157 | 166 | ||
2586 | 158 | for i in range(0, len(colors)): | 167 | for i, color_triplet in enumerate(colors, start=1): |
2587 | 159 | curses.init_pair(i + 1, colors[i][1], colors[i][2]) | 168 | # * Range operations are slightly different between python 2 and 3 |
2588 | 169 | # * so should be avoided wherever possible | ||
2589 | 170 | _, fg_color, bg_color = color_triplet | ||
2590 | 171 | curses.init_pair(i, fg_color, bg_color) | ||
2591 | 160 | 172 | ||
2592 | 161 | downloaded = [] | 173 | downloaded = [] |
2593 | 162 | if os.path.isdir(DOWNLOAD_PATH): | 174 | if os.path.isdir(DOWNLOAD_PATH): |
2594 | @@ -519,6 +531,7 @@ def main_screen(stdscr, opt, args): | |||
2595 | 519 | stdscr.addstr(x, columns_start - 7, "%6d" % item[COL_POP]) | 531 | stdscr.addstr(x, columns_start - 7, "%6d" % item[COL_POP]) |
2596 | 520 | 532 | ||
2597 | 521 | y = columns_start | 533 | y = columns_start |
2598 | 534 | # check the status on each supported release | ||
2599 | 522 | for i in range(COL_REL, len(RELEASES) + COL_REL): | 535 | for i in range(COL_REL, len(RELEASES) + COL_REL): |
2600 | 523 | release_status = item[i] | 536 | release_status = item[i] |
2601 | 524 | if release_status == "needed" \ | 537 | if release_status == "needed" \ |
2602 | @@ -706,7 +719,7 @@ def run_command(stdscr, command, pause = False): | |||
2603 | 706 | os.system("bash -c \"%s\"" % command) | 719 | os.system("bash -c \"%s\"" % command) |
2604 | 707 | if pause: | 720 | if pause: |
2605 | 708 | try: | 721 | try: |
2607 | 709 | input("\nPress Enter to continue...") | 722 | raw_input("\nPress Enter to continue...") |
2608 | 710 | except: | 723 | except: |
2609 | 711 | pass | 724 | pass |
2610 | 712 | curses.reset_prog_mode() | 725 | curses.reset_prog_mode() |
2611 | @@ -755,7 +768,7 @@ def reload_persistent_data(stdscr, opt): | |||
2612 | 755 | 768 | ||
2613 | 756 | column = COL_REL | 769 | column = COL_REL |
2614 | 757 | for release in RELEASES: | 770 | for release in RELEASES: |
2616 | 758 | if release in table[cve][package].keys(): | 771 | if release in table[cve][package] |
2617 | 759 | item[column] = table[cve][package][release] | 772 | item[column] = table[cve][package][release] |
2618 | 760 | else: | 773 | else: |
2619 | 761 | item[column] = "---" | 774 | item[column] = "---" |
2620 | @@ -782,13 +795,13 @@ def load_persistent_data(stdscr, opt): | |||
2621 | 782 | return reload_persistent_data(stdscr, opt) | 795 | return reload_persistent_data(stdscr, opt) |
2622 | 783 | 796 | ||
2623 | 784 | def get_links(filename): | 797 | def get_links(filename): |
2625 | 785 | list = [] | 798 | match_list = [] |
2626 | 786 | with open(filename) as fh: | 799 | with open(filename) as fh: |
2627 | 787 | for line in fh: | 800 | for line in fh: |
2628 | 788 | match = re.search("(http|https|ftp)://[\w\-]+(\.[\w\-]+)+\S*", line) | 801 | match = re.search("(http|https|ftp)://[\w\-]+(\.[\w\-]+)+\S*", line) |
2629 | 789 | if match: | 802 | if match: |
2632 | 790 | list.insert(len(list), match.group()) | 803 | match_list.append(match.group()) |
2633 | 791 | return list | 804 | return match_list |
2634 | 792 | 805 | ||
2635 | 793 | def is_patch(url): | 806 | def is_patch(url): |
2636 | 794 | if re.search("(http|https|ftp)://.*\/(commit|hg\/rev)\/.*", url): | 807 | if re.search("(http|https|ftp)://.*\/(commit|hg\/rev)\/.*", url): |
2637 | @@ -798,12 +811,10 @@ def is_patch(url): | |||
2638 | 798 | 811 | ||
2639 | 799 | def save_patches(filename): | 812 | def save_patches(filename): |
2640 | 800 | cve = os.path.basename(filename) | 813 | cve = os.path.basename(filename) |
2647 | 801 | links = [] | 814 | # * Use set comprehension to eliminate duplicates - creates a set which |
2648 | 802 | for link in get_links(filename): | 815 | # * by definition only contains unique elements, duplicates are discarded |
2649 | 803 | if is_patch(link): | 816 | # * then we just convert back to a list |
2650 | 804 | links.insert(len(links), link) | 817 | links = list({link for link in get_links(filename) if is_patch(link)}) |
2645 | 805 | |||
2646 | 806 | links = list(dict.fromkeys(links)) # Remove duplicates | ||
2651 | 807 | 818 | ||
2652 | 808 | try: | 819 | try: |
2653 | 809 | message = "Saved:" | 820 | message = "Saved:" |
2654 | @@ -811,19 +822,22 @@ def save_patches(filename): | |||
2655 | 811 | link = links[0] | 822 | link = links[0] |
2656 | 812 | link += ".patch" if link[-6:] != ".patch" else "" | 823 | link += ".patch" if link[-6:] != ".patch" else "" |
2657 | 813 | 824 | ||
2660 | 814 | filedata = urllib2.urlopen(link) | 825 | with contextlib.closing(urlopen(link)) as response: |
2661 | 815 | datatowrite = filedata.read() | 826 | filedata = response.read() |
2662 | 827 | # FIXME: Don't write full absolute paths directly to the filesystem | ||
2663 | 828 | # XXX : Use NamedTemporaryFile / mkstemp to generate names | ||
2664 | 816 | tmpfile = '%s.patch' % cve | 829 | tmpfile = '%s.patch' % cve |
2665 | 817 | message += " %s" % tmpfile | 830 | message += " %s" % tmpfile |
2666 | 818 | with open('/tmp/' + tmpfile, 'wb') as f: | 831 | with open('/tmp/' + tmpfile, 'wb') as f: |
2668 | 819 | f.write(datatowrite) | 832 | f.write(filedata) |
2669 | 820 | elif len(links) > 1: | 833 | elif len(links) > 1: |
2673 | 821 | for i in range(0, len(links)): | 834 | for i, link in enumerate(links): |
2674 | 822 | filedata = urllib2.urlopen("%s.patch" % links[i]) | 835 | url = "%s.patch" % link |
2675 | 823 | datatowrite = filedata.read() | 836 | with contextlib.closing(urlopen(url)) as response: |
2676 | 837 | filedata = response.read() | ||
2677 | 824 | tmpfile = '%s-%d.patch' % (cve, i + 1) | 838 | tmpfile = '%s-%d.patch' % (cve, i + 1) |
2678 | 825 | with open('/tmp/' + tmpfile, 'wb') as f: | 839 | with open('/tmp/' + tmpfile, 'wb') as f: |
2680 | 826 | f.write(datatowrite) | 840 | f.write(filedata) |
2681 | 827 | message += " %s" % tmpfile | 841 | message += " %s" % tmpfile |
2682 | 828 | return message | 842 | return message |
2683 | 829 | except: | 843 | except: |
2684 | @@ -832,7 +846,7 @@ def save_patches(filename): | |||
2685 | 832 | def git_filter(filter): | 846 | def git_filter(filter): |
2686 | 833 | returnlist = [] | 847 | returnlist = [] |
2687 | 834 | p = subprocess.Popen(['git', '-C', PATH, 'status', '-s', '.'], | 848 | p = subprocess.Popen(['git', '-C', PATH, 'status', '-s', '.'], |
2689 | 835 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 849 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) |
2690 | 836 | out, err = p.communicate() | 850 | out, err = p.communicate() |
2691 | 837 | for line in out.splitlines(): | 851 | for line in out.splitlines(): |
2692 | 838 | l = line.split() | 852 | l = line.split() |
2693 | @@ -964,6 +978,7 @@ def parse_opts(): | |||
2694 | 964 | return (opt, args) | 978 | return (opt, args) |
2695 | 965 | 979 | ||
2696 | 966 | def main(): | 980 | def main(): |
2697 | 981 | # TODO: Migrate to argparse | ||
2698 | 967 | (opt, args) = parse_opts() | 982 | (opt, args) = parse_opts() |
2699 | 968 | if not os.path.isdir(PATH): | 983 | if not os.path.isdir(PATH): |
2700 | 969 | print("CVEs directory not found (%s)!" % PATH) | 984 | print("CVEs directory not found (%s)!" % PATH) |
2701 | diff --git a/utilities/maildir2mbox.py b/utilities/maildir2mbox.py | |||
2702 | index ef75c99..9abe155 100755 | |||
2703 | --- a/utilities/maildir2mbox.py | |||
2704 | +++ b/utilities/maildir2mbox.py | |||
2705 | @@ -1,4 +1,4 @@ | |||
2707 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
2708 | 2 | # | 2 | # |
2709 | 3 | # Author: Jamie Strandboge <jamie@ubuntu.com> | 3 | # Author: Jamie Strandboge <jamie@ubuntu.com> |
2710 | 4 | # Copyright (C) 2005-2011 Canonical Ltd. | 4 | # Copyright (C) 2005-2011 Canonical Ltd. |
2711 | @@ -11,6 +11,7 @@ | |||
2712 | 11 | # directories. | 11 | # directories. |
2713 | 12 | # | 12 | # |
2714 | 13 | 13 | ||
2715 | 14 | from __future__ import absolute_import, print_function | ||
2716 | 14 | import datetime | 15 | import datetime |
2717 | 15 | import email | 16 | import email |
2718 | 16 | import email.utils | 17 | import email.utils |
2719 | @@ -25,20 +26,20 @@ import tempfile | |||
2720 | 25 | def debug(s): | 26 | def debug(s): |
2721 | 26 | '''Print debug message''' | 27 | '''Print debug message''' |
2722 | 27 | if opt.debug: | 28 | if opt.debug: |
2724 | 28 | print >>sys.stderr, "DEBUG: %s" % (s) | 29 | print("DEBUG: %s" % (s), file=sys.stderr) |
2725 | 29 | 30 | ||
2726 | 30 | def get_date(s): | 31 | def get_date(s): |
2727 | 31 | '''Return a datetime.date object from string''' | 32 | '''Return a datetime.date object from string''' |
2728 | 32 | pat = re.compile(r'^\d\d\d\d-\d\d-\d\d$') | 33 | pat = re.compile(r'^\d\d\d\d-\d\d-\d\d$') |
2729 | 33 | d = None | 34 | d = None |
2730 | 34 | if not pat.match(s): | 35 | if not pat.match(s): |
2732 | 35 | print >>sys.stderr, "date '%s' should be YYYY-MM-DD" % (s) | 36 | print("date '%s' should be YYYY-MM-DD" % (s), file=sys.stderr) |
2733 | 36 | return None | 37 | return None |
2734 | 37 | t = s.split('-') | 38 | t = s.split('-') |
2735 | 38 | try: | 39 | try: |
2736 | 39 | d = datetime.date(int(t[0]), int(t[1]), int(t[2])) | 40 | d = datetime.date(int(t[0]), int(t[1]), int(t[2])) |
2737 | 40 | except: | 41 | except: |
2739 | 41 | print >>sys.stderr, "Invalid date '%s'" % (s) | 42 | print("Invalid date '%s'" % (s), file=sys.stderr) |
2740 | 42 | raise | 43 | raise |
2741 | 43 | 44 | ||
2742 | 44 | return d | 45 | return d |
2743 | @@ -64,16 +65,16 @@ parser.add_option("--end-date", | |||
2744 | 64 | (opt, args) = parser.parse_args() | 65 | (opt, args) = parser.parse_args() |
2745 | 65 | 66 | ||
2746 | 66 | if not opt.folder: | 67 | if not opt.folder: |
2748 | 67 | print >>sys.stderr, "Must specify --folder" | 68 | print("Must specify --folder", file=sys.stderr) |
2749 | 68 | sys.exit(1) | 69 | sys.exit(1) |
2750 | 69 | elif not opt.mbox: | 70 | elif not opt.mbox: |
2752 | 70 | print >>sys.stderr, "Must specify --mbox" | 71 | print("Must specify --mbox", file=sys.stderr) |
2753 | 71 | sys.exit(1) | 72 | sys.exit(1) |
2754 | 72 | elif not os.path.isdir(opt.folder): | 73 | elif not os.path.isdir(opt.folder): |
2756 | 73 | print >>sys.stderr, "'%s' does not exist" % opt.folder | 74 | print("'%s' does not exist" % opt.folder, file=sys.stderr) |
2757 | 74 | sys.exit(1) | 75 | sys.exit(1) |
2758 | 75 | elif os.path.exists(opt.mbox): | 76 | elif os.path.exists(opt.mbox): |
2760 | 76 | print >>sys.stderr, "'%s' already exists" % opt.mbox | 77 | print("'%s' already exists" % opt.mbox, file=sys.stderr) |
2761 | 77 | sys.exit(1) | 78 | sys.exit(1) |
2762 | 78 | 79 | ||
2763 | 79 | start = None | 80 | start = None |
2764 | @@ -114,7 +115,7 @@ for message in src_maildir: | |||
2765 | 114 | debug("Skipping: 'Subject: %s' (%s is after %s)" % (message['subject'], msg_date, start)) | 115 | debug("Skipping: 'Subject: %s' (%s is after %s)" % (message['subject'], msg_date, start)) |
2766 | 115 | continue | 116 | continue |
2767 | 116 | 117 | ||
2769 | 117 | if message.has_key('subject') and message.has_key('date'): | 118 | if 'subject' in message and 'date' in message: |
2770 | 118 | debug("Processing '%s: Subject: %s'" % (message['date'], message['subject'])) | 119 | debug("Processing '%s: Subject: %s'" % (message['date'], message['subject'])) |
2771 | 119 | 120 | ||
2772 | 120 | try: | 121 | try: |
2773 | diff --git a/utilities/mugshot b/utilities/mugshot | |||
2774 | index 9f063ea..55dc6ff 100755 | |||
2775 | --- a/utilities/mugshot | |||
2776 | +++ b/utilities/mugshot | |||
2777 | @@ -1,9 +1,9 @@ | |||
2779 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/env python3 |
2780 | 2 | # Author: Kees Cook <kees@ubuntu.com> | 2 | # Author: Kees Cook <kees@ubuntu.com> |
2781 | 3 | # Copyright (C) 2010 Canonical, Ltd. | 3 | # Copyright (C) 2010 Canonical, Ltd. |
2782 | 4 | # License: GPLv3 | 4 | # License: GPLv3 |
2783 | 5 | 5 | ||
2785 | 6 | from __future__ import print_function | 6 | from __future__ import absolute_import, print_function |
2786 | 7 | import sys | 7 | import sys |
2787 | 8 | import optparse | 8 | import optparse |
2788 | 9 | import httplib2 | 9 | import httplib2 |