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

Contents of /bin/checklist

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5