5 dh_fixperms - fix permissions of files in package build directories
10 use Debian::Debhelper::Dh_Lib;
14 B<dh_fixperms> [S<I<debhelper options>>] [B<-X>I<item>]
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.
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.
35 =item B<-X>I<item>, B<--exclude> I<item>
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.
47 foreach my $package (@{$dh{DOPACKAGES}}) {
48 my $tmp=tmpdir($package);
51 if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
52 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
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");
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");
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");
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");
78 # ..and header files ..
79 complex_doit("find $tmp/usr/include -type f $find_options -print0",
80 "2>/dev/null | xargs -0r chmod 644");
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");
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");
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");
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");
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");
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");
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");
133 This program is a part of debhelper.
137 Joey Hess <joeyh@debian.org>