3 # Wrapper for Debian Security team
4 # Copyright (C) 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 ################################################################################
23 # <aj> neuro: <usual question>?
24 # <neuro> aj: PPG: the movie! july 3!
26 # <aj> (you think you can distract me, and you're right)
31 ################################################################################
33 import commands, os, pwd, re, sys, time
38 ################################################################################
44 re_taint_free = re.compile(r"^['/;\-\+\.\s\w]+$")
46 ################################################################################
48 def usage (exit_code=0):
49 print """Usage: dak security-install ADV_NUMBER CHANGES_FILE[...]
50 Install CHANGES_FILE(s) as security advisory ADV_NUMBER
52 -h, --help show this help and exit
53 -n, --no-action don't do anything
58 ################################################################################
60 def do_upload(changes_files):
63 component_mapping = {}
64 for component in Cnf.SubTree("Security-Install::ComponentMappings").List():
65 component_mapping[component] = Cnf["Security-Install::ComponentMappings::%s" % (component)]
66 uploads = {}; # uploads[uri] = file_list
67 changesfiles = {}; # changesfiles[uri] = file_list
68 package_list = {} # package_list[source_name][version]
69 changes_files.sort(daklib.utils.changes_compare)
70 for changes_file in changes_files:
71 changes_file = daklib.utils.validate_changes_file_arg(changes_file)
77 # Parse the .dak file for the .changes file
78 Upload.pkg.changes_file = changes_file
80 files = Upload.pkg.files
81 changes = Upload.pkg.changes
83 # We have the changes, now return if its amd64, to not upload them to ftp-master
84 if changes["architecture"].has_key("amd64"):
85 print "Not uploading amd64 part to ftp-master\n"
87 # Build the file list for this .changes file
88 for file in files.keys():
89 poolname = os.path.join(Cnf["Dir::Root"], Cnf["Dir::PoolRoot"],
90 daklib.utils.poolify(changes["source"], files[file]["component"]),
92 file_list.append(poolname)
93 orig_component = files[file].get("original component", files[file]["component"])
94 components[orig_component] = ""
95 # Determine the upload uri for this .changes file
96 for component in components.keys():
97 upload_uri = component_mapping.get(component)
99 upload_uris[upload_uri] = ""
100 num_upload_uris = len(upload_uris.keys())
101 if num_upload_uris == 0:
102 daklib.utils.fubar("%s: No valid upload URI found from components (%s)."
103 % (changes_file, ", ".join(components.keys())))
104 elif num_upload_uris > 1:
105 daklib.utils.fubar("%s: more than one upload URI (%s) from components (%s)."
106 % (changes_file, ", ".join(upload_uris.keys()),
107 ", ".join(components.keys())))
108 upload_uri = upload_uris.keys()[0]
109 # Update the file list for the upload uri
110 if not uploads.has_key(upload_uri):
111 uploads[upload_uri] = []
112 uploads[upload_uri].extend(file_list)
113 # Update the changes list for the upload uri
114 if not changesfiles.has_key(upload_uri):
115 changesfiles[upload_uri] = []
116 changesfiles[upload_uri].append(changes_file)
117 # Remember the suites and source name/version
118 for suite in changes["distribution"].keys():
120 # Remember the source name and version
121 if changes["architecture"].has_key("source") and \
122 changes["distribution"].has_key("testing"):
123 if not package_list.has_key(dsc["source"]):
124 package_list[dsc["source"]] = {}
125 package_list[dsc["source"]][dsc["version"]] = ""
127 if not Options["No-Action"]:
128 answer = yes_no("Upload to files to main archive (Y/n)?")
132 for uri in uploads.keys():
133 uploads[uri].extend(changesfiles[uri])
134 (host, path) = uri.split(":")
135 file_list = " ".join(uploads[uri])
136 print "Uploading files to %s..." % (host)
137 spawn("lftp -c 'open %s; cd %s; put %s'" % (host, path, file_list))
139 if not Options["No-Action"]:
140 filename = "%s/testing-processed" % (Cnf["Dir::Log"])
141 file = daklib.utils.open_file(filename, 'a')
142 for source in package_list.keys():
143 for version in package_list[source].keys():
144 file.write(" ".join([source, version])+'\n')
147 ######################################################################
148 # This function was originally written by aj and NIHishly merged into
149 # 'dak security-install' by me.
151 def make_advisory(advisory_nr, changes_files):
153 updated_pkgs = {}; # updated_pkgs[distro][arch][file] = {path,md5,size}
155 for arg in changes_files:
156 arg = daklib.utils.validate_changes_file_arg(arg)
157 Upload.pkg.changes_file = arg
161 src = Upload.pkg.changes["source"]
162 if src not in adv_packages:
163 adv_packages += [src]
165 suites = Upload.pkg.changes["distribution"].keys()
167 if not updated_pkgs.has_key(suite):
168 updated_pkgs[suite] = {}
170 files = Upload.pkg.files
171 for file in files.keys():
172 arch = files[file]["architecture"]
173 md5 = files[file]["md5sum"]
174 size = files[file]["size"]
175 poolname = Cnf["Dir::PoolRoot"] + \
176 daklib.utils.poolify(src, files[file]["component"])
177 if arch == "source" and file.endswith(".dsc"):
178 dscpoolname = poolname
180 if not updated_pkgs[suite].has_key(arch):
181 updated_pkgs[suite][arch] = {}
182 updated_pkgs[suite][arch][file] = {
183 "md5": md5, "size": size,
184 "poolname": poolname }
186 dsc_files = Upload.pkg.dsc_files
187 for file in dsc_files.keys():
189 if not dsc_files[file].has_key("files id"):
192 # otherwise, it's already in the pool and needs to be
194 md5 = dsc_files[file]["md5sum"]
195 size = dsc_files[file]["size"]
197 if not updated_pkgs[suite].has_key(arch):
198 updated_pkgs[suite][arch] = {}
199 updated_pkgs[suite][arch][file] = {
200 "md5": md5, "size": size,
201 "poolname": dscpoolname }
203 if os.environ.has_key("SUDO_UID"):
204 whoami = long(os.environ["SUDO_UID"])
207 whoamifull = pwd.getpwuid(whoami)
208 username = whoamifull[4].split(",")[0]
211 "__ADVISORY__": advisory_nr,
212 "__WHOAMI__": username,
213 "__DATE__": time.strftime("%B %d, %Y", time.gmtime(time.time())),
214 "__PACKAGE__": ", ".join(adv_packages),
215 "__DAK_ADDRESS__": Cnf["Dinstall::MyEmailAddress"]
218 if Cnf.has_key("Dinstall::Bcc"):
219 Subst["__BCC__"] = "Bcc: %s" % (Cnf["Dinstall::Bcc"])
222 archive = Cnf["Archive::%s::PrimaryMirror" % (daklib.utils.where_am_i())]
223 for suite in updated_pkgs.keys():
224 suite_header = "%s %s (%s)" % (Cnf["Dinstall::MyDistribution"],
225 Cnf["Suite::%s::Version" % suite], suite)
226 adv += "%s\n%s\n\n" % (suite_header, "-"*len(suite_header))
228 arches = Cnf.ValueList("Suite::%s::Architectures" % suite)
229 if "source" in arches:
230 arches.remove("source")
235 adv += " %s was released for %s.\n\n" % (
236 suite.capitalize(), daklib.utils.join_with_commas_and(arches))
238 for a in ["source", "all"] + arches:
239 if not updated_pkgs[suite].has_key(a):
243 adv += " Source archives:\n\n"
245 adv += " Architecture independent packages:\n\n"
247 adv += " %s architecture (%s)\n\n" % (a,
248 Cnf["Architectures::%s" % a])
250 for file in updated_pkgs[suite][a].keys():
251 adv += " http://%s/%s%s\n" % (
252 archive, updated_pkgs[suite][a][file]["poolname"], file)
253 adv += " Size/MD5 checksum: %8s %s\n" % (
254 updated_pkgs[suite][a][file]["size"],
255 updated_pkgs[suite][a][file]["md5"])
259 Subst["__ADVISORY_TEXT__"] = adv
261 adv = daklib.utils.TemplateSubst(Subst, Cnf["Dir::Templates"]+"/security-install.advisory")
262 if not Options["No-Action"]:
263 daklib.utils.send_mail (adv)
265 print "[<Would send template advisory mail>]"
267 ######################################################################
270 global Cnf, Upload, Options
273 Cnf = daklib.utils.get_conf()
275 Arguments = [('h', "help", "Security-Install::Options::Help"),
276 ('n', "no-action", "Security-Install::Options::No-Action")]
278 for i in [ "help", "no-action" ]:
279 Cnf["Security-Install::Options::%s" % (i)] = ""
281 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
282 Options = Cnf.SubTree("Security-Install::Options")
283 Upload = daklib.queue.Upload(Cnf)
291 advisory_number = arguments[0]
292 changes_files = arguments[1:]
293 if advisory_number.endswith(".changes"):
294 daklib.utils.warn("first argument must be the advisory number.")
296 for file in changes_files:
297 file = daklib.utils.validate_changes_file_arg(file)
298 return (advisory_number, changes_files)
300 ######################################################################
304 answer = daklib.utils.our_raw_input(prompt+" ").lower()
305 if answer == "y" or answer == "n":
308 print "Invalid answer; please try again."
311 ######################################################################
314 if not re_taint_free.match(command):
315 daklib.utils.fubar("Invalid character in \"%s\"." % (command))
317 if Options["No-Action"]:
318 print "[%s]" % (command)
320 (result, output) = commands.getstatusoutput(command)
322 daklib.utils.fubar("Invocation of '%s' failed:\n%s\n" % (command, output), result)
324 ######################################################################
328 print "Disabled. See your team@security email, and/or contact aj on OFTC."
331 (advisory_number, changes_files) = init()
333 if not Options["No-Action"]:
334 print "About to install the following files: "
335 for file in changes_files:
337 answer = yes_no("Continue (Y/n)?")
341 os.chdir(Cnf["Dir::Queue::Accepted"])
342 print "Installing packages into the archive..."
343 spawn("dak process-accepted -pa %s" % (" ".join(changes_files)))
344 os.chdir(Cnf["Dir::Dak"])
345 print "Updating file lists for apt-ftparchive..."
346 spawn("dak make-suite-file-list")
347 print "Updating Packages and Sources files..."
348 spawn("apt-ftparchive generate %s" % (daklib.utils.which_apt_conf_file()))
349 print "Updating Release files..."
350 spawn("dak generate-releases")
352 if not Options["No-Action"]:
353 os.chdir(Cnf["Dir::Queue::Done"])
355 os.chdir(Cnf["Dir::Queue::Accepted"])
356 print "Generating template advisory..."
357 make_advisory(advisory_number, changes_files)
359 # Trigger security mirrors
360 spawn("sudo -u archvsync /home/archvsync/signal_security")
362 do_upload(changes_files)
364 ################################################################################
366 if __name__ == '__main__':
369 ################################################################################