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
|
import os
import logging
import binascii
import posixpath
import Bcfg2.Server.Plugin
logger = logging.getLogger(__name__)
class SEModuleData(Bcfg2.Server.Plugin.SpecificData):
def bind_entry(self, entry, _):
entry.set('encoding', 'base64')
entry.text = binascii.b2a_base64(self.data)
class SEModules(Bcfg2.Server.Plugin.GroupSpool):
""" Handle SELinux 'module' entries """
name = 'SEModules'
__author__ = 'chris.a.st.pierre@gmail.com'
es_cls = Bcfg2.Server.Plugin.EntrySet
es_child_cls = SEModuleData
entry_type = 'SELinux'
experimental = True
def _get_module_name(self, entry):
""" GroupSpool stores entries as /foo.pp, but we want people
to be able to specify module entries as name='foo' or
name='foo.pp', so we put this abstraction in between """
if entry.get("name").endswith(".pp"):
name = entry.get("name")
else:
name = entry.get("name") + ".pp"
return "/" + name
def HandlesEntry(self, entry, metadata):
if entry.tag in self.Entries and entry.get('type') == 'module':
return self._get_module_name(entry) in self.Entries[entry.tag]
return Bcfg2.Server.Plugin.GroupSpool.HandlesEntry(self, entry,
metadata)
def HandleEntry(self, entry, metadata):
entry.set("name", self._get_module_name(entry))
return self.Entries[entry.tag][entry.get("name")](entry, metadata)
def add_entry(self, event):
self.filename_pattern = os.path.basename(event.filename)
Bcfg2.Server.Plugin.GroupSpool.add_entry(self, event)
|