Author: djpig
Date: 2008-04-30 23:03:19 +0200 (Wed, 30 Apr 2008)
New Revision: 1286

Modified:
   trunk/checks/lintian.desc
   trunk/debian/changelog
   trunk/debian/control
   trunk/frontend/lintian
   trunk/lib/Util.pm
Log:
* checks/lintian.desc:
  + Rename md5sum-mismatch-in-changes-file to
    checksum-mismatch-in-changes-file.
* debian/control:
  + Add dependency on libdigest-sha-perl.
* frontend/lintian:
  + Support Checksums-* fields in .changes files. Follows
    the same rules as the md5sum check. Add new option --checksums
    as alias for --md5sums.  (Closes: #476565)
* lib/Util.pm:
  + Rename function get_file_md5sum to get_file_checksum and
    support SHA1 and SHA256.


Modified: trunk/checks/lintian.desc
===================================================================
--- trunk/checks/lintian.desc   2008-04-29 00:52:38 UTC (rev 1285)
+++ trunk/checks/lintian.desc   2008-04-30 21:03:19 UTC (rev 1286)
@@ -47,9 +47,9 @@
 Info: The actual file size does not match what's listed in the
  <tt>.changes</tt> file.
 
-Tag: md5sum-mismatch-in-changes-file
+Tag: checksum-mismatch-in-changes-file
 Type: error
-Info: The actual md5sum checksum does not match what's listed in the
+Info: The actual checksum does not match what's listed in the
  <tt>.changes</tt> file.
 
 Tag: bad-section-in-changes-file

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog      2008-04-29 00:52:38 UTC (rev 1285)
+++ trunk/debian/changelog      2008-04-30 21:03:19 UTC (rev 1286)
@@ -42,6 +42,9 @@
       Josselin Mouette.  (Closes: #473428)
     + [RA] Ignore extra license files in examples subdirectories of
       /usr/share/doc.  Thanks, Daniel Jacobowitz.  (Closes: #476149)
+  * checks/lintian.desc:
+    + [FL] Rename md5sum-mismatch-in-changes-file to
+      checksum-mismatch-in-changes-file.
   * checks/nmu{.desc,}:
     + [RA] Add support for +nmuX versioning for NMUs of native packages.
       Patch from James Vega.  (Closes: #475026)
@@ -74,15 +77,24 @@
   * data/shared-libs/ldconfig-dirs:
     + [RA] New file listing directories searched by ld.so.
 
+  * debian/control:
+    + [FL] Add dependency on libdigest-sha-perl.
+
   * frontend/lintian:
     + [RA] Qualify relative --root directories so that we don't break
       later.  Patch from HÃ¥kon Stordahl.  (Closes: #469925)
     + [CW] Add intrepid as an allowable distribution for Ubuntu.
+    + [FL] Support Checksums-* fields in .changes files. Follows
+      the same rules as the md5sum check. Add new option --checksums
+      as alias for --md5sums.  (Closes: #476565)
 
   * lib/Spelling.pm:
     + [RA] Avoid Perl warnings when called with an uninitialized value.
     + [RA] Correct "meta package" and "meta-package" in descriptions to
       "metapackage".  Thanks, Frank S. Thomas.  (Closes: #476681)
+  * lib/Util.pm:
+    + [FL] Rename function get_file_md5sum to get_file_checksum and
+      support SHA1 and SHA256.
 
   * man/lintian.1:
     + [FL] Drop linda from SEE ALSO since it is obsolete now. Suggested
@@ -111,7 +123,7 @@
     + [RA] Extract a tar listing with numeric owners and groups into
       index-owner-id in the lab.
 
- -- Frank Lichtenheld <[EMAIL PROTECTED]>  Thu, 17 Apr 2008 21:52:27 +0200
+ -- Frank Lichtenheld <[EMAIL PROTECTED]>  Wed, 30 Apr 2008 22:55:20 +0200
 
 lintian (1.23.46) unstable; urgency=low
 

Modified: trunk/debian/control
===================================================================
--- trunk/debian/control        2008-04-29 00:52:38 UTC (rev 1285)
+++ trunk/debian/control        2008-04-30 21:03:19 UTC (rev 1286)
@@ -17,7 +17,8 @@
 Architecture: all
 Depends: perl, libdigest-md5-perl | perl (>> 5.8), dpkg-dev (>= 1.13.17),
  file, binutils, diffstat (>= 1.27-1), man-db (>= 2.3.20-1), gettext (>= 0.16),
- intltool-debian, libparse-debianchangelog-perl (>= 0.6), liburi-perl
+ intltool-debian, libparse-debianchangelog-perl (>= 0.6), liburi-perl,
+ libdigest-sha-perl
 Suggests: binutils-multiarch, libtext-template-perl, man-db (>= 2.5.1-1)
 Description: Debian package checker
  Lintian dissects Debian packages and reports bugs and policy

Modified: trunk/frontend/lintian
===================================================================
--- trunk/frontend/lintian      2008-04-29 00:52:38 UTC (rev 1285)
+++ trunk/frontend/lintian      2008-04-30 21:03:19 UTC (rev 1286)
@@ -54,7 +54,7 @@
 our $no_override = 0;          #flag for -o|--no-override switch
 our $show_overrides = 0;       #flag for --show-overrides switch
 our $color = 'never';          #flag for --color switch
-my $check_md5sums = 0;         #flag for -m|--md5sums switch
+my $check_checksums = 0;       #flag for -m|--md5sums|--checksums switch
 my $allow_root = 0;            #flag for --allow-root swtich
 my $fail_on_warnings = 0;       #flag for --fail-on-warnings switch
 my $packages_file = 0;         #string for the -p option
@@ -143,7 +143,7 @@
     --show-overrides          output tags that have been overriden
     --color never/always/auto disable, enable, or enable color for TTY
     -U X, --unpack-info X     specify which info should be collected
-    -m, --md5sums             check md5sums when processing a .changes file
+    -m, --md5sums, --checksums check checksums when processing a .changes file
     --allow-root              suppress lintian\'s warning when run as root
     --fail-on-warnings        return a non-zero exit status if warnings found
 Configuration options:
@@ -261,7 +261,7 @@
               "show-overrides" => \$show_overrides,
               "color=s" => \$color,
               "unpack-info|U=s" => \&record_unpack_info,
-              "md5sums|m" => \$check_md5sums,
+              "checksums|md5sums|m" => \$check_checksums,
               "allow-root" => \$allow_root,
                "fail-on-warnings" => \$fail_on_warnings,
               # Note: Ubuntu has (and other derivatives might gain) a
@@ -683,14 +683,42 @@
            }
 
            # process all listed `files:'
-            my $file_list = defined $data->{files} ? $data->{files} : '';
+           my %files;
 
+           my $file_list = $data->{files} || '';
            for ( split /\n/, $file_list ) {
                chomp;
                s/^\s+//o;
                next if $_ eq '';
 
                my ($md5sum,$size,$section,$priority,$file) = split(/\s+/o, $_);
+               $files{$file}{md5} = $md5sum;
+               $files{$file}{size} = $size;
+
+               # check section
+               if (($section eq 'non-free') or ($section eq 'contrib')) {
+                   tag( "bad-section-in-changes-file", $file, $section );
+               }
+
+           }
+
+           foreach my $alg (qw(sha1 sha256)) {
+               my $list = $data->{"checksums-$alg"} || '';
+               for ( split /\n/, $list ) {
+                   chomp;
+                   s/^\s+//o;
+                   next if $_ eq '';
+
+                   my ($checksum,$size,$file) = split(/\s+/o, $_);
+                   $files{$file}{$alg} = $checksum;
+                   if ($files{$file}{size} != $size) {
+                       tag( "file-size-mismatch-in-changes-file", $file );
+                   }
+               }
+           }
+
+
+           foreach my $file (keys %files) {
                my $filename = $arg_dir . '/' . $file;
 
                # check size
@@ -698,26 +726,25 @@
                    warn "E: $file does not exist, exiting\n";
                    exit(-1);
                }
-               if (-s $filename ne $size) {
-                   print "N: size is $size, argname is $arg_name, filename is 
$filename\n";
+               if (-s _ ne $files{$file}{size}) {
+                   print "N: size is $files{$file}{size}, argname is 
$arg_name, filename is $filename\n";
 
                    tag( "file-size-mismatch-in-changes-file", $file );
                }
 
-               # check md5sums
-               if ($check_md5sums or $file =~ /\.dsc$/) {
-                   my $real_md5sum = get_file_md5($filename);
+               # check checksums
+               if ($check_checksums or $file =~ /\.dsc$/) {
+                   foreach my $alg (qw(md5 sha1 sha256)) {
+                       next unless exists $files{$file}{$alg};
 
-                   if ($real_md5sum ne $md5sum) {
-                       tag( "md5sum-mismatch-in-changes-file", $file );
+                       my $real_checksum = get_file_checksum($alg, $filename);
+
+                       if ($real_checksum ne $files{$file}{$alg}) {
+                           tag( "checksum-mismatch-in-changes-file", $alg, 
$file );
+                       }
                    }
                }
 
-               # check section
-               if (($section eq 'non-free') or ($section eq 'contrib')) {
-                   tag( "bad-section-in-changes-file", $file, $section );
-               }
-
                # process file?
                if ($file =~ /\.dsc$/) {
                    my $info = get_dsc_info($filename);

Modified: trunk/lib/Util.pm
===================================================================
--- trunk/lib/Util.pm   2008-04-29 00:52:38 UTC (rev 1285)
+++ trunk/lib/Util.pm   2008-04-30 21:03:19 UTC (rev 1286)
@@ -29,7 +29,7 @@
        get_deb_info
        get_dsc_info
        slurp_entire_file
-       get_file_md5
+       get_file_checksum
        file_is_encoded_in_non_utf8
        fail
        system_env
@@ -38,6 +38,7 @@
 use FileHandle;
 use Pipeline;
 use Digest::MD5;
+use Digest::SHA;
 
 # general function to read dpkg control files
 # this function can parse output of `dpkg-deb -f', .dsc,
@@ -180,13 +181,18 @@
     return $_;
 }
 
-sub get_file_md5 {
-       my $file = shift;
+sub get_file_checksum {
+       my ($alg, $file) = @_;
        open (FILE, '<', $file) or fail("Couldn't open $file");
-       my $md5 = Digest::MD5->new;
-       $md5->addfile(*FILE);
+       my $digest;
+       if ($alg eq 'md5') {
+           $digest = Digest::MD5->new;
+       } elsif ($alg =~ /sha(\d+)/) {
+           $digest = Digest::SHA->new($1);
+       }
+       $digest->addfile(*FILE);
        close FILE or fail("Couldn't close $file");
-       return $md5->hexdigest;
+       return $digest->hexdigest;
 }
 
 sub file_is_encoded_in_non_utf8 {


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to