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

Contents of /bin/checklist

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1766 - (hide annotations) (download)
Thu Sep 1 19:31:46 2005 UTC (7 years, 9 months ago) by joeyh
File size: 9447 byte(s)
remove /tmp race
1 joeyh 2 #!/usr/bin/perl
2     # Must run on a machine with madison.
3 joeyh 644 #
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 joeyh 1765 use warnings;
8     use strict;
9 joeyh 256 use URI::Escape;
10 joeyh 1278 use Getopt::Long;
11 joeyh 2
12 joeyh 230 my $html=0;
13 joeyh 1280 my $debug=0;
14 joeyh 1281 my $suite="testing";
15 joeyh 1766 my $sta="http://secure-testing.debian.net/debian-security-updates/dists/testing/security-updates/main/source/Sources.gz";
16 joeyh 1279 my $output;
17     if (! GetOptions(
18     "html" => \$html,
19 joeyh 1280 "debug" => \$debug,
20 joeyh 1279 "suite=s" => \$suite,
21 neilm 1763 "sta=s" => \$sta,
22 joeyh 1279 "output=s", \$output)
23     || ! @ARGV) {
24 neilm 1763 die "usage: $0 [--suite suite] [--sta sta-mirror] [--html] [--output=file] [--debug] list ...\n";
25 joeyh 230 }
26    
27 joeyh 1766 my $stasources=`tempfile`;
28     chomp $stasources;
29     system("wget -q -O $stasources $sta");
30 neilm 1763
31 joeyh 1279 if (defined $output) {
32 neilm 1763 open (OUT, ">$output.tmp.$$") || die "output.tmp.$$: $!"; # Set the output to a file
33 joeyh 1279 }
34     else {
35 neilm 1763 open (OUT, ">&STDOUT"); # Set the output to stdout
36 joeyh 1279 }
37    
38 neilm 1763 if ($html) { # It's HTML, so we need a header
39 joeyh 1279 print OUT "<html><title>$suite security issues</title>\n";
40 neilm 1763
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 joeyh 1279 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 joeyh 1285 the testing distribution, results may be innacurate if a package has
48 joeyh 1279 changed its name, if a vulnerability affects $suite and not testing, or if a
49     vulnerability has been fixed in $suite by the $suite security team.
50     </p>
51     EOF
52     }
53     print OUT "<ul>\n";
54     }
55    
56    
57 joeyh 307 my %data;
58 neilm 1763 my %advlist;
59 joeyh 1222 my %needkernel=qw/2.4.27 0 2.6.11 0/;
60 stef-guest 688 my $list_unknown=1; #set to 1 to display kernel images with unknown source version
61 joeyh 644 my $sources=$ENV{SOURCES_FILE};
62     my $need_rebuild=0;
63    
64 neilm 1763 # Set some colours for the urgency types
65 joeyh 1243 my @urgencies=("high", "medium", "low", "unknown");
66     my %colormap=(
67     high => "#FF0000",
68     medium => "#FF9999",
69     low => "#FFFFFF",
70 joeyh 1246 unknown => "#FFFF00"
71 joeyh 1243 );
72    
73 neilm 1763 my $unprop = my $unprop_all = my $unfixed = my $todos = my $fixedsta = 0;
74 joeyh 307
75 neilm 1763 # Add an item into the data array.
76 joeyh 307 sub record {
77 joeyh 1242 my ($package, $condition, $item, $urgency)=@_;
78 joeyh 307
79 joeyh 231 if ($html) {
80 joeyh 307 $condition=~s{bug #(\d+)}{<a href="http://bugs.debian.org/$1">bug #$1</a>}g;
81 joeyh 311 $condition=~s{unfixed}{<b>unfixed</b>}g;
82 joeyh 307 $item=~s#((?:CAN|CVE)-\d+-\d+)#<a href="http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=$1">$1</a>#g;
83 joeyh 231 }
84 joeyh 307
85 joeyh 1242 push @{$data{$package}{$condition}}, {item => $item, urgency => $urgency};
86 joeyh 230 }
87    
88 neilm 1763 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 joeyh 31 if (-d $list) {
93     $list="$list/list";
94 joeyh 2 }
95 joeyh 31
96     open (IN, $list) || die "open $list: $!";
97     while (<IN>) {
98 joeyh 1765 my $id;
99 joeyh 1280 print STDERR "line: $_" if $debug;
100 joeyh 31 chomp;
101 neilm 1763 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 joeyh 1660 ($id)=m/((?:DSA|DTSA|CAN|CVE)-[^\s]+) /;
106 joeyh 2 }
107 neilm 1763 elsif (/^((?:DSA|DTSA|CAN|CVE)-[^\s]+)/) { # Check for a line with an advisory at the start : Set $id to it
108 joeyh 242 $id=$1;
109 joeyh 31 }
110 neilm 1763 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 joeyh 1242 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 neilm 1763
128     # by now, we also have the version that's affected by the security problem.
129     # This is stored in $version
130    
131 joeyh 1242 my @notes=split(/\s*;\s+/, $notes);
132    
133 neilm 1763 # Fetch the urgency, if we can.
134 joeyh 1242 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 neilm 1763
143     # It's a kernel. Add it to the list of kernels that need to be looked at.
144 joeyh 644 if ($package=~/kernel-source-([0-9.]+)/) {
145     my $kernversion=$1;
146 joeyh 1283 if (exists $needkernel{$kernversion} &&
147     length $version &&
148     system("dpkg --compare-versions $needkernel{$kernversion} lt $version") != 0) {
149     $needkernel{$kernversion}=$version;
150 joeyh 644 }
151     }
152    
153 neilm 1763 # Fire up madison.
154 joeyh 657 my @maddy;
155     for (1..5) {
156 joeyh 1278 @maddy=`madison -s '$suite' '$package'`;
157 joeyh 659 if ($? & 127 || ($? >> 8 != 0 && $? >> 8 != 1)) {
158     # good old unrelaible newraff,
159     # home of our archive..
160 joeyh 657 next;
161     }
162     last;
163     }
164 joeyh 654 if ($? & 127) {
165 joeyh 657 record($package, "<em>[madison segfaulted 5 times in a row.. Medic!]</em>", $id);
166 joeyh 564 }
167     elsif ($? >> 8 != 0 && $? >> 8 != 1) {
168 joeyh 654 record($package, "<em>[madison exited with ".($? >> 8)."]</em>", $id);
169 joeyh 564 }
170 joeyh 657 if (! @maddy) {
171 joeyh 307 next;
172     }
173 joeyh 241
174 joeyh 1242 if (grep { $_ eq 'unfixed' || $_ eq 'pending' } @notes) {
175 joeyh 1244 record($package, '('.join("; ", @notes).')', $id, $urgency);
176 joeyh 257 $unfixed++;
177 neilm 1763 # It's not been fixed!
178 joeyh 2 }
179 joeyh 241 else {
180 joeyh 657 foreach my $maddy (@maddy) {
181     my @fields = split(/\s*\|\s*/, $maddy);
182 neilm 1763 my $havver=$fields[1]; # It's this version in the archive I'm checking.
183 joeyh 657 my $arches=$fields[3];
184     $version=~s/\s+//; # strip whitespace
185     $arches=~s/\s+$//;
186 neilm 1763 # Is the version in the archive greater than the version that's vulnerable?
187     my $cmp=system("dpkg --compare-versions '$havver' '>=' '$version'");
188     if ($cmp != 0){ # No, so the archive is vulnerable.
189 joeyh 1766 my $starchive = "";
190 neilm 1763
191     # Does the version exist in the secure-testing archive?
192 joeyh 1766 my $staversion = `zcat $stasources |grep-dctrl -F Package -e ^$package\$ -s Version -`;
193 neilm 1763 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 neilm 1750 }
206 neilm 1763
207 joeyh 1278 if ($html && $suite eq 'testing') {
208 joeyh 657 $havver='<a href="http://bjorn.haxx.se/debian/testing.pl?package='.uri_escape($package).'">'.$havver.'</a>';
209     }
210 neilm 1763 record($package, "$version needed, have $havver".(@maddy > 1 ? " [$arches]" : "").$starchive, $id, $urgency);
211 joeyh 657 $unprop++;
212 joeyh 735 $unprop_all++ unless @maddy > 1;
213 joeyh 230 }
214 joeyh 31 }
215     }
216 joeyh 2 }
217     }
218     }
219 joeyh 230
220 joeyh 307
221     foreach my $package (sort keys %data) {
222     foreach my $condition (sort keys %{$data{$package}}) {
223 joeyh 1279 print OUT "<li>" if $html;
224     print OUT "$package $condition for ";
225 joeyh 307 my $items=0;
226 joeyh 1242 foreach my $i (sort @{$data{$package}{$condition}}) {
227 joeyh 1279 print OUT ", " if $items > 0;
228 joeyh 1242
229     if ($html) {
230 joeyh 1243 my $color=$colormap{$i->{urgency}};
231 joeyh 1279 print OUT "<span style=\"background:$color\">";
232 joeyh 1242 }
233 joeyh 1279 print OUT $i->{item};
234 joeyh 1243 if ($html) {
235 joeyh 1279 print OUT "</span>";
236 joeyh 1243 }
237 joeyh 1242
238 joeyh 307 $items++;
239     }
240 joeyh 1279 print OUT "\n";
241 joeyh 307 }
242     }
243    
244 joeyh 1765 my %needkern;
245    
246 joeyh 644 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 joeyh 645 my $cat=($sources=~/\.gz/) ? "zcat" : "cat";
256     @dctrl=`$cat $sources | grep-dctrl -F Binary kernel-image-$version -s Package,Build-Depends -`;
257 joeyh 644 }
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 stef-guest 687 } elsif ($line=~/kernel-source-$version\s+\(>?=\s*([^\s\)]+)\)/) {
271 joeyh 644 $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 joeyh 1765 foreach my $package (sort keys %images) {
283 joeyh 644 if ($images{$package} eq "0") {
284 joeyh 1279 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 joeyh 644 } elsif (!system("dpkg --compare-versions $needkernel{$version} gt $images{$package}")) {
287 joeyh 1279 print OUT "<li>" if $html;
288     print OUT "$package built from kernel-source-$version $needkernel{$version} needed, have $images{$package}\n";
289 joeyh 644 $need_rebuild++;
290     }
291     }
292    
293    
294     }
295    
296    
297 joeyh 307 if ($html) {
298 joeyh 1279 print OUT "</ul>\n";
299     print OUT "<hr>\n";
300 neilm 1763 print OUT "Key: ";
301 joeyh 1765 foreach my $keyline (@urgencies) {
302 neilm 1763 print OUT "<span style=\"border: 1px dashed; background:".$colormap{$keyline}."\">&nbsp;$keyline&nbsp;</span> ";
303     }
304     print OUT "<br>";
305 joeyh 1279 print OUT "Total holes unfixed: $unfixed<br>\n";
306 neilm 1763 print OUT "Total holes fixed in unstable but not $suite: $unprop_all ($fixedsta fixed in secure-testing archive)";
307 joeyh 735 if ($unprop_all != $unprop) {
308 joeyh 1279 print OUT " (+".($unprop - $unprop_all)." on some arches)";
309 joeyh 735 }
310 joeyh 1279 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 joeyh 1659 print OUT "Maintained by the <a href=\"http://secure-testing.debian.net/\">testing security team</a><br>\n";
314 joeyh 1279 print OUT "Last update: ".`date`."<br>\n";
315     print OUT "</html>\n";
316 joeyh 230 }
317 joeyh 1279
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