sepolgen: leave generated files in current directory
PATCH 1/1 sepolgen: leave generated files in current directory
This patch changes sepolgen so that the generated te files are left in the current directory when generating policy modules (with -M). This matches the behavior of the old audit2allow and allows review of the te file before inserting the module.
This patch also brings up the question of API stability for the sepolgen library (as it makes a minor change to the API). I suggest that it remain unstable for at least 1 release (i.e., the API can change in arbitrary ways). That should give sufficient time for it to stabilize and, hopefully, become general enough. Thoughts?
policycoreutils/audit2allow/audit2allow +35 -38
@@ -1,7 +1,7 @@ #! /usr/bin/python -E # Authors: Karl MacMillan <[email protected]> # -# Copyright (C) 2006 Red Hat +# Copyright (C) 2006-2007 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or
@@ -94,7 +94,6 @@ class AuditToPolicy: if not module.is_valid_name(name): sys.stderr.write("only letters and numbers allowed in module names\n") sys.exit(2) - # Make -M and -o conflict if options.module_package:
@@ -136,14 +135,14 @@ class AuditToPolicy: except IOError, e: sys.stderr.write('could not open file %s - "%s"\n' % (filename, str(e))) sys.exit(1) - + if f is not None: parser.parse_file(f) f.close() if messages is not None: parser.parse_string(messages) - + self.__parser = parser def __process_input(self):
@@ -182,16 +181,41 @@ class AuditToPolicy: perm_maps = objectmodel.PermMappings() perm_maps.from_file(fd) - + return (ifs, perm_maps) - - + + def __output_modulepackage(self, writer, generator): + generator.set_module_name(self.__options.module_package) + filename = self.__options.module_package + ".te" + packagename = self.__options.module_package + ".pp" + + try: + fd = open(filename, "w") + except IOError, e: + sys.stderr.write("could not write output file: %s\n", str(e)) + sys.exit(1) + + writer.write(generator.get_module(), fd) + fd.close() + + mc = module.ModuleCompiler() + + try: + mc.create_module_package(filename, self.__options.refpolicy) + except RuntimeError, e: + print e + sys.exit(1) + + sys.stdout.write(_("******************** IMPORTANT ***********************\n")) + sys.stdout.write((_("To make this policy package active, execute:" +\ + "\n\nsemodule -i %s\n\n") % packagename)) + def __output(self): g = policygen.PolicyGenerator() - + if self.__options.module: g.set_module_name(self.__options.module) - + # Interface generation if self.__options.refpolicy: ifs, perm_maps = self.__load_interface_info()
@@ -215,34 +239,7 @@ class AuditToPolicy: # Module package if self.__options.module_package: - g.set_module_name(self.__options.module_package) - - fd = tempfile.NamedTemporaryFile() - writer.write(g.get_module(), fd) - fd.flush() - - mc = module.ModuleCompiler() - if self.__options.debug: - clean = False - else: - clean = True - - if self.__options.refpolicy: - mc.refpolicy = True - - try: - mc.create_module_package(fd.name, self.__options.module_package + ".pp", - cleanup=clean) - except RuntimeError, e: - print e - sys.exit(1) - - # This should unlink the temporary file - fd.close() - sys.stdout.write(_("******************** IMPORTANT ***********************\n")) - sys.stdout.write((_("To make this policy package active, execute:" +\ - "\n\nsemodule -i %s.pp\n\n") % self.__options.module_package)) - + self.__output_modulepackage(writer, g) else: # File or stdout if self.__options.module:
@@ -253,7 +250,7 @@ class AuditToPolicy: else: fd = sys.stdout writer.write(g.get_module(), fd) - + def main(self): try: self.__parse_options()
sepolgen/src/sepolgen/module.py +33 -39
102 lines not on this page · raw message
sepolgen/tests/test_module.py +3 -3
@@ -25,11 +25,11 @@ class TestModuleCompiler(unittest.TestCa def test(self): package = "module_compile_test.pp" mc = module.ModuleCompiler() - mc.create_module_package("module_compile_test.te", package) + mc.create_module_package("module_compile_test.te", refpolicy=True) os.stat(package) os.unlink(package) mc.refpolicy = True - mc.create_module_package("module_compile_test.te", "module_compile_test.pp") + mc.create_module_package("module_compile_test.te", refpolicy=False) os.stat(package) - #os.unlink(package) + os.unlink(package)
Quoted 10 lines · Karl MacMillan
This patch changes sepolgen so that the generated te files are left in the current directory when generating policy modules (with -M). This matches the behavior of the old audit2allow and allows review of the te file before inserting the module.
This patch also brings up the question of API stability for the sepolgen library (as it makes a minor change to the API). I suggest that it remain unstable for at least 1 release (i.e., the API can change in arbitrary ways). That should give sufficient time for it to stabilize and, hopefully, become general enough. Thoughts?
Yes, I don't think we need to treat the sepolgen API as stable yet, particularly given that the only user at present is audit2allow (and they are packaged together at least in Fedora presently).
Quoted 2 lines
Signed-off-by Karl MacMillan <[email protected]>
Signature · 7 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.