Initial policyrep patch
Subsystems (2)
PATCH 1/1 Initial policyrep patch
Initial patch to create a new policyrep branch using C++. This patch includes basic classes for representing policy (Node and Parent), a few policy objects, a bison parser, a boost::python binding, and basic test infrastructure.
---
16 files changed, 2498 insertions(+), 1 deletion(-) Makefile | 2 libpolicyrep/Makefile | 22 libpolicyrep/include/Makefile | 10 libpolicyrep/include/policyrep/parse.hpp | 36 + libpolicyrep/include/policyrep/policy.hpp | 169 ++++++ libpolicyrep/include/policyrep/policy_base.hpp | 135 ++++ libpolicyrep/src/Makefile | 76 ++ libpolicyrep/src/parse.cpp | 57 ++ libpolicyrep/src/policy.cpp | 431 +++++++++++++++ libpolicyrep/src/policy_base.cpp | 375 +++++++++++++ libpolicyrep/src/policy_internal.hpp | 1 libpolicyrep/src/policy_parse.y | 675 ++++++++++++++++++++++++ libpolicyrep/src/policy_scan.l | 275 +++++++++ libpolicyrep/src/policyrep_python.cpp | 152 +++++ libpolicyrep/tests/Makefile | 24 libpolicyrep/tests/libpolicyrep-test.cpp | 59 ++
Makefile +1 -1
@@ -1,4 +1,4 @@ SUBDIRS=libsepol libselinux libsemanage -SUBDIRS=libsepol libselinux libsemanage sepolgen checkpolicy policycoreutils # policy +SUBDIRS=libsepol libselinux libsemanage libpolicyrep sepolgen checkpolicy policycoreutils # policy PYSUBDIRS=libselinux libsemanage ifeq ($(DEBUG),1)
libpolicyrep/Makefile +22 -0
@@ -0,0 +1,22 @@ +all: + $(MAKE) -C src + +install: + $(MAKE) -C include install + $(MAKE) -C src install + +relabel: + $(MAKE) -C src relabel + +clean: + $(MAKE) -C src clean + $(MAKE) -C tests clean + +indent: + $(MAKE) -C src $@ + $(MAKE) -C include $@ + $(MAKE) -C utils $@ + +test: all + $(MAKE) -C tests test +
libpolicyrep/include/Makefile +10 -0
@@ -0,0 +1,10 @@ +# Installation directories. +PREFIX ?= $(DESTDIR)/usr +INCDIR ?= $(PREFIX)/include/policyrep + +install: + test -d $(INCDIR) || install -m 755 -d $(INCDIR) + install -m 644 $(wildcard policyrep/*.hpp) $(INCDIR) + +indent: + ../../scripts/Lindent $(wildcard policyrep/*.hpp)
libpolicyrep/include/policyrep/parse.hpp +36 -0
@@ -0,0 +1,36 @@ +// Author Karl MacMillan <[email protected]> + +#ifndef kwm06082007_policy_hpp +#define kwm06082007_policy_hpp + +#include <policyrep/policy.hpp> + +#include <string> + +namespace policyrep { + + class location; + + class Parser { + public: + Parser(); + virtual ~Parser(); + + // scanner + void scan_begin(); + void scan_end(); + bool trace_scanning; + + // Parser + Module* parse(const std::string& f); + std::string file; + bool trace_parsing; + Module* pmodule; + + // error handling + virtual void error(const policyrep::location& l, const std::string& m); + virtual void error(const std::string& m); + }; +} + +#endif
libpolicyrep/include/policyrep/policy.hpp +169 -0
169 lines not on this page · raw message
libpolicyrep/include/policyrep/policy_base.hpp +135 -0
135 lines not on this page · raw message
libpolicyrep/src/Makefile +76 -0
76 lines not on this page · raw message
libpolicyrep/src/parse.cpp +57 -0
57 lines not on this page · raw message
libpolicyrep/src/policy.cpp +431 -0
431 lines not on this page · raw message
libpolicyrep/src/policy_base.cpp +375 -0
375 lines not on this page · raw message
libpolicyrep/src/policy_internal.hpp new file +1 -0
@@ -0,0 +1,1 @@ +
libpolicyrep/src/policy_parse.y +675 -0
675 lines not on this page · raw message
libpolicyrep/src/policy_scan.l +275 -0
275 lines not on this page · raw message
libpolicyrep/src/policyrep_python.cpp +152 -0
152 lines not on this page · raw message
libpolicyrep/tests/Makefile +24 -0
@@ -0,0 +1,24 @@ +M4 ?= m4 +MKDIR ?= mkdir +EXE ?= libpolicyrep-test + +CFLAGS += -g3 -gdwarf-2 -o0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter -Werror -I../include + +LIBPOLICYREP := ../src/libpolicyrep.a + +# test program object files +objs := $(patsubst %.cpp,%.o,$(wildcard *.cpp)) + +all: $(EXE) + +$(EXE): $(objs) $(LIBPOLICYREP) + g++ $(CFLAGS) $(objs) $(LIBPOLICYREP) -lboost_serialization -o $@ + +%.o: %.cpp + g++ $(CFLAGS) -fPIC -c -o $@ $< + +clean: + rm -f $(objs) $(EXE) + +test: $(EXE) + ./$(EXE)
libpolicyrep/tests/libpolicyrep-test.cpp +59 -0
59 lines not on this page · raw message
--
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.
Quoted 5 lines · Karl MacMillan
Initial patch to create a new policyrep branch using C++. This patch includes basic classes for representing policy (Node and Parent), a few policy objects, a bison parser, a
boost::pythonbinding, and basic test infrastructure.Signed-off-by User "Karl MacMillan <[email protected]>"
So I suck at C++, so feel free to ignore any of these comments that are
stupid :)
Quoted 6 lines
libpolicyrep/include/policyrep/parse.hpp +6
-0+namespace policyrep { + + class location; + + class Parser { + public:
libpolicyrep/include/policyrep/parse.hpp line 25
Quoted 10 lines
libpolicyrep/include/policyrep/parse.hpp +10
-0+ Parser(); + virtual ~Parser(); + + // scanner + void scan_begin(); + void scan_end(); + bool trace_scanning; + + // Parser + Module* parse(const std::string& f);
Why are you returning a pointer here, this implies that it can return
NULL ... but it can't, it throws an exception if there's an error.
libpolicyrep/include/policyrep/parse.hpp line 26
Quoted 1 line
libpolicyrep/include/policyrep/parse.hpp +1
-0+ std::string file;
Do you really want public members like this?
Quoted 7 lines
libpolicyrep/include/policyrep/parse.hpp +7
-0+ bool trace_parsing; + Module* pmodule; + + // error handling + virtual void error(const policyrep::location& l, const std::string& m); + virtual void error(const std::string& m); + };
[...]
libpolicyrep/include/policyrep/policy.hpp line 19
Quoted 7 lines
libpolicyrep/include/policyrep/policy.hpp +7
-0+ struct PolicyImpl; + class Policy : public Parent { + public: + Policy(bool mls=false); + Policy(const Policy& other); + virtual ~Policy() { }; + void operator=(const Policy& other);
Is it normal to have only a virtual dtor? My understanding was you
generally wanted ctor, dtor and op= to have the same overidability.
libpolicyrep/include/policyrep/policy.hpp line 22
Quoted 2 lines
libpolicyrep/include/policyrep/policy.hpp +2
-0+ bool get_mls() const; + void set_mls(bool val);
Isn't this better done with polymorphism? Like:
bool mls() const;
void mls(bool);Quoted 5 lines
libpolicyrep/include/policyrep/policy.hpp +5
-0+ virtual void output(std::ostream& o, enum OutputStyle style=DEFAULT_OUTPUT) const; + protected: + PolicyImpl* impl; + }; + typedef boost::shared_ptr<Policy> PolicyPtr;
[...]
libpolicyrep/include/policyrep/policy.hpp line 44
Quoted 4 lines
libpolicyrep/include/policyrep/policy.hpp +4
-0+ std::string get_name() const; + void set_name(std::string name); + std::string get_version() const; + void set_version(std::string version);
Don't you want to be returning a const reference like:
const std::string &name(void) const;
...AIUI this automatically converts to a std::string via. copy in the cases you need a writable version. Dito. the set version, but just for the speed increase (Ie. the internal member is still a plain std::string).
libpolicyrep/src/policy.cpp line 97
Quoted 7 lines
libpolicyrep/src/policy.cpp +7
-0+ Module::Module() : impl(new ModuleImpl) { } + + Module::Module(const Module& other) + : Parent(), impl(new ModuleImpl) + { + *impl = *other.impl; + }
So you are allocating memory to a pointer impl, but the Policy dtor
does nothing?
Quoted 5 lines
libpolicyrep/include/policyrep/policy.hpp +5
-0+ virtual void output(std::ostream& o, enum OutputStyle style=DEFAULT_OUTPUT) const; + protected: + ModuleImpl* impl; + }; + typedef boost::shared_ptr<Module> ModulePtr;
[...]
libpolicyrep/src/policy.cpp line 61
Quoted 4 lines
libpolicyrep/src/policy.cpp +4
-0+ void Policy::operator=(const Policy& other) + { + *impl = *impl; + }
This looks very wrong.
Signature · 1 line
James Antill <[email protected]>
Quoted 10 lines · James Antill
Quoted 5 lines · Karl MacMillan
Initial patch to create a new policyrep branch using C++. This patch includes basic classes for representing policy (Node and Parent), a few policy objects, a bison parser, a
boost::pythonbinding, and basic test infrastructure.Signed-off-by User "Karl MacMillan <[email protected]>"So I suck at C++, so feel free to ignore any of these comments that are
stupid :)
That's ok - I'm desperately trying to remember C++.
Quoted 11 lines
Quoted 11 lines
libpolicyrep/include/policyrep/parse.hpp +11
-0+namespace policyrep { + + class location; + + class Parser { + public: + Parser(); + virtual ~Parser(); + + // scanner + void scan_begin();
Quoted 9 lines
libpolicyrep/include/policyrep/parse.hpp line 25
Quoted 5 lines
libpolicyrep/include/policyrep/parse.hpp +5
-0+ void scan_end(); + bool trace_scanning; + + // Parser + Module* parse(const std::string& f);Why are you returning a pointer here, this implies that it can return
NULL ... but it can't, it throws an exception if there's an error.
I actually changed this to return a shared_ptr<Module> to match the rest of the code.
Quoted 4 lines
libpolicyrep/include/policyrep/parse.hpp line 26
Quoted 1 line
libpolicyrep/include/policyrep/parse.hpp +1
-0+ std::string file;Do you really want public members like this?
Made this use the PIMPL pattern.
Quoted 8 lines
Quoted 7 lines
libpolicyrep/include/policyrep/parse.hpp +7
-0+ bool trace_parsing; + Module* pmodule; + + // error handling + virtual void error(const policyrep::location& l, const std::string& m); + virtual void error(const std::string& m); + };[...]
Quoted 11 lines
libpolicyrep/include/policyrep/policy.hpp line 19
Quoted 7 lines
libpolicyrep/include/policyrep/policy.hpp +7
-0+ struct PolicyImpl; + class Policy : public Parent { + public: + Policy(bool mls=false); + Policy(const Policy& other); + virtual ~Policy() { }; + void operator=(const Policy& other);Is it normal to have only a virtual dtor? My understanding was you
generally wanted ctor, dtor and op= to have the same overidability.
Constructors can't be virtual, but I made op= virtual and a few others.
Quoted 5 lines
libpolicyrep/include/policyrep/policy.hpp line 22
Quoted 2 lines
libpolicyrep/include/policyrep/policy.hpp +2
-0+ bool get_mls() const; + void set_mls(bool val);Isn't this better done with polymorphism? Like:
You mean overloading.
Quoted 3 lines
bool mls() const;
void mls(bool);Matter of taste - I prefer the explicit get/set as it makes wrapping the code in non-C++ languages easier. If people have a strong preference we can change this.
Quoted 12 lines
Quoted 5 lines
libpolicyrep/include/policyrep/policy.hpp +5
-0+ virtual void output(std::ostream& o, enum OutputStyle style=DEFAULT_OUTPUT) const; + protected: + PolicyImpl* impl; + }; + typedef boost::shared_ptr<Policy> PolicyPtr;[...]
libpolicyrep/include/policyrep/policy.hpp line 44
Quoted 4 lines
libpolicyrep/include/policyrep/policy.hpp +4
-0+ std::string get_name() const; + void set_name(std::string name); + std::string get_version() const; + void set_version(std::string version);
Quoted 9 lines
Don't you want to be returning a const reference like:
const std::string &name(void) const;...AIUI this automatically converts to a
std::stringvia. copy in the cases you need a writable version. Dito. the set version, but just for the speed increase (Ie. the internal member is still a plainstd::string).
I had been intentionally returning std::string and letting the copies happen to make ownership obvious (again, this helps with wrapping the code for other languages).
However, on reconsidering I made them const references and changed boost::python to do the copying.
Quoted 11 lines
libpolicyrep/src/policy.cpp line 97
Quoted 7 lines
libpolicyrep/src/policy.cpp +7
-0+ Module::Module() : impl(new ModuleImpl) { } + + Module::Module(const Module& other) + : Parent(), impl(new ModuleImpl) + { + *impl = *other.impl; + }So you are allocating memory to a pointer impl, but the Policy dtor
does nothing?
Oops.
Quoted 7 lines
Quoted 5 lines
libpolicyrep/include/policyrep/policy.hpp +5
-0+ virtual void output(std::ostream& o, enum OutputStyle style=DEFAULT_OUTPUT) const; + protected: + ModuleImpl* impl; + }; + typedef boost::shared_ptr<Module> ModulePtr;[...]
Quoted 7 lines
libpolicyrep/src/policy.cpp line 61
Quoted 4 lines
libpolicyrep/src/policy.cpp +4
-0+ void Policy::operator=(const Policy& other) + { + *impl = *impl; + }This looks very wrong.
Maybe :)
New patch coming.
Karl
--
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.