]> git.donarmstrong.com Git - debhelper.git/blob - dh_fixperms
merge
[debhelper.git] / dh_fixperms
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_fixperms - fix permissions of files in package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_fixperms> [S<I<debhelper options>>] [B<-X>I<item>]
15
16 =head1 DESCRIPTION
17
18 B<dh_fixperms> is a debhelper program that is responsible for setting the
19 permissions of files and directories in package build directories to a
20 sane state -- a state that complies with Debian policy.
21
22 B<dh_fixperms> makes all files in F<usr/share/doc> in the package build directory
23 (excluding files in the F<examples/> directory) be mode 644. It also changes
24 the permissions of all man pages to mode 644. It makes all files be owned
25 by root, and it removes group and other write permission from all files. It
26 removes execute permissions from any libraries, headers, Perl modules, or
27 desktop files that have it set. It makes all files in the standard F<bin> and
28 F<sbin> directories, F<usr/games/> and F<etc/init.d> executable (since v4). Finally,
29 it removes the setuid and setgid bits from all files in the package.
30
31 =head1 OPTIONS
32
33 =over 4
34
35 =item B<-X>I<item>, B<--exclude> I<item>
36
37 Exclude files that contain I<item> anywhere in their filename from having
38 their permissions changed. You may use this option multiple times to build
39 up a list of things to exclude.
40
41 =back
42
43 =cut
44
45 init();
46
47 foreach my $package (@{$dh{DOPACKAGES}}) {
48         my $tmp=tmpdir($package);
49
50         my $find_options='';
51         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
52                 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
53         }
54
55         # General permissions fixing.
56         complex_doit("find $tmp $find_options -print0",
57                 "2>/dev/null | xargs -0r chown --no-dereference 0:0");
58         complex_doit("find $tmp ! -type l $find_options -print0",
59                 "2>/dev/null | xargs -0r chmod go=rX,u+rw,a-s");
60         
61         # Fix up premissions in usr/share/doc, setting everything to not
62         # executable by default, but leave examples directories alone.
63         complex_doit("find $tmp/usr/share/doc -type f $find_options ! -regex '$tmp/usr/share/doc/[^/]*/examples/.*' -print0 2>/dev/null",
64                 "| xargs -0r chmod 644");
65         complex_doit("find $tmp/usr/share/doc -type d $find_options -print0 2>/dev/null",
66                 "| xargs -0r chmod 755");
67
68         # Executable man pages are a bad thing..
69         complex_doit("find $tmp/usr/share/man $tmp/usr/man/ $tmp/usr/X11*/man/ -type f",
70                 "$find_options -print0 2>/dev/null | xargs -0r chmod 644");
71
72         # ..and so are executable shared and static libraries 
73         # (and .la files from libtool) ..
74         complex_doit("find $tmp -perm -5 -type f",
75                 "\\( -name '*.so.*' -or -name '*.so' -or -name '*.la' -or -name '*.a' \\) $find_options -print0",
76                 "2>/dev/null | xargs -0r chmod 644");
77         
78         # ..and header files ..
79         complex_doit("find $tmp/usr/include -type f $find_options -print0",
80                 "2>/dev/null | xargs -0r chmod 644");
81         
82         # ..and desktop files ..
83         complex_doit("find $tmp/usr/share/applications -type f $find_options -print0",
84                 "2>/dev/null | xargs -0r chmod 644");
85
86         # ..and OCaml native-code shared objects ..
87         complex_doit("find $tmp -perm -5 -type f",
88                 "\\( -name '*.cmxs' \\) $find_options -print0",
89                 "2>/dev/null | xargs -0r chmod 644");
90         
91         # .. and perl modules.
92         complex_doit("find $tmp/usr/lib/perl5 $tmp/usr/share/perl5 -type f",
93                 "-perm -5 -name '*.pm' $find_options -print0",
94                 "2>/dev/null | xargs -0r chmod a-X");
95         
96         # v4 and up
97         if (! compat(3)) {
98                 # Programs in the bin and init.d dirs should be executable..
99                 for my $dir (qw{usr/bin bin usr/sbin sbin usr/games etc/init.d}) {
100                         if (-d "$tmp/$dir") {
101                                 complex_doit("find $tmp/$dir -type f $find_options -print0 2>/dev/null",
102                                         "| xargs -0r chmod a+x");
103                         }
104                 }
105         }
106         
107         # ADA ali files should be mode 444 to avoid recompilation
108         if (-d "$tmp/usr/lib/ada") {
109                 complex_doit("find $tmp/usr/lib/ada -type f",
110                         "-name '*.ali' $find_options -print0",
111                         "2>/dev/null | xargs -0r chmod uga-w");
112         }
113
114         # Lintian overrides should never be executable, too.
115         if (-d "$tmp/usr/share/lintian") {
116                 complex_doit("find $tmp/usr/share/lintian/overrides",
117                         "-type f $find_options -print0",
118                         "2>/dev/null | xargs -0r chmod 644");
119         }
120
121         # Files in $tmp/etc/sudoers.d/ must be mode 440.
122         if (-d "$tmp/etc/sudoers.d") {
123                 complex_doit("find $tmp/etc/sudoers.d",
124                         "-type f ! -perm 440 $find_options -print0",
125                         "2>/dev/null | xargs -0r chmod 440");
126         }
127 }
128
129 =head1 SEE ALSO
130
131 L<debhelper(7)>
132
133 This program is a part of debhelper.
134
135 =head1 AUTHOR
136
137 Joey Hess <joeyh@debian.org>
138
139 =cut