25fc900e3a5a72d4442a72f663c9abede4315a1a
[gentoo.git] /
1 From 73b7ff410c1b2958c5c1f8e26cae5347d56416d4 Mon Sep 17 00:00:00 2001
2 From: Sven Vermeulen <sven.vermeulen@siphos.be>
3 Date: Tue, 9 Jun 2015 13:26:24 +0200
4 Subject: [PATCH 1/1] Only invoke RPM on RPM-enabled Linux distributions
5
6 When calling "sepolgen generate" to automatically generate a SELinux
7 policy template, the command fails when it cannot invoke RPM related
8 commands on Linux distributions that do not support RPM by default:
9
10 Failed to retrieve rpm info for selinux-policy
11 Traceback (most recent call last):
12   File "/usr/lib/python-exec/python2.7/sepolicy", line 643, in <module>
13     args.func(args)
14   File "/usr/lib/python-exec/python2.7/sepolicy", line 517, in generate
15     print mypolicy.generate(args.path)
16   File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1370, in generate
17     out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file"))
18   File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1219, in write_spec
19     fd.write(self.generate_spec())
20   File "/usr/lib64/python2.7/site-packages/sepolicy/generate.py", line 1181, in generate_spec
21     selinux_policyver = get_rpm_nvr_list("selinux-policy")[1]
22 TypeError: 'NoneType' object has no attribute '__getitem__'
23
24 As the RPM related steps are only needed on RPM-enabled distributions,
25 we should ignore these steps on other Linux distribution platforms.
26
27 In this patch, we use the Python platform module to get the Linux
28 distribution, and only start the RPM-related activities on Linux
29 distributions that use RPM as their native package manager.
30
31 Signed-off-by: Sven Vermeulen <sven.vermeulen@siphos.be>
32 ---
33  policycoreutils/sepolicy/sepolicy/generate.py | 7 +++++--
34  1 file changed, 5 insertions(+), 2 deletions(-)
35
36 diff --git a/policycoreutils/sepolicy/sepolicy/generate.py b/policycoreutils/sepolicy/sepolicy/generate.py
37 index 6b53035..4858582 100644
38 --- a/policycoreutils/sepolicy/sepolicy/generate.py
39 +++ b/policycoreutils/sepolicy/sepolicy/generate.py
40 @@ -26,6 +26,7 @@ import re
41  import sepolicy
42  from sepolicy import get_all_types, get_all_attributes, get_all_roles
43  import time
44 +import platform
45  
46  from templates import executable
47  from templates import boolean
48 @@ -1171,7 +1172,8 @@ allow %s_t %s_t:%s_socket name_%s;
49                         newsh += re.sub("TEMPLATETYPE", self.name, t1)
50  
51                  newsh += self.generate_user_sh()
52 -                newsh += re.sub("TEMPLATEFILE", self.file_name, script.rpm)
53 +                if (platform.linux_distribution(full_distribution_name=0)[0] in ("redhat","centos","SuSE","fedora","mandrake","mandriva")):
54 +                    newsh += re.sub("TEMPLATEFILE", self.file_name, script.rpm)
55  
56                 return newsh
57  
58 @@ -1367,6 +1369,7 @@ Warning %s does not exist
59              out += "%s # %s\n" % (self.write_if(out_dir), _("Interface file"))
60              out += "%s # %s\n" % (self.write_fc(out_dir), _("File Contexts file"))
61              if self.type != NEWTYPE:
62 -                out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file"))
63 +                if (platform.linux_distribution(full_distribution_name=0)[0] in ("redhat","centos","SuSE","fedora","mandrake","mandriva")):
64 +                    out += "%s # %s\n" % (self.write_spec(out_dir), _("Spec file"))
65                  out += "%s # %s\n" % (self.write_sh(out_dir), _("Setup Script"))
66              return out
67 -- 
68 2.4.6
69