/[secure-testing]/bin/checklist
ViewVC logotype

Contents of /bin/checklist

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1767 - (show annotations) (download)
Thu Sep 1 19:34:16 2005 UTC (7 years, 8 months ago) by joeyh
File size: 9429 byte(s)
fix a wrong comment
1 #!/usr/bin/perl
2 # Must run on a machine with madison.
3 #
4 # To check for un-updated binary kernel packages, also needs grep-dctrl
5 # and a Sources file for the distribution. Set the location of the Sources
6 # file in SOURCES_FILE in the environment.
7 use warnings;
8 use strict;
9 use URI::Escape;
10 use Getopt::Long;
11
12 my $html=0;
13 my $debug=0;
14 my $suite="testing";
15 my $sta="http://secure-testing.debian.net/debian-security-updates/dists/testing/security-updates/main/source/Sources.gz";
16 my $output;
17 if (! GetOptions(
18 "html" => \$html,
19 "debug" => \$debug,
20 "suite=s" => \$suite,
21 "sta=s" => \$sta,
22 "output=s", \$output)
23 || ! @ARGV) {
24 die "usage: $0 [--suite suite] [--sta sta-mirror] [--html] [--output=file] [--debug] list ...\n";
25 }
26
27 my $stasources=`tempfile`;
28 chomp $stasources;
29 system("wget -q -O $stasources $sta");
30
31 if (defined $output) {
32 open (OUT, ">$output.tmp.$$") || die "output.tmp.$$: $!"; # Set the output to a file
33 }
34 else {
35 open (OUT, ">&STDOUT"); # Set the output to stdout
36 }
37
38 if ($html) { # It's HTML, so we need a header
39 print OUT "<html><title>$suite security issues</title>\n";
40
41 # This is being run against something it's not meant to be, so print a warning
42 if ($suite ne 'testing' && $suite ne 'unstable') {
43 print OUT <<"EOF";
44 <p>
45 <em>Warning:</em> This page is the result of running the testing security
46 check script against the $suite distribution. As data is only gathered for
47 the testing distribution, results may be innacurate if a package has
48 changed its name, if a vulnerability affects $suite and not testing, or if a
49 vulnerability has been fixed in $suite by the security team.
50 </p>
51 EOF
52 }
53 print OUT "<ul>\n";
54 }
55
56
57 my %data;
58 my %advlist;
59 my %needkernel=qw/2.4.27 0 2.6.11 0/;
60 my $list_unknown=1; #set to 1 to display kernel images with unknown source version
61 my $sources=$ENV{SOURCES_FILE};
62 my $need_rebuild=0;
63
64 # Set some colours for the urgency types
65 my @urgencies=("high", "medium", "low", "unknown");
66 my %colormap=(
67 high => "#FF0000",
68 medium => "#FF9999",
69 low => "#FFFFFF",
70 unknown => "#FFFF00"
71 );
72
73 my $unprop = my $unprop_all = my $unfixed = my $todos = my $fixedsta = 0;
74
75 # Add an item into the data array.
76 sub record {
77 my ($package, $condition, $item, $urgency)=@_;
78
79 if ($html) {
80 $condition=~s{bug #(\d+)}{<a href="http://bugs.debian.org/$1">bug #$1</a>}g;
81 $condition=~s{unfixed}{<b>unfixed</b>}g;
82 $item=~s#((?:CAN|CVE)-\d+-\d+)#<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=$1">$1</a>#g;
83 }
84
85 push @{$data{$package}{$condition}}, {item => $item, urgency => $urgency};
86 }
87
88 foreach my $list (@ARGV) {
89 # Each of the @ARGVs we've got passed need parsing. So lets do that
90
91 # If it's a directory, set the file to list, cause we need that.
92 if (-d $list) {
93 $list="$list/list";
94 }
95
96 open (IN, $list) || die "open $list: $!";
97 while (<IN>) {
98 my $id;
99 print STDERR "line: $_" if $debug;
100 chomp;
101 if (/\s+TODO/) { # It's a todo item. Add it to the count, and ignore it
102 $todos++;
103 }
104 elsif (/^\[/) { # Checking adv. number for a line starting with [ : Set $id to it
105 ($id)=m/((?:DSA|DTSA|CAN|CVE)-[^\s]+) /;
106 }
107 elsif (/^((?:DSA|DTSA|CAN|CVE)-[^\s]+)/) { # Check for a line with an advisory at the start : Set $id to it
108 $id=$1;
109 }
110 elsif (/^\s+[!-]\s+(\S+)\s+(.*?)\s*$/) { # Deal with the rest of the lines
111 my $package=$1; # We know which package it is.
112 my $rest=$2;
113 my $version;
114 my $notes;
115 if ($rest=~/([^\(\s]+)\s+\((.*)\)/) {
116 $version=$1;
117 $notes=$2;
118 }
119 elsif ($rest=~/\((.*)\)/) {
120 $version="";
121 $notes=$1;
122 }
123 else {
124 $version=$rest;
125 $notes="";
126 }
127
128 # by now, we also have the version that's affected by the security problem.
129 # This is stored in $version
130
131 my @notes=split(/\s*;\s+/, $notes);
132
133 # Fetch the urgency, if we can.
134 my $urgency="unknown";
135 foreach my $u (@urgencies) {
136 if (grep { $_ eq $u } @notes) {
137 $urgency=$u;
138 @notes = grep { $_ ne $u } @notes;
139 last;
140 }
141 }
142
143 # It's a kernel. Add it to the list of kernels that need to be looked at.
144 if ($package=~/kernel-source-([0-9.]+)/) {
145 my $kernversion=$1;
146 if (exists $needkernel{$kernversion} &&
147 length $version &&
148 system("dpkg --compare-versions $needkernel{$kernversion} lt $version") != 0) {
149 $needkernel{$kernversion}=$version;
150 }
151 }
152
153 # Fire up madison.
154 my @maddy;
155 for (1..5) {
156 @maddy=`madison -s '$suite' '$package'`;
157 if ($? & 127 || ($? >> 8 != 0 && $? >> 8 != 1)) {
158 # good old unrelaible newraff,
159 # home of our archive..
160 next;
161 }
162 last;
163 }
164 if ($? & 127) {
165 record($package, "<em>[madison segfaulted 5 times in a row.. Medic!]</em>", $id);
166 }
167 elsif ($? >> 8 != 0 && $? >> 8 != 1) {
168 record($package, "<em>[madison exited with ".($? >> 8)."]</em>", $id);
169 }
170 if (! @maddy) {
171 next;
172 }
173
174 if (grep { $_ eq 'unfixed' || $_ eq 'pending' } @notes) {
175 record($package, '('.join("; ", @notes).')', $id, $urgency);
176 $unfixed++;
177 # It's not been fixed!
178 }
179 else {
180 foreach my $maddy (@maddy) {
181 my @fields = split(/\s*\|\s*/, $maddy);
182 my $havver=$fields[1]; # It's this version in the archive I'm checking.
183 my $arches=$fields[3];
184 $version=~s/\s+//; # strip whitespace
185 $arches=~s/\s+$//;
186 # Is the version in the archive the same or newer than the fix?
187 my $cmp=system("dpkg --compare-versions '$havver' '>=' '$version'");
188 if ($cmp != 0){ # No, so the archive is vulnerable.
189 my $starchive = "";
190
191 # Does the version exist in the secure-testing archive?
192 my $staversion = `zcat $stasources |grep-dctrl -F Package -e ^$package\$ -s Version -`;
193 chomp $staversion;
194 $staversion=~s/Version: //;
195 $staversion=~s/\s+//;
196 if (length ($staversion)) {
197 # Yes, but what version is in s-t?
198 my $stacmp = system("dpkg --compare-versions '$staversion' '>=' '$version'");
199 if ($stacmp == 0){
200 # Well, the version in the s-t archive fixes the issue
201 # but it's still vulnerable in the main archive
202 $starchive = " (fixed in $staversion in the secure-testing archive)";
203 $fixedsta++;
204 }
205 }
206
207 if ($html && $suite eq 'testing') {
208 $havver='<a href="http://bjorn.haxx.se/debian/testing.pl?package='.uri_escape($package).'">'.$havver.'</a>';
209 }
210 record($package, "$version needed, have $havver".(@maddy > 1 ? " [$arches]" : "").$starchive, $id, $urgency);
211 $unprop++;
212 $unprop_all++ unless @maddy > 1;
213 }
214 }
215 }
216 }
217 }
218 }
219
220
221 foreach my $package (sort keys %data) {
222 foreach my $condition (sort keys %{$data{$package}}) {
223 print OUT "<li>" if $html;
224 print OUT "$package $condition for ";
225 my $items=0;
226 foreach my $i (sort @{$data{$package}{$condition}}) {
227 print OUT ", " if $items > 0;
228
229 if ($html) {
230 my $color=$colormap{$i->{urgency}};
231 print OUT "<span style=\"background:$color\">";
232 }
233 print OUT $i->{item};
234 if ($html) {
235 print OUT "</span>";
236 }
237
238 $items++;
239 }
240 print OUT "\n";
241 }
242 }
243
244 my %needkern;
245
246 foreach my $version (sort keys %needkernel) {
247 my %images;
248
249 if ($needkern{$version} eq "0") {
250 next;
251 }
252
253 my @dctrl;
254 if (defined $sources && length $sources) {
255 my $cat=($sources=~/\.gz/) ? "zcat" : "cat";
256 @dctrl=`$cat $sources | grep-dctrl -F Binary kernel-image-$version -s Package,Build-Depends -`;
257 }
258
259 my $package="";
260 my $haveversion;
261
262 foreach my $line (@dctrl) {
263 chomp;
264 if ($line=~/Package:\s*(\S+)/) {
265 $package=$1;
266 $haveversion="0";
267 } elsif ($line=~/Build-Depends/) {
268 if ($line=~/kernel-tree-$version-([^,\s]+)/) {
269 $haveversion="$version-$1";
270 } elsif ($line=~/kernel-source-$version\s+\(>?=\s*([^\s\)]+)\)/) {
271 $haveversion="$1";
272 }
273 } else {
274 if ($package=~/linux-kernel-di/ || $package eq "") {
275 next;
276 }
277 $images{$package}=$haveversion;
278 $package="";
279 }
280 }
281
282 foreach my $package (sort keys %images) {
283 if ($images{$package} eq "0") {
284 print OUT "<li>" if ($html && $list_unknown);
285 print OUT "$package built from kernel-source-$version $needkernel{$version} needed, current version unknown\n" if $list_unknown;
286 } elsif (!system("dpkg --compare-versions $needkernel{$version} gt $images{$package}")) {
287 print OUT "<li>" if $html;
288 print OUT "$package built from kernel-source-$version $needkernel{$version} needed, have $images{$package}\n";
289 $need_rebuild++;
290 }
291 }
292
293
294 }
295
296
297 if ($html) {
298 print OUT "</ul>\n";
299 print OUT "<hr>\n";
300 print OUT "Key: ";
301 foreach my $keyline (@urgencies) {
302 print OUT "<span style=\"border: 1px dashed; background:".$colormap{$keyline}."\">&nbsp;$keyline&nbsp;</span> ";
303 }
304 print OUT "<br>";
305 print OUT "Total holes unfixed: $unfixed<br>\n";
306 print OUT "Total holes fixed in unstable but not $suite: $unprop_all ($fixedsta fixed in secure-testing archive)";
307 if ($unprop_all != $unprop) {
308 print OUT " (+".($unprop - $unprop_all)." on some arches)";
309 }
310 print OUT "<br>\n";
311 print OUT "Total number of kernel image packages not up to date: $need_rebuild<br>\n";
312 print OUT "Number of TODO lines in <a href=\"http://svn.debian.org/wsvn/secure-testing/data/?rev=0&sc=0\">records</a>: $todos<br>\n";
313 print OUT "Maintained by the <a href=\"http://secure-testing.debian.net/\">testing security team</a><br>\n";
314 print OUT "Last update: ".`date`."<br>\n";
315 print OUT "</html>\n";
316 }
317
318 close OUT;
319 if (defined $output) {
320 rename("$output.tmp.$$", $output) || die "rename: $!";
321 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5