1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#
# namcap rules - fhs
# Copyright (C) 2003-2009 Jason Chu <jason@archlinux.org>
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import os, re
import tarfile
from Namcap.ruleclass import *
class FHSRule(TarballRule):
name = "directoryname"
description = "Checks for standard directories."
def analyze(self, pkginfo, tar):
valid_paths = [
'etc/', 'opt/',
'lib/modules',
'usr/bin/', 'usr/include/', 'usr/lib/', 'usr/lib32/',
'usr/sbin/', 'usr/share/',
'var/cache/', 'var/lib/', 'var/log/', 'var/opt/',
'var/spool/', 'var/state/',
'.PKGINFO', '.INSTALL', '.CHANGELOG', '.MTREE', '.BUILDINFO',
]
forbidden_paths = [
'tmp/', 'var/tmp/',
'run/', 'var/run/',
'var/lock/'
]
custom_valid = {
'^mingw-': ['usr/x86_64-w64-mingw32/lib/',
'usr/x86_64-w64-mingw32/bin/',
'usr/x86_64-w64-mingw32/include/',
'usr/i686-w64-mingw32/lib/',
'usr/i686-w64-mingw32/bin/',
'usr/i686-w64-mingw32/include/'],
}
for pattern in custom_valid:
if re.search(pattern, pkginfo['name']):
valid_paths.extend(custom_valid[pattern])
for entry in tar.getmembers():
name = os.path.normpath(entry.name)
if entry.isdir():
name += '/'
# check for files in wrong dirs, directory itself will be
# catched by emptydirs rule
if name in forbidden_paths:
continue
bad_dirs = (name.startswith(dirname) for dirname in forbidden_paths)
if any(bad_dirs):
self.errors.append(('file-in-temporary-dir %s', name))
continue
# matches directory names or parent directories
good_dirs = (name.startswith(dirname) or dirname.startswith(name)
for dirname in valid_paths)
if not any(good_dirs):
self.warnings.append(("file-in-non-standard-dir %s", name))
class FHSManpagesRule(TarballRule):
name = "fhs-manpages"
description = "Verifies correct installation of man pages"
def analyze(self, pkginfo, tar):
gooddir = 'usr/share/man'
bad_dir = 'usr/man'
for i in tar.getmembers():
if not i.isfile():
continue
if i.name.startswith(bad_dir):
self.errors.append(("non-fhs-man-page %s", i.name))
elif not i.name.startswith(gooddir):
#Check everything else to see if it has a 'man' path component
for part in i.name.split(os.sep):
if part == "man":
self.warnings.append(("potential-non-fhs-man-page %s", i.name))
class FHSInfoPagesRule(TarballRule):
name = "fhs-infopages"
description = "Verifies correct installation of info pages"
def analyze(self, pkginfo, tar):
for i in tar.getmembers():
if not i.isfile():
continue
if i.name.startswith('usr/info'):
self.errors.append(("non-fhs-info-page %s", i.name))
elif not i.name.startswith('usr/share/info'):
for part in i.name.split(os.sep):
if part == "info":
self.warnings.append(("potential-non-fhs-info-page %s", i.name))
class RubyPathsRule(TarballRule):
name = "rubypaths"
description = "Verifies correct usage of folders by ruby packages"
def analyze(self, pkginfo, tar):
for i in tar.getmembers():
if i.name.startswith('usr/lib/ruby/site_ruby'):
self.warnings.append(("site-ruby", ()))
return
# vim: set ts=4 sw=4 noet:
|