Added lots more modules from lintian. Maemian appears to work.
[maemian] / checks / control-files
1 # control-files -- lintian check script -*- perl -*-
2
3 # Copyright (C) 1998 Christian Schwarz and Richard Braakman
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 package Maemian::control_files;
22 use strict;
23 use Tags;
24 use Util;
25
26 my %ctrl_deb =
27     (clilibs   => 0644,
28      config    => 0755,
29      control   => 0644,
30      conffiles => 0644,
31      md5sums   => 0644,
32      postinst  => 0755,
33      preinst   => 0755,
34      postrm    => 0755,
35      prerm     => 0755,
36      shlibs    => 0644,
37      symbols   => 0644,
38      templates => 0644,
39      triggers  => 0644);
40
41 my %ctrl_udeb =
42     (config        => 0755,
43      control       => 0644,
44      isinstallable => 0755,
45      menutest      => 0755,
46      postinst      => 0755,
47      shlibs        => 0644,
48      symbols       => 0644,
49      templates     => 0644);
50
51 sub run {
52
53 my $pkg = shift;
54 my $type = shift;
55
56 my %ctrl = $type eq 'udeb' ? %ctrl_udeb : %ctrl_deb;
57 my %ctrl_alt = $type eq 'udeb' ? %ctrl_deb : %ctrl_udeb;
58
59 # process control-index file
60 open(IN, '<', "control-index") or fail("cannot open control-index file: $!");
61 while (<IN>) {
62     chop;
63
64     my ($perm,$owner,$size,$date,$time,$file) = split(' ', $_, 6);
65     my $operm;
66
67     next if $file eq './';
68
69     $file =~ s,^(\./),,;
70     $file =~ s/ link to .*//;
71     $file =~ s/ -> .*//;
72
73     next if $file eq './';
74
75     # valid control file?
76     unless ( exists $ctrl{$file} ) {
77         if ( exists $ctrl_alt{$file} ) {
78             tag "not-allowed-control-file", "$file";
79             next;
80         } else {
81             tag "unknown-control-file", "$file";
82             next;
83         }
84     }
85
86     # I'm not sure about the udeb case
87     if ($type ne 'udeb' and $size == 0) {
88         tag "control-file-is-empty", "$file";
89     }
90
91
92     # skip `control' control file (that's an exception: dpkg doesn't care and
93     # this file isn't installed on the systems anyways)
94     next if $file eq 'control';
95
96     $operm = perm2oct($perm);
97
98     # correct permissions?
99     unless ($operm == $ctrl{$file}) {
100         tag "control-file-has-bad-permissions",
101             sprintf("$file %04o != %04o",$operm,$ctrl{$file});
102     }
103
104     # correct owner?
105     unless ($owner eq 'root/root') {
106         tag "control-file-has-bad-owner", "$file $owner != root/root";
107     }
108
109 # for other maintainer scripts checks, see the scripts check
110 }
111 close IN;
112
113 } # </run>
114
115 1;
116
117 # vim: syntax=perl sw=4 ts=8