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

Contents of /bin/checklist

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.5