~ubuntu-branches/ubuntu/trusty/devscripts/trusty-updates

« back to all changes in this revision

Viewing changes to scripts/dscverify.pl

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2013-02-18 22:27:33 UTC
  • mfrom: (10.9.22 experimental)
  • Revision ID: package-import@ubuntu.com-20130218222733-7krtkqzko32xte0z
Tags: 2.13.0ubuntu1
* Merge from Debian experimental. Remaining changes:
  - Convert python scripts to python3. (Closes: #680313)
    Debian bug #695259 needs to be fixed to get the change into Debian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
use 5.004;      # correct pipe close behavior
25
25
use strict;
26
26
use Cwd;
 
27
use Fcntl;
27
28
use Dpkg::IPC;
 
29
use File::Spec;
 
30
use File::Temp;
28
31
use File::Basename;
29
32
use POSIX       qw(:errno_h);
30
33
use Getopt::Long qw(:config gnu_getopt);
110
113
    xdie "can't find any system keyrings\n";
111
114
}
112
115
 
113
 
sub check_signature {
114
 
    my ($file, @rings) = @_;
115
 
 
116
 
    my @cmd = qw(gpg --batch --no-options --no-default-keyring --always-trust);
117
 
    foreach (@rings) { push @cmd, '--keyring'; push @cmd, $_; }
 
116
sub check_signature($\@;\$) {
 
117
    my ($file, $rings, $outref) = @_;
 
118
 
 
119
    my $fh = eval { File::Temp->new() }
 
120
        or xdie "unable to open status file for gpg: $@\n";
 
121
 
 
122
    # Allow the status file descriptor to pass on to the child process
 
123
    my $flags = fcntl($fh, F_GETFD, 0);
 
124
    fcntl($fh, F_SETFD, $flags & ~FD_CLOEXEC);
 
125
 
 
126
    my $fd = fileno $fh;
 
127
    my @cmd;
 
128
    push @cmd, qw(gpg --status-fd), $fd,
 
129
               qw(--batch --no-options --no-default-keyring --always-trust);
 
130
    foreach (@$rings) { push @cmd, '--keyring'; push @cmd, $_; }
118
131
 
119
132
    my ($out, $err) = ('', '');
120
133
    eval {
129
142
        print $out if ($verbose);
130
143
        return $err || $@;
131
144
    }
 
145
 
 
146
    seek($fh, 0, SEEK_SET);
 
147
    my $status;
 
148
    $status .= $_ while <$fh>;
 
149
    close $fh;
 
150
 
 
151
    if ($status !~ m/^\[GNUPG:\] VALIDSIG/m) {
 
152
        return $out;
 
153
    }
 
154
 
 
155
    if (defined $outref) {
 
156
        $$outref = $out;
 
157
    }
 
158
 
132
159
    return '';
133
160
}
134
161
 
152
179
        $filebase = $file;
153
180
    }
154
181
 
155
 
    if (!open SIGNED, '<', $filebase) {
156
 
        xwarn "can't open $file:";
157
 
        return;
 
182
    my $out;
 
183
    if ($verify_sigs) {
 
184
        $sigcheck = check_signature $filebase, @rings, $out;
 
185
        if ($sigcheck) {
 
186
            xwarn "$file failed signature check:\n$sigcheck";
 
187
            return;
 
188
        } else {
 
189
            print "      Good signature found\n";
 
190
        }
158
191
    }
159
 
    my $out = do { local $/; <SIGNED> };
160
 
    if (!close SIGNED) {
161
 
        xwarn "problem reading $file:";
162
 
        return;
 
192
    else {
 
193
        if (!open SIGNED, '<', $filebase) {
 
194
            xwarn "can't open $file:";
 
195
            return;
 
196
        }
 
197
        $out = do { local $/; <SIGNED> };
 
198
        if (!close SIGNED) {
 
199
            xwarn "problem reading $file:";
 
200
            return;
 
201
        }
163
202
    }
164
203
 
165
204
    if ($file =~ /\.changes$/ and $out =~ /^Format:\s*(.*)$/mi) {
177
216
        }
178
217
    }
179
218
 
180
 
    if ($verify_sigs == 1) {
181
 
        $sigcheck = check_signature $filebase, @rings;
182
 
        if ($sigcheck) {
183
 
            xwarn "$file failed signature check:\n$sigcheck";
184
 
            return;
185
 
        } else {
186
 
            print "      Good signature found\n";
187
 
        }
188
 
    }
189
 
 
190
219
    my @spec = map { split /\n/ } $out =~ /^Files:\s*\n((?:[ \t]+.*\n)+)/mgi;
191
220
    unless (@spec) {
192
221
        xwarn "no file spec lines in $file\n";
316
345
 
317
346
        close FILE;
318
347
 
319
 
        if ($filename =~ /\.dsc$/ && $verify_sigs == 1) {
 
348
        if ($filename =~ /\.dsc$/ && $verify_sigs) {
320
349
            $sigcheck = check_signature $filename, @rings;
321
350
            if ($sigcheck) {
322
351
                xwarn "$filename failed signature check:\n$sigcheck";