control-files.pm 3.39 KB
Newer Older
1
# control-files -- lintian check script -*- perl -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

# Copyright (C) 1998 Christian Schwarz and Richard Braakman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, you can find it on the World Wide
# Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
Frank Lichtenheld's avatar
Frank Lichtenheld committed
18 19
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
20

Jeroen van Wolffelaar's avatar
Jeroen van Wolffelaar committed
21
package Lintian::control_files;
22
use strict;
23
use warnings;
24
use autodie;
25

26
use Lintian::Tags qw(tag);
Jeroen van Wolffelaar's avatar
Jeroen van Wolffelaar committed
27

28 29 30 31 32
sub octify {
    my (undef, $val) = @_;
    return oct($val);
}

33 34 35 36
my $DEB_PERMISSIONS
  = Lintian::Data->new('control-files/deb-permissions',  qr/\s++/o, \&octify);
my $UDEB_PERMISSIONS
  = Lintian::Data->new('control-files/udeb-permissions', qr/\s++/o, \&octify);
37

Jeroen van Wolffelaar's avatar
Jeroen van Wolffelaar committed
38
sub run {
39 40 41
    my (undef, $type, $info) = @_;
    my $ctrl = $type eq 'udeb' ? $UDEB_PERMISSIONS : $DEB_PERMISSIONS;
    my $ctrl_alt = $type eq 'udeb' ? $DEB_PERMISSIONS : $UDEB_PERMISSIONS;
42
    my $has_ctrl_script = 0;
43 44 45 46 47 48

    # process control-index file
    foreach my $file ($info->sorted_control_index) {
        my ($owner, $operm, $experm);

        # the control.tar.gz should only contain files (and the "root"
49 50
        # dir, but that is excluded from the index)
        if (not $file->is_regular_file) {
51 52 53
            tag 'control-file-is-not-a-file', $file;
            # Doing further checks is probably not going to yield anything
            # remotely useful.
54 55
            next;
        }
56

57 58 59 60 61 62 63 64 65 66
        # valid control file?
        unless ($ctrl->known($file)) {
            if ($ctrl_alt->known($file)) {
                tag 'not-allowed-control-file', $file;
                next;
            } else {
                tag 'unknown-control-file', $file;
                next;
            }
        }
67

68
        $experm = $ctrl->value($file);
69

70
        if ($file->size == 0 and $file->basename ne 'md5sums') {
71 72
            tag 'control-file-is-empty', $file;
        }
73

74 75 76 77
        # skip `control' control file (that's an exception: dpkg
        # doesn't care and this file isn't installed on the systems
        # anyways)
        next if $file eq 'control';
78

79
        $operm = $file->operm;
80 81 82 83
        if ($operm & 0111 or $experm & 0111) {
            $has_ctrl_script = 1;
            tag 'ctrl-script', $file;
        }
84

85 86 87 88 89
        # correct permissions?
        unless ($operm == $experm) {
            tag 'control-file-has-bad-permissions',
              sprintf('%s %04o != %04o', $file, $operm, $experm);
        }
90

91
        $owner = $file->owner . '/' . $file->group;
92

93 94 95 96
        # correct owner?
        unless ($owner eq 'root/root') {
            tag 'control-file-has-bad-owner', "$file $owner != root/root";
        }
97

98 99
        # for other maintainer scripts checks, see the scripts check
    }
100 101 102
    if (not $has_ctrl_script) {
        tag 'no-ctrl-scripts';
    }
103
    return;
Jeroen van Wolffelaar's avatar
Jeroen van Wolffelaar committed
104
} # </run>
105

Jeroen van Wolffelaar's avatar
Jeroen van Wolffelaar committed
106 107
1;

108 109 110 111 112
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et